[#841] ir: Execute netmap.addPeerIR only for state online

Signed-off-by: Anton Nikiforov <an.nikiforov@yadro.com>
This commit is contained in:
Anton Nikiforov 2023-12-05 11:16:44 +03:00
parent db49ad16cc
commit 9d51142696
2 changed files with 21 additions and 1 deletions

View file

@ -144,6 +144,21 @@ func TestAddPeer(t *testing.T) {
time.Sleep(10 * time.Millisecond) time.Sleep(10 * time.Millisecond)
} }
require.Nil(t, nc.notaryInvokes, "invalid notary invokes")
node.SetOnline()
ev = netmapEvent.AddPeer{
NodeBytes: node.Marshal(),
Request: &payload.P2PNotaryRequest{
MainTransaction: &transaction.Transaction{},
},
}
proc.handleAddPeer(ev)
for proc.pool.Running() > 0 {
time.Sleep(10 * time.Millisecond)
}
require.EqualValues(t, []notaryInvoke{ require.EqualValues(t, []notaryInvoke{
{ {
contract: nc.contractAddress, contract: nc.contractAddress,

View file

@ -57,7 +57,12 @@ func (np *Processor) processAddPeer(ev netmapEvent.AddPeer) bool {
updated := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter(), nodeInfoBinary) updated := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter(), nodeInfoBinary)
if updated { // `processAddPeer` reacts on `AddPeer` notification, `processNewEpoch` - on `NewEpoch`.
// This two notification produces in order - `NewEpoch` -> `AddPeer`.
// But there is no guarantee that code will be executed in the same order.
// That is why we need to perform `addPeerIR` only in case when node is online,
// because in scope of this method, contract set state `ONLINE` for the node.
if updated && nodeInfo.IsOnline() {
np.log.Info(logs.NetmapApprovingNetworkMapCandidate, np.log.Info(logs.NetmapApprovingNetworkMapCandidate,
zap.String("key", keyString)) zap.String("key", keyString))