diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index a2658c125f..c7bc59a5a2 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -102,7 +102,6 @@ const ( // config keys for cfgReputation cfgReputationContract = "reputation.scripthash" - cfgReputationAlpha = "reputation.alpha" cfgReputationWorkerPoolEnabled = "reputation.async_worker.enabled" cfgReputationWorkerPoolSize = "reputation.async_worker.size" @@ -320,9 +319,6 @@ type cfgControlService struct { } type cfgReputation struct { - // Alpha parameter from origin EigenTrust algorithm - // http://ilpubs.stanford.edu:8090/562/1/2002-56.pdf Ch.5.1. - alpha float64 workerPool util2.WorkerPool // pool for EigenTrust algorithm's iterations localTrustStorage *truststorage.Storage @@ -430,7 +426,6 @@ func initCfg(path string) *cfg { healthStatus: atomic.NewInt32(int32(control.HealthStatus_HEALTH_STATUS_UNDEFINED)), cfgReputation: cfgReputation{ scriptHash: u160Reputation, - alpha: viper.GetFloat64(cfgReputationAlpha), workerPool: reputationWorkerPool, }, } @@ -486,7 +481,6 @@ func defaultConfiguration(v *viper.Viper) { v.SetDefault(cfgContainerWorkerPoolEnabled, true) v.SetDefault(cfgContainerWorkerPoolSize, 10) - v.SetDefault(cfgReputationAlpha, 0.5) v.SetDefault(cfgReputationWorkerPoolEnabled, true) v.SetDefault(cfgReputationWorkerPoolSize, 10) diff --git a/cmd/neofs-node/reputation/intermediate/calculator.go b/cmd/neofs-node/reputation/intermediate/calculator.go index 11f69adfcd..2bd671ebe4 100644 --- a/cmd/neofs-node/reputation/intermediate/calculator.go +++ b/cmd/neofs-node/reputation/intermediate/calculator.go @@ -25,3 +25,13 @@ func (c *DaughtersTrustCalculator) Calculate(ctx eigentrustctrl.IterationContext c.Calculator.Calculate(calcPrm) } + +// AlphaProvider provides required alpha parameter of eigen trust algorithm. +// TODO: decide if `Alpha` should be dynamically read from global config. #497 +type AlphaProvider struct { + Alpha float64 +} + +func (ap AlphaProvider) EigenTrustAlpha() (float64, error) { + return ap.Alpha, nil +} diff --git a/pkg/services/reputation/eigentrust/calculator/calculator.go b/pkg/services/reputation/eigentrust/calculator/calculator.go index 883cecf8ca..9cb5acaff3 100644 --- a/pkg/services/reputation/eigentrust/calculator/calculator.go +++ b/pkg/services/reputation/eigentrust/calculator/calculator.go @@ -18,7 +18,7 @@ type Prm struct { // http://ilpubs.stanford.edu:8090/562/1/2002-56.pdf Ch.5.1. // // Must be in range (0, 1). - Alpha float64 + AlphaProvider AlphaProvider // Source of initial node trust values // @@ -63,8 +63,8 @@ func panicOnPrmValue(n string, v interface{}) { // initialization and is completely ready for work. func New(prm Prm, opts ...Option) *Calculator { switch { - case prm.Alpha <= 0 || prm.Alpha >= 1: - panicOnPrmValue("Alpha", prm.Alpha) + case prm.AlphaProvider == nil: + panicOnPrmValue("AlphaProvider", prm.AlphaProvider) case prm.InitialTrustSource == nil: panicOnPrmValue("InitialTrustSource", prm.InitialTrustSource) case prm.DaughterTrustSource == nil: @@ -84,9 +84,7 @@ func New(prm Prm, opts ...Option) *Calculator { } return &Calculator{ - alpha: reputation.TrustValueFromFloat64(prm.Alpha), - beta: reputation.TrustValueFromFloat64(1 - prm.Alpha), - prm: prm, - opts: o, + prm: prm, + opts: o, } } diff --git a/pkg/services/reputation/eigentrust/calculator/calls.go b/pkg/services/reputation/eigentrust/calculator/calls.go index a4f24ce421..ef4ab52e2f 100644 --- a/pkg/services/reputation/eigentrust/calculator/calls.go +++ b/pkg/services/reputation/eigentrust/calculator/calls.go @@ -24,6 +24,18 @@ func (p *CalculatePrm) SetEpochIteration(ei eigentrust.EpochIteration) { } func (c *Calculator) Calculate(prm CalculatePrm) { + alpha, err := c.prm.AlphaProvider.EigenTrustAlpha() + if err != nil { + c.opts.log.Debug( + "failed to get alpha param", + zap.Error(err), + ) + return + } + + c.alpha = reputation.TrustValueFromFloat64(alpha) + c.beta = reputation.TrustValueFromFloat64(1 - alpha) + ctx := eigentrust.IterContext{ Context: context.Background(), EpochIteration: prm.ei, diff --git a/pkg/services/reputation/eigentrust/calculator/deps.go b/pkg/services/reputation/eigentrust/calculator/deps.go index f94de3d490..aed381a5f7 100644 --- a/pkg/services/reputation/eigentrust/calculator/deps.go +++ b/pkg/services/reputation/eigentrust/calculator/deps.go @@ -59,3 +59,9 @@ type IntermediateWriter interface { type IntermediateWriterProvider interface { InitIntermediateWriter(Context) (IntermediateWriter, error) } + +// AlphaProvider must provide information about required +// alpha parameter for eigen trust algorithm. +type AlphaProvider interface { + EigenTrustAlpha() (float64, error) +} diff --git a/pkg/services/reputation/eigentrust/controller/deps.go b/pkg/services/reputation/eigentrust/controller/deps.go index ade2f6a2da..8c4752657e 100644 --- a/pkg/services/reputation/eigentrust/controller/deps.go +++ b/pkg/services/reputation/eigentrust/controller/deps.go @@ -34,7 +34,7 @@ type DaughtersTrustCalculator interface { Calculate(ctx IterationContext) } -// IterationsProvider must provides information about numbers +// IterationsProvider must provide information about numbers // of iterations for algorithm. type IterationsProvider interface { EigenTrustIterations() (uint64, error)