[#60] cmd/neofs-node: Initialize network state on boot

Get current epoch number from morph client and store the value in local
state structure.

Signed-off-by: Leonard Lyubich <leonard@nspcc.ru>
remotes/KirillovDenis/release/v0.21.1
Leonard Lyubich 2020-10-21 19:26:38 +03:00 committed by Alex Vanin
parent dae94aa230
commit 0bdfd18469
1 changed files with 14 additions and 0 deletions

View File

@ -10,6 +10,7 @@ import (
netmapService "github.com/nspcc-dev/neofs-node/pkg/services/netmap"
"github.com/pkg/errors"
"go.uber.org/atomic"
"go.uber.org/zap"
)
// primary solution of local network state dump.
@ -58,6 +59,8 @@ func initNetmapService(c *cfg) {
}
func bootstrapNode(c *cfg) {
initState(c)
err := c.cfgNetmap.wrapper.AddPeer(c.cfgNodeInfo.info)
fatalOnErr(errors.Wrap(err, "bootstrap error"))
}
@ -82,6 +85,17 @@ func setNetmapNotificationParser(c *cfg, sTyp string, p event.Parser) {
c.cfgNetmap.parsers[typ] = p
}
func initState(c *cfg) {
epoch, err := c.cfgNetmap.wrapper.Epoch()
fatalOnErr(errors.Wrap(err, "could not initialize current epoch number"))
c.log.Info("initial epoch number",
zap.Uint64("value", epoch),
)
c.cfgNetmap.state.setCurrentEpoch(epoch)
}
func addNewEpochNotificationHandler(c *cfg, h event.Handler) {
addNetmapNotificationHandler(c, newEpochNotification, h)
}