Skip to content

fix: handle missing L1 finalized block on devnets#22663

Merged
spalladino merged 1 commit intomerge-train/spartanfrom
spl/fix/handle-missing-l1-finalized-block
Apr 21, 2026
Merged

fix: handle missing L1 finalized block on devnets#22663
spalladino merged 1 commit intomerge-train/spartanfrom
spl/fix/handle-missing-l1-finalized-block

Conversation

@spalladino
Copy link
Copy Markdown
Contributor

Motivation

On freshly-started L1 devnets (anvil, local geth/reth/nethermind) there is a startup window during which the finalized block tag is not yet available — calls like getBlock({ blockTag: 'finalized' }) fail with a JSON-RPC error instead of returning a block. The archiver currently logs noisy warnings during this window and epoch-cache would crash dereferencing the missing block's timestamp.

Approach

Added a shared getFinalizedL1Block helper in @aztec/ethereum/queries that returns undefined when the chain has no finalized block yet, distinguishing that specific failure from other RPC errors by walking the viem error chain for the "finalized|safe block not found" message (the code -32000 surfaced by geth/reth/nethermind). All three production call sites now handle undefined gracefully: the archiver skips the finalized checkpoint update, and epoch-cache treats entries as "not finalized yet" so they continue to refresh on TTL until the L1 chain catches up.

Changes

  • ethereum: New getFinalizedL1Block helper and isFinalizedBlockTagNotFoundError predicate in queries.ts.
  • archiver: updateFinalizedCheckpoint uses the helper and returns early with a trace log instead of warning; removed the old "returned no data" substring workaround.
  • epoch-cache: refreshStaleEntry and fetchAndCache use the helper and guard the samplingTs <= finalizedBlock.timestamp comparison so entries stay unfinalized when L1 has none yet.
  • tests: Unit tests for the helper/predicate, an archiver sync test using FakeL1State configured with no finalized block, and an epoch-cache test asserting entries stay unfinalized and keep refreshing.

@spalladino spalladino requested a review from alexghr April 20, 2026 14:19
Adds getFinalizedL1Block helper that returns undefined when the L1 chain
does not yet have a finalized block (common on freshly-started devnets)
and uses it in the archiver and epoch-cache call sites.
@spalladino spalladino force-pushed the spl/fix/handle-missing-l1-finalized-block branch from 03cde8b to 43fc41a Compare April 20, 2026 14:27
@spalladino spalladino merged commit dbf8b95 into merge-train/spartan Apr 21, 2026
12 checks passed
@spalladino spalladino deleted the spl/fix/handle-missing-l1-finalized-block branch April 21, 2026 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants