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()
|
await nimbus.networkLoop.cancelAndWait()
|
||||||
if nimbus.peerManager.isNil.not:
|
if nimbus.peerManager.isNil.not:
|
||||||
await nimbus.peerManager.stop()
|
await nimbus.peerManager.stop()
|
||||||
#if nimbus.snapSyncRef.isNil.not:
|
if nimbus.beaconSyncRef.isNil.not:
|
||||||
# nimbus.snapSyncRef.stop()
|
nimbus.beaconSyncRef.stop()
|
||||||
if nimbus.metricsServer.isNil.not:
|
if nimbus.metricsServer.isNil.not:
|
||||||
await nimbus.metricsServer.stop()
|
await nimbus.metricsServer.stop()
|
||||||
|
|
||||||
|
|
|
@ -110,17 +110,13 @@ proc setupP2P(nimbus: NimbusNode, conf: NimbusConf,
|
||||||
nimbus.ethNode.peerPool,
|
nimbus.ethNode.peerPool,
|
||||||
nimbus.chainRef,
|
nimbus.chainRef,
|
||||||
nimbus.txPool)
|
nimbus.txPool)
|
||||||
#of ProtocolFlag.Snap:
|
|
||||||
# nimbus.ethNode.addSnapHandlerCapability(
|
|
||||||
# nimbus.ethNode.peerPool,
|
|
||||||
# nimbus.chainRef)
|
|
||||||
# Cannot do without minimal `eth` capability
|
# Cannot do without minimal `eth` capability
|
||||||
if ProtocolFlag.Eth notin protocols:
|
if ProtocolFlag.Eth notin protocols:
|
||||||
nimbus.ethNode.addEthHandlerCapability(
|
nimbus.ethNode.addEthHandlerCapability(
|
||||||
nimbus.ethNode.peerPool,
|
nimbus.ethNode.peerPool,
|
||||||
nimbus.chainRef)
|
nimbus.chainRef)
|
||||||
|
|
||||||
# Always start syncer -- will throttle itself unless needed
|
# Always initialise beacon syncer
|
||||||
nimbus.beaconSyncRef = BeaconSyncRef.init(
|
nimbus.beaconSyncRef = BeaconSyncRef.init(
|
||||||
nimbus.ethNode, nimbus.chainRef, conf.maxPeers, conf.beaconChunkSize)
|
nimbus.ethNode, nimbus.chainRef, conf.maxPeers, conf.beaconChunkSize)
|
||||||
|
|
||||||
|
@ -225,7 +221,11 @@ proc run(nimbus: NimbusNode, conf: NimbusConf) =
|
||||||
setupRpc(nimbus, conf, com, protocols)
|
setupRpc(nimbus, conf, com, protocols)
|
||||||
|
|
||||||
if conf.maxPeers > 0:
|
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:
|
if nimbus.state == NimbusState.Starting:
|
||||||
# it might have been set to "Stopping" with Ctrl+C
|
# it might have been set to "Stopping" with Ctrl+C
|
||||||
|
|
|
@ -14,7 +14,7 @@ import
|
||||||
pkg/[chronicles, chronos, eth/p2p, results],
|
pkg/[chronicles, chronos, eth/p2p, results],
|
||||||
pkg/stew/[interval_set, sorted_set],
|
pkg/stew/[interval_set, sorted_set],
|
||||||
../core/chain,
|
../core/chain,
|
||||||
./beacon/[worker, worker_desc],
|
./beacon/[worker, worker_desc, worker/db],
|
||||||
"."/[sync_desc, sync_sched, protocol]
|
"."/[sync_desc, sync_sched, protocol]
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
|
@ -62,16 +62,20 @@ proc init*(
|
||||||
var desc = T()
|
var desc = T()
|
||||||
desc.initSync(ethNode, maxPeers)
|
desc.initSync(ethNode, maxPeers)
|
||||||
desc.ctx.pool.nBodiesBatch = chunkSize
|
desc.ctx.pool.nBodiesBatch = chunkSize
|
||||||
# Initalise for `persistBlocks()`
|
|
||||||
desc.ctx.pool.chain = chain
|
desc.ctx.pool.chain = chain
|
||||||
desc
|
desc
|
||||||
|
|
||||||
proc start*(ctx: BeaconSyncRef) =
|
proc start*(desc: BeaconSyncRef; resumeOnly = false): bool =
|
||||||
## Beacon Sync always begin with stop mode
|
## Start beacon sync. If `resumeOnly` is set `true` the syncer will only
|
||||||
doAssert ctx.startSync() # Initialize subsystems
|
## 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) =
|
proc stop*(desc: BeaconSyncRef) =
|
||||||
ctx.stopSync()
|
desc.stopSync()
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------
|
||||||
# End
|
# End
|
||||||
|
|
|
@ -98,7 +98,7 @@ proc setupDatabase*(ctx: BeaconCtxRef) =
|
||||||
# Load initial state from database if there is any
|
# Load initial state from database if there is any
|
||||||
ctx.dbLoadSyncStateLayout()
|
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 < nFetchBodiesRequest:
|
||||||
if ctx.pool.nBodiesBatch == 0:
|
if ctx.pool.nBodiesBatch == 0:
|
||||||
ctx.pool.nBodiesBatch = nFetchBodiesBatchDefault
|
ctx.pool.nBodiesBatch = nFetchBodiesBatchDefault
|
||||||
|
|
|
@ -18,7 +18,7 @@ import
|
||||||
../helpers
|
../helpers
|
||||||
|
|
||||||
logScope:
|
logScope:
|
||||||
topics = "ticker"
|
topics = "beacon ticker"
|
||||||
|
|
||||||
type
|
type
|
||||||
TickerStatsUpdater* = proc: TickerStats {.gcsafe, raises: [].}
|
TickerStatsUpdater* = proc: TickerStats {.gcsafe, raises: [].}
|
||||||
|
@ -108,10 +108,10 @@ proc tickerLogger(t: TickerRef) {.gcsafe.} =
|
||||||
t.visited = now
|
t.visited = now
|
||||||
|
|
||||||
if data.stored == data.base:
|
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
|
B, L, C, D, F, H, T, hS, hU, bS, bU, rrg, mem
|
||||||
else:
|
else:
|
||||||
info "Sync state", up, peers,
|
debug "Sync state", up, peers,
|
||||||
S=data.stored.bnStr,
|
S=data.stored.bnStr,
|
||||||
B, L, C, D, F, H, T, hS, hU, bS, bU, rrg, mem
|
B, L, C, D, F, H, T, hS, hU, bS, bU, rrg, mem
|
||||||
|
|
||||||
|
|
|
@ -130,7 +130,7 @@ type
|
||||||
blkSync*: BlocksImportSync ## For importing/executing blocks
|
blkSync*: BlocksImportSync ## For importing/executing blocks
|
||||||
nextUpdate*: Moment ## For updating metrics
|
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
|
# `nBodiesBatch` blocks in each round (minimum value is
|
||||||
# `nFetchBodiesRequest`.)
|
# `nFetchBodiesRequest`.)
|
||||||
chain*: ForkedChainRef ## Database
|
chain*: ForkedChainRef ## Database
|
||||||
|
|
Loading…
Reference in New Issue