Skip to content

fix(proofs-history): answer near-head blocks and run proofs off async workers - #187

Closed
ivanwang-coder wants to merge 1 commit into
dev/mantle-v1.7.0from
fix/proofs-history-near-head
Closed

ivanwang-coder wants to merge 1 commit into
dev/mantle-v1.7.0from
fix/proofs-history-near-head

Conversation

@ivanwang-coder

@ivanwang-coder ivanwang-coder commented Oct 24, 2026 •

Copy link
Copy Markdown

Summary

Fixes three proofs-history problems on dev/mantle-v1.7.0, all found while reviewing #181:

  1. Blocks near the head are not queryable. The proofs engine writes to the sidecar in batches: every 5 blocks, or after 10 s idle. The RPC only reads written blocks, so the newest blocks fail with no state found.
  2. The test harness seeded the sidecar with a zero anchor hash. The ExEx stopped at the first mined block, so no proofs-history test could mine a block. As a result, nothing checked that the sidecar's eth_getProof is the one serving requests.
  3. Proof work ran on async runtime workers. The sidecar eth_getProof and debug_executionWitness walked the trie, and re-executed the block, directly on tokio worker threads.

Production proof nodes run mantle-v1.6.2, which has no proofs engine, so none of this triggers today. It triggers once proof nodes move to v1.6.3 / v1.7.x and serve clients that ask for recent state. For example, if public eth_getProof is routed to proof reths, wallets and bridges query latest and blocks that have just arrived.

Changes

Near-head fallback (op-reth/crates/rpc/src/state.rs)

  • OpStateProviderFactory::state_provider now answers a block from reth's own state when all of these hold:
    • it is above the proofs window;
    • it is not past the head;
    • it is within NEAR_HEAD_FALLBACK_BLOCKS (64) of the head.
  • The function already built that state provider for the overlay, so the change only decides whether to return it directly.
  • 64 matches the changeset cache reth keeps behind its persisted tip, so reth's proof path stays cheap at that distance.
  • The window's lower bound stays strict. Old blocks still fail rather than falling back to the slow revert-based path.
  • One change covers eth_getProof, debug_executePayload and debug_executionWitness.
  • The decision is a small pure function with a table test.

Off-worker proofs (eth/proofs.rs, debug.rs)

  • The sidecar eth_getProof now runs on spawn_blocking_io_fut, the same pattern as stock reth and the Mantle rpc-ext override. The tracing permit is still held for the whole call.
  • debug_executionWitness now runs its re-execution and witness on a blocking task, as debug_executePayload already did.
  • Error codes and messages are unchanged.

Test harness and tests (integration-tests)

  • seed_proofs_sidecar anchors the sidecar at the real genesis number and hash.
  • proofs_history_wiring_serves_sidecar_rpc:
    • Its last step used to be guarded by if earliest > 0, which never held, so the step never ran.
    • It now mines block 1 and asks for block 0. Only the sidecar can answer that: under the default proof window (0), the Mantle and stock eth_getProof refuse it with -32602.
  • New proofs_history_answers_blocks_not_yet_in_the_sidecar:
    • It mines block 1 and checks that the sidecar still reports latest = 0.
    • eth_getProof at latest and 0x1 succeed, and so does debug_executionWitness for 0x1.
    • A block past the head still fails.

Verification

Each new test fails when the fix it covers is reverted:

Revert Result
Disable the fallback The near-head test fails with no state found for block number 1, the production symptom
Seed with the zero hash again The ExEx crashes with Parent hash mismatch at block 1; both block-mining tests fail
Install the Mantle extensions after the sidecar overrides The wiring test fails with -32602 distance to target block exceeds maximum proof window

Local devnet: the PR's release binary was run in the proofs-history slot, with the same flags as production proof nodes (window 100000, storage v2). 300 random latest queries were sent, plus 30 queries of each new block as soon as it appeared:

Binary Random latest failures Fresh-block failures
v1.6.3 (current devnet) 256/300 30/30
This PR 0/300 0/30
  • With this PR, a block below the window still returns no state found.
  • Proofs from the proofs-history node match a node without proofs-history byte for byte, whether the block is above the window (the new path) or inside it.
  • rpc-compat core suite, proofs-history node vs a node without proofs-history: no eth_getProof differences remain. Before this PR there were 15–18. The only real differences left are the 4 eth_getBlockRange cases, because the comparison node runs v1.6.3 and fix(rpc): enable Mantle mainnet historical forwarding #144 retired the method.

Checks:

  • cargo test -p reth-optimism-rpc --lib: 63 passed.
  • cargo nextest run -p mantle-reth-integration-tests --tests proofs_history historical_rpc get_proof: 6 passed.
  • cargo clippy --workspace --lib --examples --tests --benches --all-features -- -D warnings: clean. cargo +nightly fmt --all: clean.

Relation to upstream op-reth

Item Upstream (ethereum-optimism/optimism develop) This PR
Near-head blocks fail Same engine (5 blocks / 10 s) and strict window. Upstream chose this on purpose: ethereum-optimism/optimism#19855 removed an out-of-window fallback to the historical provider because deep fallbacks caused OOMs, ethereum-optimism/optimism#20707 made the window strict, and ethereum-optimism/optimism#23390 lists a buffered-but-unflushed height as an expected error A Mantle divergence, marked [MANTLE]. It only covers blocks above the window and within 64 of the head, so it never reaches the deep historical path behind the OOMs that ethereum-optimism/optimism#19855 removed. Re-apply on the next bump, which rewrites state.rs
Sidecar eth_getProof on async workers Fixed in the reth v2.6.0 bump (df7168efb5, ethereum-optimism/optimism#23046): permit plus spawn_blocking_io_fut, with the window checked before taking the permit Same pattern. Take upstream's version on the next bump
debug_executionWitness on async workers Still re-executes on the async task Fixed here first; could go upstream
Harness anchor, ordering test — (Mantle's harness; upstream has no second eth_getProof override to order against) Mantle only

… workers

The proofs engine writes to the sidecar in batches, so the newest blocks
failed with `no state found`. Answer a canonical block above the window and
within 64 blocks of the head from reth's own state; the lower bound stays
strict.

- Run the sidecar eth_getProof on a blocking IO task and debug_executionWitness
  on a blocking task, instead of async runtime workers.
- Seed the test sidecar with the real genesis anchor so tests can mine blocks.
- Check that block 0 is served once it is no longer the tip, which only the
  sidecar override can do, and that blocks not yet in the sidecar are served.
@ivanwang-coder

Copy link
Copy Markdown
Author

Closing: Mantle's proof consumers (op-succinct, the bridge) only query explicit deep blocks, so none of these changes is needed for v1.7.0; the off-worker eth_getProof change will arrive with the next upstream sync (df7168efb5).

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.

1 participant