From 71f18ba9ecdfb11360472066960a74c3b771a163 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Fri, 13 May 2022 21:35:37 +0300 Subject: [PATCH] [#1224] morph: Call Alphabet methods flexibly Call `UpdateStateIR` and `AddPeerIR` method instead of `UpdateState` and `AddPeer` if calling client is configured as Alphabet in notary enabled environment. Signed-off-by: Pavel Karpy --- pkg/morph/client/netmap/add_peer.go | 17 +++++++++++++---- pkg/morph/client/netmap/update_state.go | 11 ++++++++++- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/pkg/morph/client/netmap/add_peer.go b/pkg/morph/client/netmap/add_peer.go index 421178539..b5736a9df 100644 --- a/pkg/morph/client/netmap/add_peer.go +++ b/pkg/morph/client/netmap/add_peer.go @@ -22,22 +22,31 @@ func (a *AddPeerPrm) SetNodeInfo(nodeInfo *netmap.NodeInfo) { // AddPeer registers peer in NeoFS network through // Netmap contract call. func (c *Client) AddPeer(p AddPeerPrm) error { + var method = addPeerMethod + + if c.client.WithNotary() && c.client.IsAlpha() { + // In notary environments Alphabet must calls AddPeerIR method instead of AddPeer. + // It differs from AddPeer only by name, so we can do this in the same form. + // See https://github.com/nspcc-dev/neofs-contract/issues/154. + method += "IR" + } + if p.nodeInfo == nil { - return fmt.Errorf("nil node info (%s)", addPeerMethod) + return fmt.Errorf("nil node info (%s)", method) } rawNodeInfo, err := p.nodeInfo.Marshal() if err != nil { - return fmt.Errorf("can't marshal node info (%s): %w", addPeerMethod, err) + return fmt.Errorf("can't marshal node info (%s): %w", method, err) } prm := client.InvokePrm{} - prm.SetMethod(addPeerMethod) + prm.SetMethod(method) prm.SetArgs(rawNodeInfo) prm.InvokePrmOptional = p.InvokePrmOptional if err := c.client.Invoke(prm); err != nil { - return fmt.Errorf("could not invoke method (%s): %w", addPeerMethod, err) + return fmt.Errorf("could not invoke method (%s): %w", method, err) } return nil } diff --git a/pkg/morph/client/netmap/update_state.go b/pkg/morph/client/netmap/update_state.go index 695478f19..9bd83f7ff 100644 --- a/pkg/morph/client/netmap/update_state.go +++ b/pkg/morph/client/netmap/update_state.go @@ -27,8 +27,17 @@ func (u *UpdatePeerPrm) SetState(state netmap.NodeState) { // UpdatePeerState changes peer status through Netmap contract call. func (c *Client) UpdatePeerState(p UpdatePeerPrm) error { + method := updateStateMethod + + if c.client.WithNotary() && c.client.IsAlpha() { + // In notary environments Alphabet must calls UpdateStateIR method instead of UpdateState. + // It differs from UpdateState only by name, so we can do this in the same form. + // See https://github.com/nspcc-dev/neofs-contract/issues/225. + method += "IR" + } + prm := client.InvokePrm{} - prm.SetMethod(updateStateMethod) + prm.SetMethod(method) prm.SetArgs(int64(p.state.ToV2()), p.key) prm.InvokePrmOptional = p.InvokePrmOptional