Skip to content

perf(db): Pass ExecutedBlocks to OverlayBuilder, reduce reverts queried#23657

Merged
mediocregopher merged 22 commits into
mainfrom
mediocregopher/lazyoverlay-refactor
Apr 27, 2026
Merged

perf(db): Pass ExecutedBlocks to OverlayBuilder, reduce reverts queried#23657
mediocregopher merged 22 commits into
mainfrom
mediocregopher/lazyoverlay-refactor

Conversation

@mediocregopher
Copy link
Copy Markdown
Member

@mediocregopher mediocregopher commented Apr 20, 2026

LazyOverlay now carries executed blocks, derives and caches overlays by requested anchor, and OverlayBuilder::new requires the anchor hash when combining reverts with lazy or immediate overlays. This allows us to not have to request reverts in OverlayBuilder when the new anchor is the parent of one of the blocks in the overlay itself, we just recompute a new overlay on the fly.

Example

Given:

  • anchor block: 10
  • overlay blocks: 11->15
  • db tip: 13 (can happen if persistence completes during payload validation initialization)

Previously

Overlay = reverts(13->10) + in_mem_overlay(11->15)

Now

Overlay = in_mem_overlay(14->15) (computed on-the-fly)

Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dab40-7d65-709b-90d6-98965c5c6a65
Co-authored-by: Amp <amp@ampcode.com>
@github-project-automation github-project-automation Bot moved this to Backlog in Reth Tracker Apr 20, 2026
@mediocregopher mediocregopher added A-engine Related to the engine implementation A-trie Related to Merkle Patricia Trie implementation C-debt A clean up/refactor of existing code labels Apr 20, 2026
@mediocregopher mediocregopher self-assigned this Apr 20, 2026
Comment thread crates/chain-state/src/lazy_overlay.rs Outdated
Comment thread crates/chain-state/src/lazy_overlay.rs Outdated
Comment thread crates/chain-state/src/lazy_overlay.rs
Comment thread crates/chain-state/src/lazy_overlay.rs Outdated
Comment thread crates/engine/tree/src/tree/state.rs Outdated
mediocregopher and others added 2 commits April 20, 2026 15:01
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dab40-7d65-709b-90d6-98965c5c6a65
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dab6f-7cee-755e-9f9c-309ae0b8517c
Co-authored-by: Amp <amp@ampcode.com>
Comment thread crates/storage/provider/src/providers/state/overlay.rs Outdated
mediocregopher and others added 2 commits April 20, 2026 15:46
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dab6f-7cee-755e-9f9c-309ae0b8517c
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019daba4-3598-758d-8771-cb5db784db81
Co-authored-by: Amp <amp@ampcode.com>
Comment thread crates/storage/provider/src/providers/state/overlay.rs Outdated
Comment thread crates/chain-state/src/lazy_overlay.rs
Comment thread crates/engine/tree/src/tree/payload_validator.rs Outdated
Comment thread crates/storage/provider/src/providers/state/overlay.rs Outdated
Comment thread crates/storage/provider/src/providers/state/overlay.rs Outdated
Comment thread crates/storage/provider/src/providers/state/overlay.rs Outdated
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019daba4-3598-758d-8771-cb5db784db81
Co-authored-by: Amp <amp@ampcode.com>
Comment thread crates/engine/tree/src/tree/payload_validator.rs Outdated
Comment thread crates/storage/provider/src/providers/state/overlay.rs Outdated
mediocregopher and others added 7 commits April 20, 2026 16:36
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019daba4-3598-758d-8771-cb5db784db81
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dafa5-05ee-739e-a0b6-037cc30e4a0e
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019daba4-3598-758d-8771-cb5db784db81
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dafbb-3571-73ef-ae67-43c242e2bf23
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dafbb-3571-73ef-ae67-43c242e2bf23
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dafbb-3571-73ef-ae67-43c242e2bf23
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019db57a-7f08-7761-9a50-27a2a5c8f917
Co-authored-by: Amp <amp@ampcode.com>
@mediocregopher
Copy link
Copy Markdown
Member Author

