Skip to content

Commit

Permalink
Obtain extra LightClientFinalityUpdate after LC sync (#6752)
Browse files Browse the repository at this point in the history
To avoid having to wait several minutes for LC finality gossip, obtain
extra finality update once LC sync finishes.
  • Loading branch information
etan-status authored Dec 5, 2024
1 parent c3ef7fe commit 0ae7bcf
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions beacon_chain/sync/light_client_manager.nim
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,10 @@ template query[E](

# https://github.com/ethereum/consensus-specs/blob/v1.5.0-alpha.9/specs/altair/light-client/light-client.md#light-client-sync-process
proc loop(self: LightClientManager) {.async: (raises: [CancelledError]).} =
var nextSyncTaskTime = self.getBeaconTime()
var
nextSyncTaskTime = self.getBeaconTime()
wasGossipSupported = false
haveFinalityUpdate = false
while true:
# Periodically wake and check for changes
let wallTime = self.getBeaconTime()
Expand Down Expand Up @@ -373,16 +376,32 @@ proc loop(self: LightClientManager) {.async: (raises: [CancelledError]).} =
await self.query(UpdatesByRange,
(startPeriod: syncTask.startPeriod, count: syncTask.count))
of LcSyncKind.FinalityUpdate:
haveFinalityUpdate = true
await self.query(FinalityUpdate)
of LcSyncKind.OptimisticUpdate:
await self.query(OptimisticUpdate)

nextSyncTaskTime = wallTime + self.rng.nextLcSyncTaskDelay(
wallTime,
finalized = self.getFinalizedPeriod(),
optimistic = self.getOptimisticPeriod(),
isNextSyncCommitteeKnown = self.isNextSyncCommitteeKnown(),
didLatestSyncTaskProgress = didProgress)
if not haveFinalityUpdate:
haveFinalityUpdate = true
await self.query(FinalityUpdate)
else:
await self.query(OptimisticUpdate)

let
finalized = self.getFinalizedPeriod()
optimistic = self.getOptimisticPeriod()
isNextSyncCommitteeKnown = self.isNextSyncCommitteeKnown()
isGossipSupported =
current.isGossipSupported(finalized, isNextSyncCommitteeKnown)
nextSyncTaskTime =
if not wasGossipSupported and isGossipSupported:
# Obtain an extra finality update after finishing sync
# to avoid having to wait several minutes for finality gossip
haveFinalityUpdate = false
wallTime
else:
wallTime + self.rng.nextLcSyncTaskDelay(
wallTime, finalized, optimistic, isNextSyncCommitteeKnown,
didLatestSyncTaskProgress = didProgress)
wasGossipSupported = isGossipSupported

proc start*(self: var LightClientManager) =
## Start light client manager's loop.
Expand Down

0 comments on commit 0ae7bcf

Please sign in to comment.