Skip to content

Commit

Permalink
node/netmap: prevent zero epoch duration state
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
carpawell committed Dec 25, 2024
1 parent 2b27bff commit 7028440
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 730 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L727-L730

Added lines #L727 - L730 were not covered by tests
Expand All @@ -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)

Check warning on line 747 in cmd/neofs-node/config.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/config.go#L744-L747

Added lines #L744 - L747 were not covered by tests
ttl := c.applicationConfiguration.fsChain.cacheTTL
if ttl == 0 {
Expand Down
20 changes: 19 additions & 1 deletion cmd/neofs-node/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -35,11 +40,12 @@ type networkState struct {
metrics *metrics.NodeMetrics
}

func newNetworkState() *networkState {
func newNetworkState(l *zap.Logger) *networkState {

Check warning on line 43 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L43

Added line #L43 was not covered by tests
var nmStatus atomic.Value
nmStatus.Store(control.NetmapStatus_STATUS_UNDEFINED)

return &networkState{
l: l,

Check warning on line 48 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L48

Added line #L48 was not covered by tests
controlNetStatus: nmStatus,
}
}
Expand All @@ -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
}

Check warning on line 75 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L71-L75

Added lines #L71 - L75 were not covered by tests

s.l.Warn("zero epoch duration received, fallback to default value", zap.Uint64("applied default value", defaultEpochDuration))
s.epochDuration.Store(defaultEpochDuration)

return

Check warning on line 80 in cmd/neofs-node/netmap.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/netmap.go#L77-L80

Added lines #L77 - L80 were not covered by tests
}

func (s *networkState) setNodeInfo(ni *netmapSDK.NodeInfo) {
ctrlNetSt := control.NetmapStatus_STATUS_UNDEFINED

Expand Down
3 changes: 1 addition & 2 deletions cmd/neofs-node/reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 232 in cmd/neofs-node/reputation.go

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/reputation.go#L232

Added line #L232 was not covered by tests

iterations, err := c.cfgNetmap.wrapper.EigenTrustIterations()
if err != nil {
Expand Down

0 comments on commit 7028440

Please sign in to comment.