derek bench big-blocks

@decofe
Copy link
Copy Markdown
Member

decofe commented Apr 22, 2026

cc @mediocregopher

✅ Benchmark complete! View job

Benchmark Results

Metric main mediocregopher/lazyoverlay-refactor Change
Mean 793.44ms 775.25ms -2.29% ✅ (±1.35%)
StdDev 207.82ms 172.31ms
P50 746.01ms 738.41ms -1.02% ⚪ (±1.52%)
P90 1021.66ms 929.68ms -9.00% ✅ (±3.39%)
P99 1778.02ms 1612.10ms -9.33% ⚪ (±18.06%)
Mgas/s 1343.03 1359.51 +1.23% ✅ (±1.05%)
Wall Clock 825.45s 807.65s -2.16% ✅ (±1.71%)
Persist Wait 2.06ms 1.75ms -14.90% ⚪ (±67.10%)

500 big blocks, 20 warmup

Wait Time Breakdown

Persistence Wait

Metric main mediocregopher/lazyoverlay-refactor
Mean 2.06ms 1.75ms
P50 0.06ms 0.06ms
P95 0.09ms 0.09ms

Trie Cache Update Wait

Metric main mediocregopher/lazyoverlay-refactor
Mean 0.35ms 0.26ms
P50 0.00ms 0.00ms
P95 0.00ms 0.00ms

Execution Cache Update Wait

Metric main mediocregopher/lazyoverlay-refactor
Mean 0.00ms 0.00ms
P50 0.00ms 0.00ms
P95 0.00ms 0.00ms

Grafana Dashboard

Charts

Latency, Throughput & Diff

Latency, Throughput & Diff

Wait Time Breakdown

Wait Time Breakdown

Gas vs Latency

Gas vs Latency

Grafana Dashboard

View real-time metrics

mediocregopher and others added 3 commits April 22, 2026 14:11
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019db57a-7f08-7761-9a50-27a2a5c8f917
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019db57a-7f08-7761-9a50-27a2a5c8f917
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dbc30-68d0-76b8-a32c-e1173122ca48
Co-authored-by: Amp <amp@ampcode.com>
@mediocregopher
Copy link
Copy Markdown
Member Author

derek bench blocks=2000

@mediocregopher
Copy link
Copy Markdown
Member Author

derek bench blocks=500 big-blocks

@decofe
Copy link
Copy Markdown
Member

decofe commented Apr 24, 2026

cc @mediocregopher

❌ Benchmark failed while running baseline benchmark (1/2). View logs

@decofe
Copy link
Copy Markdown
Member

decofe commented Apr 24, 2026

cc @mediocregopher

❌ Benchmark failed while unknown step. View logs

@decofe
Copy link
Copy Markdown
Member

decofe commented Apr 24, 2026

cc @mediocregopher

❌ Benchmark failed while unknown step. View logs

Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dbee7-f576-769d-923c-dfdfe0a40858
Co-authored-by: Amp <amp@ampcode.com>
@mediocregopher
Copy link
Copy Markdown
Member Author

derek bench blocks=2000

@decofe
Copy link
Copy Markdown
Member

decofe commented Apr 24, 2026

cc @mediocregopher

✅ Benchmark complete! View job

Benchmark Results

⚠️ Feature is 5 commits behind main. Consider rebasing for accurate results.

Metric main mediocregopher/lazyoverlay-refactor Change
Mean 30.40ms 30.39ms -0.03% ⚪ (±1.20%)
StdDev 24.56ms 24.37ms
P50 24.39ms 24.38ms -0.03% ⚪ (±1.17%)
P90 48.05ms 48.71ms +1.37% ⚪ (±3.49%)
P99 139.93ms 140.49ms +0.40% ⚪ (±8.74%)
Mgas/s 1138.75 1139.73 +0.09% ⚪ (±0.55%)
Wall Clock 125.51s 125.30s -0.17% ⚪ (±1.17%)
Persist Wait 23.33ms 23.21ms -0.55% ⚪ (±12.69%)

