forked from TrueCloudLab/frostfs-node
[#812] pkg/innerring: Support notary notifications in reputation processor
Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
parent
a7f6a3df78
commit
dc26a09ec3
4 changed files with 65 additions and 24 deletions
|
@ -8,18 +8,23 @@ import (
|
|||
|
||||
apireputation "github.com/nspcc-dev/neofs-api-go/pkg/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
||||
reputationEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/reputation"
|
||||
"github.com/nspcc-dev/neofs-node/pkg/services/reputation"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var errWrongManager = errors.New("got manager that is incorrect for peer")
|
||||
|
||||
func (rp *Processor) processPut(epoch uint64, id apireputation.PeerID, value apireputation.GlobalTrust) {
|
||||
func (rp *Processor) processPut(e *reputationEvent.Put) {
|
||||
if !rp.alphabetState.IsAlphabet() {
|
||||
rp.log.Info("non alphabet mode, ignore reputation put notification")
|
||||
return
|
||||
}
|
||||
|
||||
epoch := e.Epoch()
|
||||
id := e.PeerID()
|
||||
value := e.Value()
|
||||
|
||||
// check if epoch is valid
|
||||
currentEpoch := rp.epochState.EpochCounter()
|
||||
if epoch >= currentEpoch {
|
||||
|
@ -49,18 +54,7 @@ func (rp *Processor) processPut(epoch uint64, id apireputation.PeerID, value api
|
|||
return
|
||||
}
|
||||
|
||||
args := wrapper.PutArgs{}
|
||||
args.SetEpoch(epoch)
|
||||
args.SetPeerID(id)
|
||||
args.SetValue(value)
|
||||
|
||||
err := rp.reputationWrp.Put(args)
|
||||
if err != nil {
|
||||
// FIXME: do not use `ToV2` method outside neofs-api-go library
|
||||
rp.log.Warn("can't send approval tx for reputation value",
|
||||
zap.String("peer_id", hex.EncodeToString(id.ToV2().GetPublicKey())),
|
||||
zap.String("error", err.Error()))
|
||||
}
|
||||
rp.approvePutReputation(e)
|
||||
}
|
||||
|
||||
func (rp *Processor) checkManagers(e uint64, mng apireputation.PeerID, peer apireputation.PeerID) error {
|
||||
|
@ -78,3 +72,28 @@ func (rp *Processor) checkManagers(e uint64, mng apireputation.PeerID, peer apir
|
|||
|
||||
return errWrongManager
|
||||
}
|
||||
|
||||
func (rp *Processor) approvePutReputation(e *reputationEvent.Put) {
|
||||
var (
|
||||
id = e.PeerID()
|
||||
err error
|
||||
)
|
||||
|
||||
if nr := e.NotaryRequest(); nr != nil {
|
||||
// put event was received via Notary service
|
||||
err = rp.reputationWrp.Morph().NotarySignAndInvokeTX(nr.MainTransaction)
|
||||
} else {
|
||||
args := wrapper.PutArgs{}
|
||||
args.SetEpoch(e.Epoch())
|
||||
args.SetPeerID(id)
|
||||
args.SetValue(e.Value())
|
||||
|
||||
err = rp.reputationWrp.Put(args)
|
||||
}
|
||||
if err != nil {
|
||||
// FIXME: do not use `ToV2` method outside neofs-api-go library
|
||||
rp.log.Warn("can't send approval tx for reputation value",
|
||||
zap.String("peer_id", hex.EncodeToString(id.ToV2().GetPublicKey())),
|
||||
zap.String("error", err.Error()))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue