[#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 <leonard@nspcc.ru>
This commit is contained in:
Leonard Lyubich 2022-09-19 20:59:23 +04:00 committed by fyrchik
parent 6a2ec21641
commit 9fcc80ea38

View file

@ -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)
}