[#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

@ -50,27 +50,25 @@ func (np *Processor) processAddPeer(ev netmapEvent.AddPeer) {
})
nodeInfo.SetAttributes(a...)
// marshal updated node info structure
nodeInfoBinary, err := nodeInfo.Marshal()
if err != nil {
np.log.Warn("could not marshal updated network map candidate",
zap.String("error", err.Error()),
)
return
}
keyString := hex.EncodeToString(nodeInfo.PublicKey())
exists := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter())
if !exists {
updated := np.netmapSnapshot.touch(keyString, np.epochState.EpochCounter(), nodeInfoBinary)
if updated {
np.log.Info("approving network map candidate",
zap.String("key", keyString))
if nr := ev.NotaryRequest(); nr != nil {
// notary event case
var nodeInfoBinary []byte
nodeInfoBinary, err = nodeInfo.Marshal()
if err != nil {
np.log.Warn("could not marshal updated network map candidate",
zap.String("error", err.Error()),
)
return
}
// create new notary request with the original nonce
err = np.netmapClient.Morph().NotaryInvoke(
np.netmapClient.ContractAddress(),