Suppress beacon sync unless potential actions (#2765)
* 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.
This commit is contained in:
parent
693ad315b3
commit
070f117d3c
|
@ -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()
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
@ -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 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*(ctx: BeaconSyncRef) =
|
||||
ctx.stopSync()
|
||||
proc stop*(desc: BeaconSyncRef) =
|
||||
desc.stopSync()
|
||||
|
||||
# ------------------------------------------------------------------------------
|
||||
# End
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,7 +18,7 @@ import
|
|||
../helpers
|
||||
|
||||
logScope:
|
||||
topics = "ticker"
|
||||
topics = "beacon ticker"
|
||||
|
||||
type
|
||||
TickerStatsUpdater* = proc: TickerStats {.gcsafe, raises: [].}
|
||||
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue