[#428] cmd/node: Trigger local trust controller on new epoch

Implement and call `initReputationService` func that constructs local trust
storage and controller, and subscribes the controller on new epoch
notification. Event handler calls `Controller.Report` method to process
collected values.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-03-23 21:54:00 +03:00 committed by Leonard Lyubich
parent c4a1c70089
commit a6f2394dec
3 changed files with 43 additions and 0 deletions

View file

@ -4,7 +4,10 @@ import (
"bytes"
"encoding/hex"
crypto "github.com/nspcc-dev/neofs-crypto"
netmapcore "github.com/nspcc-dev/neofs-node/pkg/core/netmap"
"github.com/nspcc-dev/neofs-node/pkg/morph/event"
"github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
trustcontroller "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/controller"
truststorage "github.com/nspcc-dev/neofs-node/pkg/services/reputation/local/storage"
@ -117,3 +120,32 @@ func (l *localTrustLogger) Write(t reputation.Trust) error {
func (*localTrustLogger) Close() error {
return nil
}
func initReputationService(c *cfg) {
// consider sharing this between application components
nmSrc := newCachedNetmapStorage(c.cfgNetmap.state, c.cfgNetmap.wrapper)
c.cfgReputation.localTrustStorage = truststorage.New(truststorage.Prm{})
trustStorage := &localTrustStorage{
log: c.log,
storage: c.cfgReputation.localTrustStorage,
nmSrc: nmSrc,
localKey: crypto.MarshalPublicKey(&c.key.PublicKey),
}
c.cfgReputation.localTrustCtrl = trustcontroller.New(trustcontroller.Prm{
LocalTrustSource: trustStorage,
LocalTrustTarget: trustStorage,
})
addNewEpochNotificationHandler(c, func(ev event.Event) {
var reportPrm trustcontroller.ReportPrm
// report collected values from previous epoch
reportPrm.SetEpoch(ev.(netmap.NewEpoch).EpochNumber() - 1)
// TODO: implement and use worker pool [neofs-node#440]
go c.cfgReputation.localTrustCtrl.Report(reportPrm)
})
}