[#488] cmd/cfg: Update cfgReputation

Add `alpha` and `workerPool` to
`cfgReputation` structure.

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-04-21 08:29:35 +03:00 committed by Alex Vanin
parent f6783f4f81
commit 35ec694b04

View file

@ -100,6 +100,11 @@ const (
cfgContainerWorkerPoolEnabled = "container.async_worker.enabled"
cfgContainerWorkerPoolSize = "container.async_worker.size"
// config keys for cfgReputation
cfgReputationAlpha = "reputation.alpha"
cfgReputationWorkerPoolEnabled = "reputation.async_worker.enabled"
cfgReputationWorkerPoolSize = "reputation.async_worker.size"
cfgGCQueueSize = "gc.queuesize"
cfgGCQueueTick = "gc.duration.sleep"
cfgGCTimeout = "gc.duration.timeout"
@ -314,6 +319,11 @@ 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
localTrustCtrl *trustcontroller.Controller
@ -361,6 +371,9 @@ func initCfg(path string) *cfg {
netmapWorkerPool, err := initNetmapWorkerPool(viperCfg)
fatalOnErr(err)
reputationWorkerPool, err := initReputationWorkerPool(viperCfg)
fatalOnErr(err)
relayOnly := viperCfg.GetBool(cfgReBootstrapRelay)
c := &cfg{
@ -408,6 +421,10 @@ func initCfg(path string) *cfg {
},
netStatus: atomic.NewInt32(int32(control.NetmapStatus_STATUS_UNDEFINED)),
healthStatus: atomic.NewInt32(int32(control.HealthStatus_HEALTH_STATUS_UNDEFINED)),
cfgReputation: cfgReputation{
alpha: viper.GetFloat64(cfgReputationAlpha),
workerPool: reputationWorkerPool,
},
}
if viperCfg.GetBool(cfgMetricsEnable) {
@ -461,6 +478,10 @@ 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)
v.SetDefault(cfgNetmapContract, "75194459637323ea8837d2afe8225ec74a5658c3")
v.SetDefault(cfgNetmapFee, "1")
v.SetDefault(cfgNetmapWorkerPoolEnabled, true)
@ -782,6 +803,16 @@ func initContainerWorkerPool(v *viper.Viper) (util2.WorkerPool, error) {
return util2.SyncWorkerPool{}, nil
}
func initReputationWorkerPool(v *viper.Viper) (util2.WorkerPool, error) {
if v.GetBool(cfgReputationWorkerPoolEnabled) {
// return async worker pool
return ants.NewPool(v.GetInt(cfgReputationWorkerPoolSize))
}
// return sync worker pool
return util2.SyncWorkerPool{}, nil
}
func (c *cfg) LocalNodeInfo() (*netmapV2.NodeInfo, error) {
ni := c.localNodeInfo()
return ni.ToV2(), nil