From 7028440389544ca91713586fadfb0cb75cbed1e6 Mon Sep 17 00:00:00 2001 From: Pavel Karpy Date: Wed, 25 Dec 2024 15:30:52 +0300 Subject: [PATCH] node/netmap: prevent zero epoch duration state Fallback to 240 blocks default epoch duration if unexpected zero value received. Zero value is not acceptable, and it is hard to predict how the system reacts to it (panic was observed at least once). Refs #3066. Signed-off-by: Pavel Karpy --- cmd/neofs-node/config.go | 4 ++-- cmd/neofs-node/netmap.go | 20 +++++++++++++++++++- cmd/neofs-node/reputation.go | 3 +-- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/neofs-node/config.go b/cmd/neofs-node/config.go index b097fb3bfb..4951d05f0c 100644 --- a/cmd/neofs-node/config.go +++ b/cmd/neofs-node/config.go @@ -724,7 +724,7 @@ func initBasics(c *cfg, key *keys.PrivateKey, stateStorage *state.PersistentStor lookupScriptHashesInNNS(cli, c.applicationConfiguration, &b) - nState := newNetworkState() + nState := newNetworkState(c.log) currBlock, err := cli.BlockCount() fatalOnErr(err) nState.block.Store(currBlock) @@ -743,7 +743,7 @@ func initBasics(c *cfg, key *keys.PrivateKey, stateStorage *state.PersistentStor eDuration, err := nmWrap.EpochDuration() fatalOnErr(err) - nState.epochDuration.Store(eDuration) + nState.updateEpochDuration(eDuration) ttl := c.applicationConfiguration.fsChain.cacheTTL if ttl == 0 { diff --git a/cmd/neofs-node/netmap.go b/cmd/neofs-node/netmap.go index 3a197ef08b..b54f4e7f5b 100644 --- a/cmd/neofs-node/netmap.go +++ b/cmd/neofs-node/netmap.go @@ -22,8 +22,13 @@ import ( "go.uber.org/zap" ) +// defaultEpochDuration is a default epoch duration to replace zero from FS chain. +const defaultEpochDuration = 240 + // primary solution of local network state dump. type networkState struct { + l *zap.Logger + epoch atomic.Uint64 block atomic.Uint32 epochDuration atomic.Uint64 @@ -35,11 +40,12 @@ type networkState struct { metrics *metrics.NodeMetrics } -func newNetworkState() *networkState { +func newNetworkState(l *zap.Logger) *networkState { var nmStatus atomic.Value nmStatus.Store(control.NetmapStatus_STATUS_UNDEFINED) return &networkState{ + l: l, controlNetStatus: nmStatus, } } @@ -62,6 +68,18 @@ func (s *networkState) setCurrentEpoch(v uint64) { s.metrics.SetEpoch(v) } +func (s *networkState) updateEpochDuration(v uint64) { + if v != 0 { + s.epochDuration.Store(v) + return + } + + s.l.Warn("zero epoch duration received, fallback to default value", zap.Uint64("applied default value", defaultEpochDuration)) + s.epochDuration.Store(defaultEpochDuration) + + return +} + func (s *networkState) setNodeInfo(ni *netmapSDK.NodeInfo) { ctrlNetSt := control.NetmapStatus_STATUS_UNDEFINED diff --git a/cmd/neofs-node/reputation.go b/cmd/neofs-node/reputation.go index d2ea3ad09f..ea4fe0936e 100644 --- a/cmd/neofs-node/reputation.go +++ b/cmd/neofs-node/reputation.go @@ -229,8 +229,7 @@ func initReputationService(c *cfg) { log.Debug("could not fetch epoch duration", zap.Error(err)) return } - - c.networkState.epochDuration.Store(duration) + c.networkState.updateEpochDuration(duration) iterations, err := c.cfgNetmap.wrapper.EigenTrustIterations() if err != nil {