[#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 <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-29 19:01:35 +03:00 committed by Alex Vanin
parent 0c42db2c3c
commit 118f7fb309

View file

@ -28,15 +28,18 @@ func (np *Processor) processAddPeer(node []byte) {
return return
} }
keyString := hex.EncodeToString(nodeInfo.PublicKey)
np.log.Info("approving network map candidate", np.log.Info("approving network map candidate",
zap.String("key", hex.EncodeToString(nodeInfo.PublicKey)), zap.String("key", keyString))
)
exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter())
if !exists {
err = invoke.ApprovePeer(np.morphClient, np.netmapContract, node) err = invoke.ApprovePeer(np.morphClient, np.netmapContract, node)
if err != nil { if err != nil {
np.log.Error("can't invoke netmap.AddPeer", zap.Error(err)) np.log.Error("can't invoke netmap.AddPeer", zap.Error(err))
} }
} }
}
// Process new epoch tick by invoking new epoch method in network map contract. // Process new epoch tick by invoking new epoch method in network map contract.
func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) { func (np *Processor) processUpdatePeer(ev netmapEvent.UpdatePeer) {