Skip to content

op-reth,op-reth-test-engine: Fail pending and test engine state when opened, not on first read - #24069

Open
aakoshh wants to merge 11 commits into
developfrom
af/23404-review-followups
Open

aakoshh wants to merge 11 commits into
developfrom
af/23404-review-followups

Conversation

@aakoshh

@aakoshh aakoshh commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Addresses the optional review comments left open on #24024 when it was enqueued, and fixes a test engine bug that the review of these changes found.

What

  • A pending state query on a flashblocks node now falls back to latest state when the flashblock's anchor is no longer canonical, for example after a reorg. Before, a tip built on the anchor returned an overlay that only failed on its first read, so eth_call pending and similar queries returned an error. A speculative tip already fell back. Both cases now log the fallback at debug.
  • In op-reth-test-engine, a recorded block whose ancestors the provider can't resolve now fails an import as an error. Before, it came back as an INVALID payload, which points whoever debugs the test at the payload instead of the engine.
  • The pending state tests now cover a destroyed account's storage: the earlier fixture's account had no storage, so a read falling back to the anchor's slots would have passed. They also check which overlay serves each case.
  • The rest is comment and doc fixes: a duplicate and a stale line in local_pending_state, and get_proof's pending safety note, which relied on reth never setting a canonical pending block. The engine tree sets one whenever a payload extends the head.

Why

reth's state_with_block_appended resolves the chain it appends to lazily, on the first read, so it returns Ok for an anchor or ancestor it can't resolve. Since #24024 both callers depend on it failing when opened:

  • Upstream RPC callers treat pending state as best effort and fall back to latest only when opening it fails, so a lazy failure failed the RPC instead.
  • The test engine's first state read during an import is a system call, whose errors alloy-evm reports as validation failures.

How

Both now fail when the state is opened. The pending state code checks the anchor with the guard history_by_block_hash runs in the speculative branch. The test engine's block_state reads the state once, which makes reth resolve and cache the chain for the later reads.

Caveats

  • get_proof still resolves the state inside its blocking task, so it relies on the proofs window rejecting pending. After a reorg to a shorter chain, until the proofs ExEx reverts, window.latest can be past the head, and a pending block could pass that check.

Alternatives

  • Overriding LoadPendingBlock::local_pending_block_or_state to return PendingStateSource::Block for a tip on the anchor, as suggested on rust!: Update reth to v2.7.0 #24024, would save one blocking-task hop per pending query. We kept the single override:
    • Upstream opens a Block source with the same lazy state_with_block_appended, so its or_else fallback doesn't fire for an anchor that is gone. Checking the anchor first would need a synchronous read on the async runtime, or a second blocking task again.
    • state_at_block_id calls local_pending_state directly, so both methods would need overriding, and the speculative branch stays either way.

Potential follow-ups

🤖 Generated with Claude Code

@aakoshh
aakoshh requested a review from op-will November 11, 2026 18:14
@aakoshh aakoshh closed this Nov 12, 2026
@aakoshh aakoshh reopened this Nov 12, 2026
@aakoshh
aakoshh marked this pull request as ready for review November 12, 2026 09:05
@aakoshh
aakoshh requested a review from a team as a code owner November 12, 2026 09:05
Callers of local_pending_state treat an error as "no pending block" and
serve latest, so a pending state source has to fail before it returns.
The speculative branch did, in history_by_block_hash. The canonical
branch didn't: reth's overlay resolves the anchor on its first read, so
a reorged-out or evicted anchor surfaced later as an RPC error instead.
Check the anchor before opening the overlay, so both branches fall back
the same way.

Log at debug when the pending state can't be opened, since the
fallback otherwise leaves no trace that a pending block existed.
Both branches of pending_flashblock_state must fail before any state is
read when the provider doesn't know the anchor, so that the caller falls
back to latest instead of failing the RPC on its first read. Without the
anchor check, the canonical case returns an overlay that only fails
later, when it is read.
The destroyed account in the pending state test came from the mainnet
genesis, whose first account has no storage, so a regression that read
a destroyed account's slots from the anchor would have passed. Use a
genesis account with a storage slot and check that it reads zero.

Also split out the speculative check and assert it per case, so the test
fails if a case is served by the other overlay.
… resolve

The provider resolves a recorded block's ancestors lazily, so a recorded
ancestor missing from the shared overlay manager only fails the first
state read. During import that read is a system call, whose errors
alloy-evm reports as validation failures, so the payload comes back
INVALID instead of as an error.
…g on it

block_state now reads the state once after opening it, so an ancestor
the provider can't resolve fails there as a provider error. Before, the
failure surfaced in the first system call of the import, which alloy-evm
reports as a validation error, so the payload came back INVALID.
@aakoshh
aakoshh force-pushed the af/23404-review-followups branch from a4cbee9 to 6e9132a Compare November 12, 2026 16:41

This branch has not been deployed

No deployments
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