From 118f7fb30999159d9eb6501baf62dc2548e0ba03 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Thu, 29 Oct 2020 19:01:35 +0300 Subject: [PATCH] [#132] Put new storage peers in netmap cleaner cache There is an optimization to send ApprovePeer tx only in case if `touch` returns false. It returns false if node is not in the cache or it was flagged to removal. Signed-off-by: Alex Vanin --- pkg/innerring/processors/netmap/process_peers.go | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/pkg/innerring/processors/netmap/process_peers.go b/pkg/innerring/processors/netmap/process_peers.go index 1aece6441..b8da13078 100644 --- a/pkg/innerring/processors/netmap/process_peers.go +++ b/pkg/innerring/processors/netmap/process_peers.go @@ -28,13 +28,16 @@ func (np *Processor) processAddPeer(node []byte) { return } + keyString := hex.EncodeToString(nodeInfo.PublicKey) np.log.Info("approving network map candidate", - zap.String("key", hex.EncodeToString(nodeInfo.PublicKey)), - ) + zap.String("key", keyString)) - err = invoke.ApprovePeer(np.morphClient, np.netmapContract, node) - if err != nil { - np.log.Error("can't invoke netmap.AddPeer", zap.Error(err)) + exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter()) + if !exists { + err = invoke.ApprovePeer(np.morphClient, np.netmapContract, node) + if err != nil { + np.log.Error("can't invoke netmap.AddPeer", zap.Error(err)) + } } }