[#846] innerring: Use epoch as nonce in cleanup netmap process

Signed-off-by: Pavel Karpy <carpawell@nspcc.ru>
This commit is contained in:
Pavel Karpy 2021-09-23 20:13:59 +03:00 committed by Alex Vanin
parent e3c0288e50
commit 5702349cb2
2 changed files with 19 additions and 5 deletions

View file

@ -51,7 +51,7 @@ func (np *Processor) handleAddPeer(ev event.Event) {
// send event to the worker pool
err := np.pool.Submit(func() {
np.processAddPeer(newPeer.Node())
np.processAddPeer(newPeer)
})
if err != nil {
// there system can be moved into controlled degradation stage
@ -91,7 +91,7 @@ func (np *Processor) handleCleanupTick(ev event.Event) {
// send event to the worker pool
err := np.pool.Submit(func() {
np.processNetmapCleanupTick(cleanup.epoch)
np.processNetmapCleanupTick(cleanup)
})
if err != nil {
// there system can be moved into controlled degradation stage

View file

@ -3,17 +3,18 @@ package netmap
import (
"github.com/nspcc-dev/neo-go/pkg/crypto/keys"
"github.com/nspcc-dev/neofs-api-go/pkg/netmap"
netmapEvent "github.com/nspcc-dev/neofs-node/pkg/morph/event/netmap"
"go.uber.org/zap"
)
func (np *Processor) processNetmapCleanupTick(epoch uint64) {
func (np *Processor) processNetmapCleanupTick(ev netmapCleanupTick) {
if !np.alphabetState.IsAlphabet() {
np.log.Info("non alphabet mode, ignore new netmap cleanup tick")
return
}
err := np.netmapSnapshot.forEachRemoveCandidate(epoch, func(s string) error {
err := np.netmapSnapshot.forEachRemoveCandidate(ev.epoch, func(s string) error {
key, err := keys.NewPublicKeyFromString(s)
if err != nil {
np.log.Warn("can't decode public key of netmap node",
@ -24,7 +25,20 @@ func (np *Processor) processNetmapCleanupTick(epoch uint64) {
np.log.Info("vote to remove node from netmap", zap.String("key", s))
err = np.netmapClient.UpdatePeerState(key.Bytes(), netmap.NodeStateOffline)
if np.notaryDisabled {
err = np.netmapClient.UpdatePeerState(key.Bytes(), netmap.NodeStateOffline)
} else {
// use epoch as TX nonce to prevent collisions
err = np.netmapClient.Morph().NotaryInvoke(
np.netmapContract,
0,
uint32(ev.epoch),
netmapEvent.UpdateStateNotaryEvent,
int64(netmap.NodeStateOffline.ToV2()),
key.Bytes(),
)
}
if err != nil {
np.log.Error("can't invoke netmap.UpdateState", zap.Error(err))
}