2021-03-31 15:38:01 +00:00
|
|
|
package reputation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/hex"
|
|
|
|
|
2021-04-05 09:29:33 +00:00
|
|
|
"github.com/nspcc-dev/neofs-api-go/pkg/reputation"
|
2021-03-31 15:38:01 +00:00
|
|
|
"github.com/nspcc-dev/neofs-node/pkg/morph/client/reputation/wrapper"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
)
|
|
|
|
|
2021-04-05 09:29:33 +00:00
|
|
|
func (rp *Processor) processPut(epoch uint64, id reputation.PeerID, value reputation.GlobalTrust) {
|
2021-03-31 15:38:01 +00:00
|
|
|
if !rp.alphabetState.IsAlphabet() {
|
|
|
|
rp.log.Info("non alphabet mode, ignore reputation put notification")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-04-05 09:29:33 +00:00
|
|
|
// check if epoch is valid
|
|
|
|
currentEpoch := rp.epochState.EpochCounter()
|
|
|
|
if epoch >= currentEpoch {
|
|
|
|
rp.log.Info("ignore reputation value",
|
|
|
|
zap.String("reason", "invalid epoch number"),
|
|
|
|
zap.Uint64("trust_epoch", epoch),
|
|
|
|
zap.Uint64("local_epoch", currentEpoch))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// check signature
|
|
|
|
if err := value.VerifySignature(); err != nil {
|
|
|
|
rp.log.Info("ignore reputation value",
|
|
|
|
zap.String("reason", "invalid signature"),
|
|
|
|
zap.String("error", err.Error()))
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// todo: do sanity checks of value
|
2021-03-31 15:38:01 +00:00
|
|
|
|
|
|
|
args := wrapper.PutArgs{}
|
|
|
|
args.SetEpoch(epoch)
|
|
|
|
args.SetPeerID(id)
|
|
|
|
args.SetValue(value)
|
|
|
|
|
2021-04-29 13:40:34 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
if rp.notaryDisabled {
|
|
|
|
err = rp.reputationWrp.Put(args)
|
|
|
|
} else {
|
|
|
|
err = rp.reputationWrp.PutViaNotary(args)
|
|
|
|
}
|
|
|
|
|
2021-03-31 15:38:01 +00:00
|
|
|
if err != nil {
|
|
|
|
rp.log.Warn("can't send approval tx for reputation value",
|
2021-04-05 09:29:33 +00:00
|
|
|
zap.String("peer_id", hex.EncodeToString(id.ToV2().GetValue())),
|
2021-03-31 15:38:01 +00:00
|
|
|
zap.String("error", err.Error()))
|
|
|
|
}
|
|
|
|
}
|