[#488] reputation: Initial Trusts using netMap

Make initial trust values depend on NetMap:
initial trust equals 1 / (`amount of storage nodes`).

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-05-04 13:10:41 +03:00 committed by Alex Vanin
parent d1db54acf8
commit 25ea5fea90
2 changed files with 19 additions and 4 deletions

View file

@ -38,7 +38,6 @@ import (
)
const EigenTrustAlpha = 0.1
const EigenTrustInitialTrust = 0.5
func initReputationService(c *cfg) {
staticClient, err := client.NewStatic(
@ -154,7 +153,7 @@ func initReputationService(c *cfg) {
Alpha: EigenTrustAlpha,
},
InitialTrustSource: intermediatereputation.InitialTrustSource{
Trust: reputation.TrustValueFromFloat64(EigenTrustInitialTrust),
NetMap: nmSrc,
},
IntermediateValueTarget: intermediateTrustRouter,
WorkerPool: c.cfgReputation.workerPool,

View file

@ -1,6 +1,10 @@
package intermediate
import (
"errors"
"fmt"
"github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
@ -10,12 +14,24 @@ import (
// InitialTrustSource is implementation of the
// reputation/eigentrust/calculator's InitialTrustSource interface.
type InitialTrustSource struct {
Trust reputation.TrustValue
NetMap netmap.Source
}
var ErrEmptyNetMap = errors.New("empty NepMap")
// InitialTrust returns `initialTrust` as initial trust value.
func (i InitialTrustSource) InitialTrust(reputation.PeerID) (reputation.TrustValue, error) {
return i.Trust, nil
nm, err := i.NetMap.GetNetMap(1)
if err != nil {
return reputation.TrustZero, fmt.Errorf("failed to get NetMap: %w", err)
}
nodeCount := reputation.TrustValueFromFloat64(float64(len(nm.Nodes)))
if nodeCount == 0 {
return reputation.TrustZero, ErrEmptyNetMap
}
return reputation.TrustOne.Div(nodeCount), nil
}
// DaughtersTrustCalculator wraps EigenTrust calculator and implements