diff --git a/packages/fork-choice/src/forkChoice/forkChoice.ts b/packages/fork-choice/src/forkChoice/forkChoice.ts index 4cdbe579eaa4..6a79f8e12957 100644 --- a/packages/fork-choice/src/forkChoice/forkChoice.ts +++ b/packages/fork-choice/src/forkChoice/forkChoice.ts @@ -505,6 +505,7 @@ export class ForkChoice implements IForkChoice { * Call `onTick` for all slots between `fcStore.getCurrentSlot()` and the provided `currentSlot`. */ updateTime(currentSlot: Slot): void { + if (this.fcStore.currentSlot >= currentSlot) return; while (this.fcStore.currentSlot < currentSlot) { const previousSlot = this.fcStore.currentSlot; // Note: we are relying upon `onTick` to update `fcStore.time` to ensure we don't get stuck in a loop. @@ -951,7 +952,8 @@ export class ForkChoice implements IForkChoice { private processAttestationQueue(): void { const currentSlot = this.fcStore.currentSlot; for (const attestation of this.queuedAttestations.values()) { - if (attestation.slot <= currentSlot) { + // Delay consideration in the fork choice until their slot is in the past. + if (attestation.slot < currentSlot) { this.queuedAttestations.delete(attestation); const {blockRoot, targetEpoch} = attestation; const blockRootHex = blockRoot; diff --git a/packages/lodestar/src/api/impl/validator/index.ts b/packages/lodestar/src/api/impl/validator/index.ts index 92ab209c135f..b2a8aeafe258 100644 --- a/packages/lodestar/src/api/impl/validator/index.ts +++ b/packages/lodestar/src/api/impl/validator/index.ts @@ -176,6 +176,12 @@ export function getValidatorApi({chain, config, logger, metrics, network, sync}: notWhileSyncing(); await waitForSlot(slot); // Must never request for a future slot > currentSlot + // Process the queued attestations in the forkchoice for correct head estimation + // forkChoice.updateTime() might have already been called by the onSlot clock + // handler, in which case this should just return. + chain.forkChoice.updateTime(slot); + chain.forkChoice.updateHead(); + timer = metrics?.blockProductionTime.startTimer(); const block = await assembleBlock( {chain, metrics},