[#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:
parent
d1db54acf8
commit
25ea5fea90
2 changed files with 19 additions and 4 deletions
|
@ -38,7 +38,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const EigenTrustAlpha = 0.1
|
const EigenTrustAlpha = 0.1
|
||||||
const EigenTrustInitialTrust = 0.5
|
|
||||||
|
|
||||||
func initReputationService(c *cfg) {
|
func initReputationService(c *cfg) {
|
||||||
staticClient, err := client.NewStatic(
|
staticClient, err := client.NewStatic(
|
||||||
|
@ -154,7 +153,7 @@ func initReputationService(c *cfg) {
|
||||||
Alpha: EigenTrustAlpha,
|
Alpha: EigenTrustAlpha,
|
||||||
},
|
},
|
||||||
InitialTrustSource: intermediatereputation.InitialTrustSource{
|
InitialTrustSource: intermediatereputation.InitialTrustSource{
|
||||||
Trust: reputation.TrustValueFromFloat64(EigenTrustInitialTrust),
|
NetMap: nmSrc,
|
||||||
},
|
},
|
||||||
IntermediateValueTarget: intermediateTrustRouter,
|
IntermediateValueTarget: intermediateTrustRouter,
|
||||||
WorkerPool: c.cfgReputation.workerPool,
|
WorkerPool: c.cfgReputation.workerPool,
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package intermediate
|
package intermediate
|
||||||
|
|
||||||
import (
|
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"
|
||||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
"github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust"
|
||||||
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
eigencalc "github.com/nspcc-dev/neofs-node/pkg/services/reputation/eigentrust/calculator"
|
||||||
|
@ -10,12 +14,24 @@ import (
|
||||||
// InitialTrustSource is implementation of the
|
// InitialTrustSource is implementation of the
|
||||||
// reputation/eigentrust/calculator's InitialTrustSource interface.
|
// reputation/eigentrust/calculator's InitialTrustSource interface.
|
||||||
type InitialTrustSource struct {
|
type InitialTrustSource struct {
|
||||||
Trust reputation.TrustValue
|
NetMap netmap.Source
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var ErrEmptyNetMap = errors.New("empty NepMap")
|
||||||
|
|
||||||
// InitialTrust returns `initialTrust` as initial trust value.
|
// InitialTrust returns `initialTrust` as initial trust value.
|
||||||
func (i InitialTrustSource) InitialTrust(reputation.PeerID) (reputation.TrustValue, error) {
|
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
|
// DaughtersTrustCalculator wraps EigenTrust calculator and implements
|
||||||
|
|
Loading…
Reference in a new issue