From 0bdfd184693c7d0525afe0dbcaf0c88f47811a43 Mon Sep 17 00:00:00 2001 From: Leonard Lyubich Date: Wed, 21 Oct 2020 19:26:38 +0300 Subject: [PATCH] [#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 --- cmd/neofs-node/netmap.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 25036e9a..2c7946a6 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -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) }