[#938] ir/netmap: Call AddPeer method if existing candidate was updated

In previous implementation IR handler of `AddPeer` notification didn't send
registration to contract if existing peer changed has changed its
information. as a consequence, the network map members could not update the
information without going into offline.

Change `processAddPeer` handler to check if
  * candidate in the network map is a brand new
  * or information about the network map member was changed
and call `AddPeer` method if so.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2021-11-08 16:21:48 +03:00 committed by Alex Vanin
parent 0ec8f529ab
commit 68565d9617
3 changed files with 66 additions and 34 deletions

View file

@ -25,10 +25,13 @@ func TestCleanupTable(t *testing.T) {
networkMap, err := netmap.NewNetmap(netmap.NodesFromInfo(infos))
require.NoError(t, err)
mapInfos := map[string]struct{}{
hex.EncodeToString(infos[0].PublicKey()): {},
hex.EncodeToString(infos[1].PublicKey()): {},
hex.EncodeToString(infos[2].PublicKey()): {},
mapInfos := make(map[string][]byte)
for i := range infos {
binNodeInfo, err := infos[i].Marshal()
require.NoError(t, err)
mapInfos[hex.EncodeToString(infos[i].PublicKey())] = binNodeInfo
}
t.Run("update", func(t *testing.T) {
@ -59,10 +62,15 @@ func TestCleanupTable(t *testing.T) {
c.update(networkMap, 1)
key := hex.EncodeToString(infos[1].PublicKey())
require.True(t, c.touch(key, 11))
require.False(t, c.touch(key, 11, mapInfos[key]))
require.EqualValues(t, 11, c.lastAccess[key].epoch)
require.False(t, c.touch(key+"x", 12))
updNodeInfo := []byte("changed node info")
require.True(t, c.touch(key, 11, updNodeInfo))
require.EqualValues(t, 11, c.lastAccess[key].epoch)
require.True(t, c.touch(key+"x", 12, updNodeInfo))
require.EqualValues(t, 12, c.lastAccess[key+"x"].epoch)
})
@ -74,7 +82,7 @@ func TestCleanupTable(t *testing.T) {
c.flag(key)
require.True(t, c.lastAccess[key].removeFlag)
require.False(t, c.touch(key, 2))
require.True(t, c.touch(key, 2, mapInfos[key]))
require.False(t, c.lastAccess[key].removeFlag)
})
@ -108,7 +116,7 @@ func TestCleanupTable(t *testing.T) {
cnt := 0
key := hex.EncodeToString(infos[1].PublicKey())
require.False(t, c.touch(key, 4)) // one node was updated
require.True(t, c.touch(key, 4, mapInfos[key])) // one node was updated
require.NoError(t,
c.forEachRemoveCandidate(4, func(s string) error {