Skip to content

Commit

Permalink
Suppress beacon sync unless potential actions (#2765)
Browse files Browse the repository at this point in the history
* Update comments & logs

* Do not start beacon sync unless there is possibly something to do

why:
  It would continue polling without having any effect other than
  logging. Now it will not start unless there is RPC available
  or there was a previously interrupted sync to be resumed.
  • Loading branch information
mjfh authored Oct 21, 2024
1 parent 693ad31 commit 070f117
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions nimbus/nimbus_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ proc stop*(nimbus: NimbusNode, conf: NimbusConf) {.async, gcsafe.} =
await nimbus.networkLoop.cancelAndWait()
if nimbus.peerManager.isNil.not:
await nimbus.peerManager.stop()
#if nimbus.snapSyncRef.isNil.not:
# nimbus.snapSyncRef.stop()
if nimbus.beaconSyncRef.isNil.not:
nimbus.beaconSyncRef.stop()
if nimbus.metricsServer.isNil.not:
await nimbus.metricsServer.stop()

Expand Down
12 changes: 6 additions & 6 deletions nimbus/nimbus_execution_client.nim
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,13 @@ proc setupP2P(nimbus: NimbusNode, conf: NimbusConf,
nimbus.ethNode.peerPool,
nimbus.chainRef,
nimbus.txPool)
#of ProtocolFlag.Snap:
# nimbus.ethNode.addSnapHandlerCapability(
# nimbus.ethNode.peerPool,
# nimbus.chainRef)
# Cannot do without minimal `eth` capability
if ProtocolFlag.Eth notin protocols:
nimbus.ethNode.addEthHandlerCapability(
nimbus.ethNode.peerPool,
nimbus.chainRef)

# Always start syncer -- will throttle itself unless needed
# Always initialise beacon syncer
nimbus.beaconSyncRef = BeaconSyncRef.init(
nimbus.ethNode, nimbus.chainRef, conf.maxPeers, conf.beaconChunkSize)

Expand Down Expand Up @@ -225,7 +221,11 @@ proc run(nimbus: NimbusNode, conf: NimbusConf) =
setupRpc(nimbus, conf, com, protocols)

if conf.maxPeers > 0:
nimbus.beaconSyncRef.start
# Not starting syncer if there is definitely no way to run it. This
# avoids polling (i.e. waiting for instructions) and some logging.
let resumeOnly = not conf.engineApiServerEnabled()
if not nimbus.beaconSyncRef.start(resumeOnly):
nimbus.beaconSyncRef = BeaconSyncRef(nil)

if nimbus.state == NimbusState.Starting:
# it might have been set to "Stopping" with Ctrl+C
Expand Down
20 changes: 12 additions & 8 deletions nimbus/sync/beacon.nim
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import
pkg/[chronicles, chronos, eth/p2p, results],
pkg/stew/[interval_set, sorted_set],
../core/chain,
./beacon/[worker, worker_desc],
./beacon/[worker, worker_desc, worker/db],
"."/[sync_desc, sync_sched, protocol]

logScope:
Expand Down Expand Up @@ -62,16 +62,20 @@ proc init*(
var desc = T()
desc.initSync(ethNode, maxPeers)
desc.ctx.pool.nBodiesBatch = chunkSize
# Initalise for `persistBlocks()`
desc.ctx.pool.chain = chain
desc

proc start*(ctx: BeaconSyncRef) =
## Beacon Sync always begin with stop mode
doAssert ctx.startSync() # Initialize subsystems

proc stop*(ctx: BeaconSyncRef) =
ctx.stopSync()
proc start*(desc: BeaconSyncRef; resumeOnly = false): bool =
## Start beacon sync. If `resumeOnly` is set `true` the syncer will only
## start up if it can resume work, e.g. after being previously interrupted.
if resumeOnly:
desc.ctx.dbLoadSyncStateLayout()
if not desc.ctx.layout.headLocked:
return false
desc.startSync()

proc stop*(desc: BeaconSyncRef) =
desc.stopSync()

# ------------------------------------------------------------------------------
# End
Expand Down
2 changes: 1 addition & 1 deletion nimbus/sync/beacon/worker/start_stop.nim
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ proc setupDatabase*(ctx: BeaconCtxRef) =
# Load initial state from database if there is any
ctx.dbLoadSyncStateLayout()

# Set blocks batch import value for `persistBlocks()`
# Set blocks batch import value for block import
if ctx.pool.nBodiesBatch < nFetchBodiesRequest:
if ctx.pool.nBodiesBatch == 0:
ctx.pool.nBodiesBatch = nFetchBodiesBatchDefault
Expand Down
6 changes: 3 additions & 3 deletions nimbus/sync/beacon/worker/start_stop/ticker.nim
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import
../helpers

logScope:
topics = "ticker"
topics = "beacon ticker"

type
TickerStatsUpdater* = proc: TickerStats {.gcsafe, raises: [].}
Expand Down Expand Up @@ -108,10 +108,10 @@ proc tickerLogger(t: TickerRef) {.gcsafe.} =
t.visited = now

if data.stored == data.base:
info "Sync state", up, peers,
debug "Sync state", up, peers,
B, L, C, D, F, H, T, hS, hU, bS, bU, rrg, mem
else:
info "Sync state", up, peers,
debug "Sync state", up, peers,
S=data.stored.bnStr,
B, L, C, D, F, H, T, hS, hU, bS, bU, rrg, mem

Expand Down
2 changes: 1 addition & 1 deletion nimbus/sync/beacon/worker_desc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ type
blkSync*: BlocksImportSync ## For importing/executing blocks
nextUpdate*: Moment ## For updating metrics

# Blocks import/execution settings for running `persistBlocks()` with
# Blocks import/execution settings for importing with
# `nBodiesBatch` blocks in each round (minimum value is
# `nFetchBodiesRequest`.)
chain*: ForkedChainRef ## Database
Expand Down

0 comments on commit 070f117

Please sign in to comment.