[#134] Resend bootstrap txs periodically

Signed-off-by: Alex Vanin <alexey@nspcc.ru>
This commit is contained in:
Alex Vanin 2020-10-30 15:57:49 +03:00 committed by Alex Vanin
parent c7975dbe87
commit 2bd827a478
2 changed files with 27 additions and 3 deletions

View file

@ -86,6 +86,9 @@ const (
cfgPolicerHeadTimeout = "policer.head_timeout" cfgPolicerHeadTimeout = "policer.head_timeout"
cfgReplicatorPutTimeout = "replicator.put_timeout" cfgReplicatorPutTimeout = "replicator.put_timeout"
cfgReBootstrapEnabled = "bootstrap.periodic.enabled"
cfgReBootstrapInterval = "bootstrap.periodic.interval"
) )
const ( const (
@ -169,6 +172,9 @@ type cfgNetmap struct {
subscribers map[event.Type][]event.Handler subscribers map[event.Type][]event.Handler
state *networkState state *networkState
reBootstrapEnabled bool
reBootstrapInterval uint64 // in epochs
} }
type BootstrapType uint32 type BootstrapType uint32
@ -245,9 +251,11 @@ func initCfg(path string) *cfg {
fee: util.Fixed8(viperCfg.GetInt(cfgContainerFee)), fee: util.Fixed8(viperCfg.GetInt(cfgContainerFee)),
}, },
cfgNetmap: cfgNetmap{ cfgNetmap: cfgNetmap{
scriptHash: u160Netmap, scriptHash: u160Netmap,
fee: util.Fixed8(viperCfg.GetInt(cfgNetmapFee)), fee: util.Fixed8(viperCfg.GetInt(cfgNetmapFee)),
state: state, state: state,
reBootstrapInterval: viperCfg.GetUint64(cfgReBootstrapInterval),
reBootstrapEnabled: viperCfg.GetBool(cfgReBootstrapEnabled),
}, },
cfgNodeInfo: cfgNodeInfo{ cfgNodeInfo: cfgNodeInfo{
bootType: StorageNode, bootType: StorageNode,
@ -332,6 +340,9 @@ func defaultConfiguration(v *viper.Viper) {
v.SetDefault(cfgPolicerHeadTimeout, 5*time.Second) v.SetDefault(cfgPolicerHeadTimeout, 5*time.Second)
v.SetDefault(cfgReplicatorPutTimeout, 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 { func (c *cfg) LocalAddress() *network.Address {

View file

@ -58,6 +58,19 @@ func initNetmapService(c *cfg) {
addNewEpochNotificationHandler(c, func(ev event.Event) { addNewEpochNotificationHandler(c, func(ev event.Event) {
c.cfgNetmap.state.setCurrentEpoch(ev.(netmapEvent.NewEpoch).EpochNumber()) 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) { func bootstrapNode(c *cfg) {