From bdb8243a5ab0dfd76f28fd0447d9b8b35893897f Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 19 Sep 2022 20:21:35 +0400 Subject: [PATCH] [#1681] morph/netmap: Support MAINTENANCE state notification After recent changes Netmap contract can send `UpdateState` notification event with `MAINTENANCE` node's state. There is a need to provide functionality to work with the status. Provide `UpdatePeer.Maintenance` method. Support new state in `ParseUpdatePeer` and `ParseUpdatePeerNotary` functions. Signed-off-by: Leonard Lyubich --- pkg/morph/event/netmap/update_peer.go | 11 +++++++++++ pkg/morph/event/netmap/update_peer_notary.go | 10 ++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pkg/morph/event/netmap/update_peer.go b/pkg/morph/event/netmap/update_peer.go index d83da6a5..2eb61048 100644 --- a/pkg/morph/event/netmap/update_peer.go +++ b/pkg/morph/event/netmap/update_peer.go @@ -16,6 +16,7 @@ import ( const ( _ int8 = iota stateOnline + stateMaintenance ) type UpdatePeer struct { @@ -31,10 +32,18 @@ type UpdatePeer struct { // MorphEvent implements Neo:Morph Event interface. func (UpdatePeer) MorphEvent() {} +// Online returns true if node's state is requested to be switched +// to "online". func (s UpdatePeer) Online() bool { return s.state == stateOnline } +// Maintenance returns true if node's state is requested to be switched +// to "maintenance". +func (s UpdatePeer) Maintenance() bool { + return s.state == stateMaintenance +} + func (s UpdatePeer) PublicKey() *keys.PublicKey { return s.publicKey } @@ -85,6 +94,8 @@ func ParseUpdatePeer(e *state.ContainedNotificationEvent) (event.Event, error) { case int64(netmap.OfflineState): case int64(netmap.OnlineState): ev.state = stateOnline + case int64(netmap.OfflineState) + 1: // FIXME: use named constant after neofs-contract#269 + ev.state = stateMaintenance } return ev, nil diff --git a/pkg/morph/event/netmap/update_peer_notary.go b/pkg/morph/event/netmap/update_peer_notary.go index 1c1b8b36..eb780895 100644 --- a/pkg/morph/event/netmap/update_peer_notary.go +++ b/pkg/morph/event/netmap/update_peer_notary.go @@ -7,7 +7,7 @@ import ( "github.com/nspcc-dev/neo-go/pkg/crypto/keys" "github.com/nspcc-dev/neo-go/pkg/vm/opcode" - v2netmap "github.com/nspcc-dev/neofs-api-go/v2/netmap" + "github.com/nspcc-dev/neofs-contract/netmap" "github.com/nspcc-dev/neofs-node/pkg/morph/event" ) @@ -61,12 +61,14 @@ func ParseUpdatePeerNotary(ne event.NotaryEvent) (event.Event, error) { return nil, err } - switch v2netmap.NodeState(state) { + switch state { default: return nil, fmt.Errorf("unsupported node state %d", err) - case v2netmap.Offline: - case v2netmap.Online: + case int64(netmap.OfflineState): + case int64(netmap.OnlineState): ev.state = stateOnline + case int64(netmap.OfflineState) + 1: // FIXME: use named constant after neofs-contract#269 + ev.state = stateMaintenance } fieldNum++