Skip to content

Commit

Permalink
node/nemtap: prevent zero epoch duration
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 a9183c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -743,6 +743,11 @@ func initBasics(c *cfg, key *keys.PrivateKey, stateStorage *state.PersistentStor

eDuration, err := nmWrap.EpochDuration()
fatalOnErr(err)
if eDuration == 0 {
c.log.Warn("zero epoch duration received, fallback to default value",
zap.Uint64("default applied value", defaultEpochDuration))
eDuration = defaultEpochDuration
}
nState.epochDuration.Store(eDuration)

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L744 - L752 were not covered by tests
ttl := c.applicationConfiguration.fsChain.cacheTTL
Expand Down
5 changes: 5 additions & 0 deletions cmd/neofs-node/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ import (
"go.uber.org/zap"
)

// defaultEpochDuration sets default epoch duration. Should not be used in a
// normal situations but if no info can be fetched, smth should be used as a
// fallback value.
const defaultEpochDuration = 240

// primary solution of local network state dump.
type networkState struct {
epoch atomic.Uint64
Expand Down
6 changes: 6 additions & 0 deletions cmd/neofs-node/reputation.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ func initReputationService(c *cfg) {
return
}

if duration == 0 {
c.log.Warn("zero epoch duration received, fallback to default value",
zap.Uint64("epoch", epoch), zap.Uint64("default applied value", defaultEpochDuration))
duration = defaultEpochDuration
}

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

View check run for this annotation

Codecov / codecov/patch

cmd/neofs-node/reputation.go#L233-L237

Added lines #L233 - L237 were not covered by tests

c.networkState.epochDuration.Store(duration)

iterations, err := c.cfgNetmap.wrapper.EigenTrustIterations()
Expand Down

0 comments on commit a9183c7

Please sign in to comment.