From 2bd827a478f0414be211bfb845aa394aaaf1ba39 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Fri, 30 Oct 2020 15:57:49 +0300 Subject: [PATCH] [#134] Resend bootstrap txs periodically Signed-off-by: Alex Vanin --- cmd/neofs-node/config.go | 17 ++++++++++++++--- cmd/neofs-node/netmap.go | 13 +++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index e2c5c5c94..9d3488c32 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -86,6 +86,9 @@ const ( cfgPolicerHeadTimeout = "policer.head_timeout" cfgReplicatorPutTimeout = "replicator.put_timeout" + + cfgReBootstrapEnabled = "bootstrap.periodic.enabled" + cfgReBootstrapInterval = "bootstrap.periodic.interval" ) const ( @@ -169,6 +172,9 @@ type cfgNetmap struct { subscribers map[event.Type][]event.Handler state *networkState + + reBootstrapEnabled bool + reBootstrapInterval uint64 // in epochs } type BootstrapType uint32 @@ -245,9 +251,11 @@ func initCfg(path string) *cfg { fee: util.Fixed8(viperCfg.GetInt(cfgContainerFee)), }, cfgNetmap: cfgNetmap{ - scriptHash: u160Netmap, - fee: util.Fixed8(viperCfg.GetInt(cfgNetmapFee)), - state: state, + scriptHash: u160Netmap, + fee: util.Fixed8(viperCfg.GetInt(cfgNetmapFee)), + state: state, + reBootstrapInterval: viperCfg.GetUint64(cfgReBootstrapInterval), + reBootstrapEnabled: viperCfg.GetBool(cfgReBootstrapEnabled), }, cfgNodeInfo: cfgNodeInfo{ bootType: StorageNode, @@ -332,6 +340,9 @@ func defaultConfiguration(v *viper.Viper) { v.SetDefault(cfgPolicerHeadTimeout, 5*time.Second) v.SetDefault(cfgReplicatorPutTimeout, 5*time.Second) + + v.SetDefault(cfgReBootstrapEnabled, false) // in epochs + v.SetDefault(cfgReBootstrapInterval, 2) // in epochs } func (c *cfg) LocalAddress() *network.Address { diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index ad149851f..af012486d 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -58,6 +58,19 @@ func initNetmapService(c *cfg) { addNewEpochNotificationHandler(c, func(ev event.Event) { c.cfgNetmap.state.setCurrentEpoch(ev.(netmapEvent.NewEpoch).EpochNumber()) }) + + if c.cfgNetmap.reBootstrapEnabled { + addNewEpochNotificationHandler(c, func(ev event.Event) { + n := ev.(netmapEvent.NewEpoch).EpochNumber() + + if n%c.cfgNetmap.reBootstrapInterval == 0 { + err := c.cfgNetmap.wrapper.AddPeer(c.cfgNodeInfo.info) + if err != nil { + c.log.Warn("can't send re-bootstrap tx", zap.Error(err)) + } + } + }) + } } func bootstrapNode(c *cfg) {