You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
execution/exec: execute read-ahead blocks to warm state - #26332
Multi-block exec faults state pages in on demand: blocksReadAheadFunc warms only sender, to, code and access-list keys, and read-ahead never runs in the initial cycle.
READ_AHEAD_EXEC runs block N+500's txs on a read-only reader, results dropped, to warm what they touch; READ_AHEAD_EXEC_COMMITMENT also prefetches their commitment branches; READ_AHEAD_INITIAL starts read-ahead in the initial cycle. All default off.
Draft: a live node shared the box; a quiet rerun decides. Commitment prefetch shows no win.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Speculative block states are never closed, draining resource pools, and the loading-based watermark can skip useful read-ahead before actual execution starts.
This PR adds opt-in speculative block execution to Erigon’s read-ahead pipeline, warming state pages before normal execution reaches them. Speculative results are discarded, and the new execution, commitment-prefetch, and initial-cycle options default to off.
Changes:
Adds speculative transaction execution, optional commitment prefetch, and warmup metrics.
Makes read-ahead distance and worker count configurable, with matching database reader capacity.
Adds tests for state isolation, cancellation, commitment keys, reader capacity, and initial-cycle execution.
File
Description
node/node.go
Includes configured read-ahead workers in database reader capacity.
execution/stagedsync/read_ahead_initial_test.go
Compares state roots and receipts with initial-cycle read-ahead enabled.
execution/stagedsync/exec3.go
Wires read-ahead options and the block-progress watermark into staged execution.
execution/exec/historical_trace_worker.go
Adapts historical tracing to the expanded read-ahead API.
execution/exec/blocks_read_ahead.go
Implements speculative execution, key recording, metrics, and cancellation.
execution/exec/blocks_read_ahead_test.go
Adds speculative execution and resource-handling regression tests.
execution/exec/bal_commitment_warmup.go
Shares commitment-key generation and supports prefetch with an existing transaction.
execution/exec/bal_commitment_warmup_test.go
Updates tests for explicit prefetch parallelism.
common/dbg/experiments.go
Defines read-ahead experiment switches and tuning settings.
cmd/utils/flags.go
Updates reader-capacity validation and diagnostics.
cmd/rpcdaemon/cli/httpcfg/http_cfg.go
Sizes the reader limit using configurable read-ahead workers.
cmd/rpcdaemon/cli/httpcfg/http_cfg_test.go
Tests reader limits with configurable and disabled worker pools.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Speculative execution failures can be recorded as successful warmups and prefetch incomplete write sets, while the tests rely on uncontrolled scheduling and stored header roots that cannot verify persisted-state equivalence.
Mark failed speculative execution as errored and stop warmup
execution/exec/blocks_read_ahead.go:982
An ApplyMessage or FinalizeTx failure leaves Errored false, so the caller records this partial warmup as "done" and can prefetch an incomplete write set. State-read failures also need an explicit StateReadError check because they are not always returned by ApplyMessage. Check these errors, mark the speculative block as errored, and stop it without failing canonical execution.
Compare persisted state instead of stored header roots
These roots come from m.Current(tx), which reads the stored block header, not the state produced by Sync.Run. Both runs insert the same generated headers, so this equality cannot detect a difference in persisted state. Please compare a root computed from the resulting state, or read and assert the sender nonce and contract storage through m.NewStateReader(tx) in both runs, and check that execution reached the expected head.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Read-ahead gives each transaction a fresh block-sized gas pool, allowing speculative work to exceed the cumulative block gas budget and compete with real execution for CPU.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Bound speculative execution by the block gas budget
execution/exec/blocks_read_ahead.go:981
Each transaction receives a fresh block-sized gas pool, so speculative execution has no cumulative block gas budget. On the older snapshot, calls that return cheaply in real execution can instead exhaust their gas limits, making read-ahead workers consume many times the block gas limit and compete with execution for CPU. Share a bounded gas pool across the loop and stop when the remaining budget cannot admit the next transaction.
execution/exec/blocks_read_ahead.go L924: delete: the READ_AHEAD_EXEC_COMMITMENT arm. The body measures no win for it (−2.6% vs −6.0% for exec alone, and +102 CPU s). Delete the flag, readAheadCommitmentKeys, the written-key maps, readAheadPrefetchCommitment, the par parameter added through bal_commitment_warmup.go, the prefetchCommitmentWithTx split (L457), and the three TestReadAheadCommitment* tests. readAheadRecordingWriter then only counts writes, so state.NewNoopWriter() can be used directly.
L715, L733: delete: StorageReadKeys. Only a test reads it, but every speculative SLOAD inserts into this map. Assert on StorageRead in the test instead.
L703, L708: idiom: ReadAheadStorageKey and ReadAheadExecStats are exported, but only code in this package uses them. Make them unexported.
L943: bug: recover() != nil discards the panic value. A real EVM bug on this path then shows up only as an error metric. Log the value with dbg.Stack() before returning.
L967: speed: types.MakeSigner is called once per tx, but the signer depends only on the block. Create it once before the loop.
blocks_read_ahead_test.go L1366, L1388, L1431: idiom: the TestReview* names record which review round added them. Remove the Review prefix.
execution/stagedsync/exec3.go L222: idiom the read-ahead comment (L222-224) now sits above pe :=, and var clean func() (L200) moved to function scope, but only the if at L242 uses it. Move the comment to L242 and declare clean inside the if, as before.
execution/exec/blocks_read_ahead.go L964: shrink each tx checks the ctx twice (L964 and L974-976). One if ctx.Err() != nil { return } right after evm.Reset covers both cases: a cancel before the check returns, and a cancel after it reaches evm.Cancel through context.AfterFunc.
execution/exec/blocks_read_ahead.go L930: shrink the map[string]int{...} literal allocates a map on every block only to loop over three counters. Write three AddInt calls, like L933-934 do.
execution/exec/blocks_read_ahead_test.go L1329, L1349: idiom the helpers reviewReadAheadTx and reviewReadAheadFixture also carry the review-round name. Rename them too, for example readAheadStubTx and readAheadFixture.
Tip numbers for the same mechanism (a block's txs pre-executed on a read-only reader, results dropped). Taken on another branch with commitment v3, not on this PR's build.
At the tip it nets zero on newPayload: the commitment round and the time outside the exec loop get shorter, and the exec loop pays it back per Mgas.
arb1-dev mainnet tip, 154 pairs, 2026-11-19
pre-exec
main's read-ahead
paired change
p
newPayload p50, ms
29
28
−1.7%
.95
exec loop, ms per Mgas
0.779
0.737
−7.2%
5.2e-05
commitment round + wait, ms
2.704
3.25
+17.1%
5.5e-11
outside the exec loop, ms
5
6
+20.0%
1.2e-06
So the case for this PR is catch-up sync only: the −6.0% (p .031) in the body, taken on a shared box for +19% CPU (608.5 → 723.3 s).
It stays a draft until that table is rerun on a quiet box. If the rerun shows no win, it gets closed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
blocksReadAheadFuncwarms only sender,to, code and access-list keys, and read-ahead never runs in the initial cycle.READ_AHEAD_EXECruns block N+500's txs on a read-only reader, results dropped, to warm what they touch;READ_AHEAD_EXEC_COMMITMENTalso prefetches their commitment branches;READ_AHEAD_INITIALstarts read-ahead in the initial cycle. All default off.arb1-dev, mainnet archive from 26054550, ~3,300 blocks, cold cache, 6 ABBA rounds, medians,
e76f2914ea0.