diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index 719398ac..6c632a6e 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -836,26 +836,12 @@ func (c *cfg) handleLocalNodeInfo(ni *netmap.NodeInfo) { c.cfgNetmap.state.setNodeInfo(ni) } -// bootstrap sets local node's netmap status to "online". -// If current netmap status is MAINTENANCE and this function wasn't called thorough a control service, -// the status is untouched. -func (c *cfg) bootstrap(manual bool) error { +// bootstrapWithState calls "addPeer" method of the Sidechain Netmap contract +// with the binary-encoded information from the current node's configuration. +// The state is set using the provided setter which MUST NOT be nil. +func (c *cfg) bootstrapWithState(stateSetter func(*netmap.NodeInfo)) error { ni := c.cfgNodeInfo.localInfo - - // switch to online except when under maintenance - if st := c.cfgNetmap.state.controlNetmapStatus(); st == control.NetmapStatus_MAINTENANCE && !manual { - ni.SetMaintenance() - - c.log.Info("bootstrap with untouched node state", - zap.Stringer("state", st), - ) - } else { - ni.SetOnline() - - c.log.Info("bootstrapping with online state", - zap.Stringer("previous", st), - ) - } + stateSetter(&ni) prm := nmClient.AddPeerPrm{} prm.SetNodeInfo(ni) @@ -863,6 +849,29 @@ func (c *cfg) bootstrap(manual bool) error { return c.cfgNetmap.wrapper.AddPeer(prm) } +// bootstrapOnline calls cfg.bootstrapWithState with "online" state. +func bootstrapOnline(c *cfg) error { + return c.bootstrapWithState((*netmap.NodeInfo).SetOnline) +} + +// bootstrap calls bootstrapWithState with: +// - "maintenance" state if maintenance is in progress on the current node +// - "online", otherwise +func (c *cfg) bootstrap() error { + // switch to online except when under maintenance + st := c.cfgNetmap.state.controlNetmapStatus() + if st == control.NetmapStatus_MAINTENANCE { + c.log.Info("bootstrapping with the maintenance state") + return c.bootstrapWithState((*netmap.NodeInfo).SetMaintenance) + } + + c.log.Info("bootstrapping with online state", + zap.Stringer("previous", st), + ) + + return bootstrapOnline(c) +} + // needBootstrap checks if local node should be registered in network on bootup. func (c *cfg) needBootstrap() bool { return c.cfgNetmap.needBootstrap diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 1bd05054..3c12faf8 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -179,7 +179,7 @@ func initNetmapService(c *cfg) { const reBootstrapInterval = 2 if (n-c.cfgNetmap.startEpoch)%reBootstrapInterval == 0 { - err := c.bootstrap(false) + err := c.bootstrap() if err != nil { c.log.Warn("can't send re-bootstrap tx", zap.Error(err)) } @@ -241,7 +241,7 @@ func readSubnetCfg(c *cfg) { // Must be called after initNetmapService. func bootstrapNode(c *cfg) { if c.needBootstrap() { - err := c.bootstrap(false) + err := c.bootstrap() fatalOnErrDetails("bootstrap error", err) } } @@ -352,7 +352,7 @@ func (c *cfg) SetNetmapStatus(st control.NetmapStatus) error { if st == control.NetmapStatus_ONLINE { c.cfgNetmap.reBoostrapTurnedOff.Store(false) - return c.bootstrap(true) + return bootstrapOnline(c) } c.cfgNetmap.reBoostrapTurnedOff.Store(true)