Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node: init blockchain state on startup #3069

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/neofs-node/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,10 @@

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

cnrWrap, err := cntClient.NewFromMorph(cli, b.containerSH, 0)
fatalOnErr(err)
Expand All @@ -738,6 +741,10 @@
nmWrap, err := nmClient.NewFromMorph(cli, b.netmapSH, 0)
fatalOnErr(err)

eDuration, err := nmWrap.EpochDuration()
fatalOnErr(err)
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 {
msPerBlock, err := cli.MsPerBlock()
Expand Down
18 changes: 17 additions & 1 deletion cmd/neofs-node/netmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
"go.uber.org/zap"
)

// defaultEpochDuration is a default epoch duration to replace zero from FS chain.
const defaultEpochDuration = 240
roman-khimov marked this conversation as resolved.
Show resolved Hide resolved

// 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 @@
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,16 @@
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)

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

View check run for this annotation

Codecov / codecov/patch

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

Added lines #L77 - L78 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 @@
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
Loading