2000 blocks, 200 warmup

Wait Time Breakdown

Persistence Wait

Metric main mediocregopher/lazyoverlay-refactor
Mean 23.33ms 23.21ms
P50 0.02ms 0.02ms
P95 223.69ms 217.59ms

Trie Cache Update Wait

Metric main mediocregopher/lazyoverlay-refactor
Mean 0.42ms 0.40ms
P50 0.05ms 0.04ms
P95 1.78ms 1.64ms

Execution Cache Update Wait

Metric main mediocregopher/lazyoverlay-refactor
Mean 0.00ms 0.00ms
P50 0.00ms 0.00ms
P95 0.00ms 0.00ms

Grafana Dashboard

Charts

Latency, Throughput & Diff

Latency, Throughput & Diff

Wait Time Breakdown

Wait Time Breakdown

Gas vs Latency

Gas vs Latency

Grafana Dashboard

View real-time metrics

Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dbf08-3c9d-736b-9b47-3070f2bf2a54
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dcdd4-c9f4-76ec-b23f-c18456b71247
Co-authored-by: Amp <amp@ampcode.com>
@mediocregopher mediocregopher changed the title refactor(chain-state): derive lazy overlay anchor from blocks refactor(provider): anchor state overlays in OverlayBuilder Apr 27, 2026
@mediocregopher mediocregopher changed the title refactor(provider): anchor state overlays in OverlayBuilder perf(db): Pass ExecutedBlocks to OverlayBuilder, reduce reverts queried Apr 27, 2026
Comment on lines +253 to +259
// If the DB tip has moved forward into the `LazyOverlay` then we still don't need to
// revert, the `LazyOverlay` will generate a new in-memory overlay using only the relevant
// blocks data.
if let Some(OverlaySource::Lazy(lazy_overlay)) = &self.overlay_source &&
lazy_overlay.has_anchor_hash(db_tip_block.hash)
{
return Ok(None)
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the optimization

Co-authored-by: Brian Picciano <933154+mediocregopher@users.noreply.github.com>
Amp-Thread-ID: https://ampcode.com/threads/T-019dce92-2fe5-730d-9b8e-69d62a796b85
Co-authored-by: Amp <amp@ampcode.com>
@mediocregopher mediocregopher marked this pull request as ready for review April 27, 2026 11:07
Copy link
Copy Markdown
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@github-project-automation github-project-automation Bot moved this from Backlog to In Progress in Reth Tracker Apr 27, 2026
@mediocregopher mediocregopher added this pull request to the merge queue Apr 27, 2026
Merged via the queue into main with commit 344037d Apr 27, 2026
34 checks passed
@mediocregopher mediocregopher deleted the mediocregopher/lazyoverlay-refactor branch April 27, 2026 13:33
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Reth Tracker Apr 27, 2026
umeeSthein pushed a commit to umeeSthein/tempo that referenced this pull request Apr 30, 2026
Automated nightly update of reth dependencies from `paradigmxyz/reth`
main branch.

## Upstream reth changes


[`7839f3d...73ec2c9`](paradigmxyz/reth@7839f3d...73ec2c9)

🔗 Amp thread:
https://ampcode.com/threads/T-019dd89b-f659-75eb-a3f2-3e769d63297f
**Engine**
- Spawn BAL hashed state before storage prefetch
([#23761](paradigmxyz/reth#23761)) and disable
BAL parallel execution by default
([#23764](paradigmxyz/reth#23764))
- Add CLI flag to disable BAL storage prefetch
([#23770](paradigmxyz/reth#23770))
- Log transient invalid header cache skips
([#23711](paradigmxyz/reth#23711))
- Add `DecodedBal` in `ExecutionEnv`
([#23675](paradigmxyz/reth#23675))

**RPC**
- Clean up eth state cache reorg entries
([#23683](paradigmxyz/reth#23683))
- Pass block timestamp to txn
([#23700](paradigmxyz/reth#23700))
- Include block numbers in `BlockRangeExceedsHead` error
([#23720](paradigmxyz/reth#23720))

**Network / P2P**
- Add Basic in-memory BAL store and BAL request to block access list
requests ([#23682](paradigmxyz/reth#23682),
[#23710](paradigmxyz/reth#23710))
- Enforce BAL response soft limit and apply count cap to handler
([#23725](paradigmxyz/reth#23725),
[#23754](paradigmxyz/reth#23754))
- Avoid RLP-decoding `NewBlock` payloads
([#23712](paradigmxyz/reth#23712)) and bound
memory footprint of p2p messages
([#23718](paradigmxyz/reth#23718))
- Memory-bound channel between network and tx manager
([#23802](paradigmxyz/reth#23802))
- Track unknown tx types in announcement metrics
([#23688](paradigmxyz/reth#23688))
- Retain active session buffer capacity
([#23702](paradigmxyz/reth#23702)) and respect
peer requirements for fetch followups
([#23706](paradigmxyz/reth#23706))
- Support binding discv5 and discv4 to the same port
([#23613](paradigmxyz/reth#23613)) and use Weak
reference in discv5 kbuckets bg task to release port on shutdown
([#23282](paradigmxyz/reth#23282))

**Trie**
- Skip DB seek on exact overlay hits
([#23559](paradigmxyz/reth#23559))
- Account for heap-allocated blinded hashes in `SparseNode::memory_size`
([#23726](paradigmxyz/reth#23726))

**DB / Storage**
- `reth db migrate-v2` for pruned nodes
([#23716](paradigmxyz/reth#23716))
- Pass `ExecutedBlocks` to `OverlayBuilder`, reduce reverts queried
([#23657](paradigmxyz/reth#23657))
- Add empty request check to storage values
([#23714](paradigmxyz/reth#23714))
- Derive `Eq` for `IntegerList`
([#23709](paradigmxyz/reth#23709)) and reorder
unix deps after strum
([#23697](paradigmxyz/reth#23697))

**Provider / EVM**
- Use overlay builders in historical state paths
([#23667](paradigmxyz/reth#23667))
- Return gas output from block builder
([#23744](paradigmxyz/reth#23744))
- Expose executor transaction result type
([#23759](paradigmxyz/reth#23759))

**Perf**
- Configurable rocksdb block cache size and re-use of mdbx provider in
re-execute ([#23701](paradigmxyz/reth#23701))
- Enable revm `p256-aws-lc-rs` feature
([#23721](paradigmxyz/reth#23721))
- Add platform-specific RUSTFLAGS to Dockerfile
([#23738](paradigmxyz/reth#23738))

**Bench**
- Add reorg mode to `new-payload-fcu`
([#23666](paradigmxyz/reth#23666))
- Enable `keccak-cache-global` in `reth-bb`
([#23723](paradigmxyz/reth#23723)) and fix
multi-executor support
([#23763](paradigmxyz/reth#23763))
- Dedupe merged BAL storage reads
([#23758](paradigmxyz/reth#23758))

**Re-execute**
- Verify reverts against changesets
([#23717](paradigmxyz/reth#23717))

**Payload**
- Track Amsterdam block gas in builders
([#23743](paradigmxyz/reth#23743))

**CLI**
- Use `TxTy`/`ReceiptTy` for static-file db get
([#23692](paradigmxyz/reth#23692)) and node
types in execution stage dump
([#23705](paradigmxyz/reth#23705))
- Preserve `trusted_nodes_only` from config when `--trusted-only` is
unset ([#23703](paradigmxyz/reth#23703))
- Avoid u64 underflow in `setup_without_evm` for genesis header
([#23728](paradigmxyz/reth#23728))

**Testing**
- Add BAL request e2e coverage
([#23727](paradigmxyz/reth#23727))
- Cover admin node info discv5 port
([#23781](paradigmxyz/reth#23781))

**Misc**
- Bump reth core to v0.3.1
([#23707](paradigmxyz/reth#23707)) and alloy-evm
to 0.33.3 ([#23778](paradigmxyz/reth#23778))
- Align ERA1 export with spec
([#23693](paradigmxyz/reth#23693))

## Migrations

🔗 Amp thread:
https://ampcode.com/threads/T-019dd89c-63d3-752f-ac22-7d4aef2ac3e3
- **Bumped reth git rev** from `7839f3d` to `73ec2c9` across all
`reth-*` workspace dependencies in
[Cargo.toml](file:///home/runner/work/tempo/tempo/Cargo.toml), and
bumped `reth-primitives-traits` from `0.3.0` to `0.3.1` and `alloy-evm`
from `0.33.0` to `0.34.0` to track upstream releases.
- **Switched p2p proxy transactions channel** from
`tokio::sync::mpsc::unbounded_channel` to
`reth_metrics::common::mpsc::memory_bounded_channel` with a 32 MiB
budget in
[bin/tempo/src/p2p_proxy.rs](file:///home/runner/work/tempo/tempo/bin/tempo/src/p2p_proxy.rs),
matching reth's new default `tx_channel_memory_limit_bytes` to prevent
unbounded memory growth; added `reth-metrics` to
[bin/tempo/Cargo.toml](file:///home/runner/work/tempo/tempo/bin/tempo/Cargo.toml).
- **Changed `BlockExecutor::commit_transaction` signature** in
[crates/evm/src/block.rs](file:///home/runner/work/tempo/tempo/crates/evm/src/block.rs)
from returning `Result<GasOutput, BlockExecutionError>` to returning
`GasOutput` directly (upstream removed the fallible return); replaced
the missing-tx error with an `expect`, and updated all tests to drop
`.unwrap()`.
- **Added `Send + 'static` bound to `TxResult` impl** for
`TempoTxResult<H>` to satisfy the new upstream trait bounds on
associated execution-result types.
- **Exposed `TempoBlockExecutor` and `TempoTxResult` as `pub`**
(previously `pub(crate)`) and re-exported them from
[crates/evm/src/lib.rs](file:///home/runner/work/tempo/tempo/crates/evm/src/lib.rs)
so they can be named in the new associated types.
- **Added associated types `TxExecutionResult` and `Executor` to
`BlockExecutorFactory` impl** for `TempoEvmConfig`, and changed
`create_executor` to return the concrete `Self::Executor<'a, DB, I>`
instead of `impl BlockExecutorFor<'a, Self, DB, I>`, tracking upstream's
move from RPIT to named associated types; dropped the now-unused
`BlockExecutorFor` import and the `'a` lifetime bounds on `DB`/`I`.
- **Implemented new `HeaderMut` methods** (`set_mix_hash`,
`set_extra_data`, `set_parent_beacon_block_root`) for `TempoHeader` in
[crates/primitives/src/reth_compat/header.rs](file:///home/runner/work/tempo/tempo/crates/primitives/src/reth_compat/header.rs)
to satisfy the expanded upstream trait, delegating to the inner Ethereum
header.

[GitHub
Workflow](https://github.com/tempoxyz/tempo/actions/runs/25101489247)

---------

Co-authored-by: Centaur AI <ai@centaur.local>
Co-authored-by: Amp <amp@ampcode.com>
Co-authored-by: klkvr <klkvrr@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-engine Related to the engine implementation A-trie Related to Merkle Patricia Trie implementation C-debt A clean up/refactor of existing code

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants