From 5702349cb24a4d215bd0f52336492bc9ac0ee045 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Thu, 23 Sep 2021 20:13:59 +0300 Subject: [PATCH] [#846] innerring: Use epoch as nonce in cleanup netmap process Signed-off-by: Pavel Karpy --- pkg/innerring/processors/netmap/handlers.go | 4 ++-- .../processors/netmap/process_cleanup.go | 20 ++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/pkg/innerring/processors/netmap/handlers.go b/pkg/innerring/processors/netmap/handlers.go index 23046a8b1..ca83ea2bd 100644 --- a/pkg/innerring/processors/netmap/handlers.go +++ b/pkg/innerring/processors/netmap/handlers.go @@ -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 diff --git a/pkg/innerring/processors/netmap/process_cleanup.go b/pkg/innerring/processors/netmap/process_cleanup.go index 04cd15913..61290de2d 100644 --- a/pkg/innerring/processors/netmap/process_cleanup.go +++ b/pkg/innerring/processors/netmap/process_cleanup.go @@ -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)) }