inhibit LC sync while DAG is synced (#6505)

Normally, running LC and DAG sync at same time is fine, but on tiny
devnet where some peer may not support the LC data, we can end up in
situation where peer gets disconnected when DAG is in sync, because
DAG sync never uses any req/resp on local devnet (perfect nw conditions)
so the LC sync over minutes removes the peer as sync is stuck.

We don't need to actively sync LC from network if DAG is already synced,
preventing this specific low peer devnet issue (there are others still).
LC is still locally updated when DAG finalized checkpoint advances.
This commit is contained in:
Etan Kissling 2024-08-22 08:13:47 +02:00 committed by GitHub
parent a597fe95fa
commit bd09e4d864
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 25 additions and 10 deletions

View File

@ -52,9 +52,15 @@ proc initLightClient*(
optimisticProcessor = initOptimisticProcessor( optimisticProcessor = initOptimisticProcessor(
getBeaconTime, optimisticHandler) getBeaconTime, optimisticHandler)
shouldInhibitSync = func(): bool =
if node.syncManager != nil:
not node.syncManager.inProgress # No LC sync needed if DAG is in sync
else:
false
lightClient = createLightClient( lightClient = createLightClient(
node.network, rng, config, cfg, forkDigests, getBeaconTime, node.network, rng, config, cfg, forkDigests, getBeaconTime,
genesis_validators_root, LightClientFinalizationMode.Strict) genesis_validators_root, LightClientFinalizationMode.Strict,
shouldInhibitSync = shouldInhibitSync)
if config.syncLightClient: if config.syncLightClient:
proc onOptimisticHeader( proc onOptimisticHeader(

View File

@ -86,7 +86,8 @@ proc createLightClient(
getBeaconTime: GetBeaconTimeFn, getBeaconTime: GetBeaconTimeFn,
genesis_validators_root: Eth2Digest, genesis_validators_root: Eth2Digest,
finalizationMode: LightClientFinalizationMode, finalizationMode: LightClientFinalizationMode,
strictVerification = false strictVerification = false,
shouldInhibitSync: light_client_manager.GetBoolCallback = nil
): LightClient = ): LightClient =
let lightClient = LightClient( let lightClient = LightClient(
network: network, network: network,
@ -177,7 +178,8 @@ proc createLightClient(
lightClient.network, rng, getTrustedBlockRoot, lightClient.network, rng, getTrustedBlockRoot,
bootstrapVerifier, updateVerifier, finalityVerifier, optimisticVerifier, bootstrapVerifier, updateVerifier, finalityVerifier, optimisticVerifier,
isLightClientStoreInitialized, isNextSyncCommitteeKnown, isLightClientStoreInitialized, isNextSyncCommitteeKnown,
getFinalizedPeriod, getOptimisticPeriod, getBeaconTime) getFinalizedPeriod, getOptimisticPeriod, getBeaconTime,
shouldInhibitSync = shouldInhibitSync)
lightClient.gossipState = {} lightClient.gossipState = {}
@ -191,13 +193,15 @@ proc createLightClient*(
forkDigests: ref ForkDigests, forkDigests: ref ForkDigests,
getBeaconTime: GetBeaconTimeFn, getBeaconTime: GetBeaconTimeFn,
genesis_validators_root: Eth2Digest, genesis_validators_root: Eth2Digest,
finalizationMode: LightClientFinalizationMode finalizationMode: LightClientFinalizationMode,
shouldInhibitSync: light_client_manager.GetBoolCallback = nil
): LightClient = ): LightClient =
createLightClient( createLightClient(
network, rng, network, rng,
config.dumpEnabled, config.dumpDirInvalid, config.dumpDirIncoming, config.dumpEnabled, config.dumpDirInvalid, config.dumpDirIncoming,
cfg, forkDigests, getBeaconTime, genesis_validators_root, finalizationMode, cfg, forkDigests, getBeaconTime, genesis_validators_root, finalizationMode,
strictVerification = config.strictVerification) strictVerification = config.strictVerification,
shouldInhibitSync = shouldInhibitSync)
proc createLightClient*( proc createLightClient*(
network: Eth2Node, network: Eth2Node,
@ -207,12 +211,14 @@ proc createLightClient*(
forkDigests: ref ForkDigests, forkDigests: ref ForkDigests,
getBeaconTime: GetBeaconTimeFn, getBeaconTime: GetBeaconTimeFn,
genesis_validators_root: Eth2Digest, genesis_validators_root: Eth2Digest,
finalizationMode: LightClientFinalizationMode finalizationMode: LightClientFinalizationMode,
shouldInhibitSync: light_client_manager.GetBoolCallback = nil
): LightClient = ): LightClient =
createLightClient( createLightClient(
network, rng, network, rng,
dumpEnabled = false, dumpDirInvalid = ".", dumpDirIncoming = ".", dumpEnabled = false, dumpDirInvalid = ".", dumpDirIncoming = ".",
cfg, forkDigests, getBeaconTime, genesis_validators_root, finalizationMode) cfg, forkDigests, getBeaconTime, genesis_validators_root, finalizationMode,
shouldInhibitSync = shouldInhibitSync)
proc start*(lightClient: LightClient) = proc start*(lightClient: LightClient) =
notice "Starting light client", notice "Starting light client",

View File

@ -65,6 +65,7 @@ type
getFinalizedPeriod: GetSyncCommitteePeriodCallback getFinalizedPeriod: GetSyncCommitteePeriodCallback
getOptimisticPeriod: GetSyncCommitteePeriodCallback getOptimisticPeriod: GetSyncCommitteePeriodCallback
getBeaconTime: GetBeaconTimeFn getBeaconTime: GetBeaconTimeFn
shouldInhibitSync: GetBoolCallback
loopFuture: Future[void].Raising([CancelledError]) loopFuture: Future[void].Raising([CancelledError])
func init*( func init*(
@ -80,7 +81,8 @@ func init*(
isNextSyncCommitteeKnown: GetBoolCallback, isNextSyncCommitteeKnown: GetBoolCallback,
getFinalizedPeriod: GetSyncCommitteePeriodCallback, getFinalizedPeriod: GetSyncCommitteePeriodCallback,
getOptimisticPeriod: GetSyncCommitteePeriodCallback, getOptimisticPeriod: GetSyncCommitteePeriodCallback,
getBeaconTime: GetBeaconTimeFn getBeaconTime: GetBeaconTimeFn,
shouldInhibitSync: GetBoolCallback = nil
): LightClientManager = ): LightClientManager =
## Initialize light client manager. ## Initialize light client manager.
LightClientManager( LightClientManager(
@ -95,8 +97,8 @@ func init*(
isNextSyncCommitteeKnown: isNextSyncCommitteeKnown, isNextSyncCommitteeKnown: isNextSyncCommitteeKnown,
getFinalizedPeriod: getFinalizedPeriod, getFinalizedPeriod: getFinalizedPeriod,
getOptimisticPeriod: getOptimisticPeriod, getOptimisticPeriod: getOptimisticPeriod,
getBeaconTime: getBeaconTime getBeaconTime: getBeaconTime,
) shouldInhibitSync: shouldInhibitSync)
proc isGossipSupported*( proc isGossipSupported*(
self: LightClientManager, self: LightClientManager,
@ -335,6 +337,7 @@ proc loop(self: LightClientManager) {.async: (raises: [CancelledError]).} =
# Periodically wake and check for changes # Periodically wake and check for changes
let wallTime = self.getBeaconTime() let wallTime = self.getBeaconTime()
if wallTime < nextSyncTaskTime or if wallTime < nextSyncTaskTime or
(self.shouldInhibitSync != nil and self.shouldInhibitSync()) or
self.network.peerPool.lenAvailable < 1: self.network.peerPool.lenAvailable < 1:
await sleepAsync(chronos.seconds(2)) await sleepAsync(chronos.seconds(2))
continue continue