From 25ea5fea907c9ca87e4cd13bbcadc8d3716c403d Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Tue, 4 May 2021 13:10:41 +0300 Subject: [PATCH] [#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 --- cmd/neofs-node/reputation.go | 3 +-- .../reputation/intermediate/calculator.go | 20 +++++++++++++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index 3b4a0be3e..fe5947203 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -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, diff --git a/cmd/neofs-node/reputation/intermediate/calculator.go b/cmd/neofs-node/reputation/intermediate/calculator.go index 157ed94c9..a59293538 100644 --- a/cmd/neofs-node/reputation/intermediate/calculator.go +++ b/cmd/neofs-node/reputation/intermediate/calculator.go @@ -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