From 9fcc80ea383f12267aebfcea45d58c443dda9f18 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Mon, 19 Sep 2022 20:59:23 +0400 Subject: [PATCH] [#1680] node/control: Send request to switch to `MAINTENANCE` state After recent changes `MAINTENANCE` state is reflected in the Sidechain. Storage node should switch its state to "maintenance" during serving the `ControlService.SetNetmapStatus` RPC with correspoding status in the request. Call `UpdatePeerState` operation of Netmap contract's client in `control.NodeState` provider on Storage node app side. The op is executed if `BlockExecution` on local object storage is succeeded. Signed-off-by: Leonard Lyubich --- cmd/neofs-node/netmap.go | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index bc68a44b4..7b0057f35 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -325,7 +325,14 @@ func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error { default: return fmt.Errorf("unsupported status %v", st) case control.NetmapStatus_MAINTENANCE: - return c.cfgObject.cfgLocalStorage.localStorage.BlockExecution(errNodeMaintenance) + err := c.cfgObject.cfgLocalStorage.localStorage.BlockExecution(errNodeMaintenance) + if err != nil { + return fmt.Errorf("block execution of local object storage: %w", err) + } + + // TODO: #1691 think how to process two different actions which can fail both + + return c.updateNetMapState((*nmClient.UpdatePeerPrm).SetMaintenance) case control.NetmapStatus_ONLINE, control.NetmapStatus_OFFLINE: } @@ -347,9 +354,15 @@ func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error { c.cfgNetmap.reBoostrapTurnedOff.Store(true) - prm := nmClient.UpdatePeerPrm{} + return c.updateNetMapState(func(*nmClient.UpdatePeerPrm) {}) +} +// calls UpdatePeerState operation of Netmap contract's client for the local node. +// State setter is used to specify node state to switch to. +func (c *cfg) updateNetMapState(stateSetter func(*nmClient.UpdatePeerPrm)) error { + var prm nmClient.UpdatePeerPrm prm.SetKey(c.key.PublicKey().Bytes()) + stateSetter(&prm) return c.cfgNetmap.wrapper.UpdatePeerState(prm) }