forked from paradigmxyz/reth
-
Notifications
You must be signed in to change notification settings - Fork 3
feat: AL-direct prefetch from EIP-2930 access lists at block build time #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
defistar
wants to merge
15
commits into
dev
Choose a base branch
from
feature/al-prefetch-only
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
ca55647
feat: AL-direct prefetch from EIP-2930 access lists at block build time
defistar 1403036
chore: ignore local spec/design docs via .gitignore
defistar b9fe235
perf: deduplicate AL prefetch keys before MDBX reads
defistar cc0a195
refactor: move AL prefetch to correct position between selection and …
defistar dc073b2
refactor: simplify al_prefetch — remove dedup, lean down comments
defistar c0b406e
perf: re-add dedup to address review — one MDBX read per unique key
defistar ab7d8f9
chore: remove dedup comments
defistar 80211de
diag: add reth_al_prefetch_calls_total counter
defistar 7f552e3
diag: warn-log AL prefetch init with raw env var value
defistar 6ef2a55
feat: wire EIP-2930 access lists into BAL prefetcher
defistar a740ed1
obs: add logging and metrics for EIP-2930 BAL prefetch path
defistar 68db3f4
obs: upgrade BAL prefetch sent log from debug to info
defistar d5f680f
fix: setup issues
defistar 7875cb1
fix: remove obselete BAL entry modification
defistar 8020263
feat: remove redundant logging in al-prefetch function
defistar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,3 +75,6 @@ __pycache__/ | |
| # direnv | ||
| .envrc | ||
| .direnv/ | ||
|
|
||
| # Local spec / design docs | ||
| *_SPEC.md | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| use alloy_consensus::Transaction as _; | ||
| use alloy_primitives::{map::HashSet, Address, U256}; | ||
| use reth_payload_util::PayloadTransactions; | ||
| use std::sync::OnceLock; | ||
| use tracing::{debug, info}; | ||
|
|
||
| static ENABLED: OnceLock<bool> = OnceLock::new(); | ||
|
|
||
| pub fn is_enabled() -> bool { | ||
| *ENABLED.get_or_init(|| { | ||
| let raw = std::env::var("TXPOOL_AL_PREFETCH_ONLY").unwrap_or_default(); | ||
| let enabled = matches!(raw.as_str(), "1" | "true" | "True" | "TRUE"); | ||
| // Fires exactly once at first call — visible in node logs regardless of log level. | ||
| tracing::warn!( | ||
| target: "payload_builder::al_prefetch", | ||
| enabled, | ||
| raw_value = %raw, | ||
| "AL prefetch init (TXPOOL_AL_PREFETCH_ONLY)" | ||
| ); | ||
| enabled | ||
| }) | ||
| } | ||
|
|
||
| /// Pre-loads EIP-2930 access list keys from MDBX into the EVM's cached DB | ||
| /// for the already-selected best transactions, before execution begins. | ||
| /// Reads go through `builder.evm_mut().db_mut()` so State/CachedReads is | ||
| /// populated automatically — the EVM then hits cache instead of MDBX. | ||
| pub fn prefetch_from_best_txs<Txs, DB>(mut txs: Txs, db: &mut DB) | ||
| where | ||
| Txs: PayloadTransactions, | ||
| Txs::Transaction: alloy_consensus::Transaction, | ||
| DB: revm::Database, | ||
| { | ||
| let start = std::time::Instant::now(); | ||
| let mut tx_count = 0usize; | ||
|
|
||
| let mut accounts: HashSet<Address> = HashSet::default(); | ||
| let mut slots: HashSet<(Address, U256)> = HashSet::default(); | ||
|
|
||
| while let Some(tx) = txs.next(()) { | ||
| let Some(al) = tx.access_list() else { | ||
| continue | ||
| }; | ||
| if al.0.is_empty() { | ||
| continue; | ||
| } | ||
|
|
||
| tx_count += 1; | ||
| for item in &al.0 { | ||
| accounts.insert(item.address); | ||
| for key in &item.storage_keys { | ||
| slots.insert((item.address, U256::from_be_bytes(key.0))); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // Pass 2: one MDBX read per unique key — populates State/CachedReads. | ||
| for &addr in &accounts { | ||
| let _ = db.basic(addr); | ||
| } | ||
| for &(addr, slot) in &slots { | ||
| let _ = db.storage(addr, slot); | ||
| } | ||
|
|
||
| let key_count = accounts.len() + slots.len(); | ||
|
|
||
| let elapsed_us = start.elapsed().as_micros() as u64; | ||
|
|
||
| // Always increments — non-zero confirms is_enabled() fired and the code | ||
| // path is executing, even if no incoming txns carry access lists. | ||
| metrics::counter!("reth_al_prefetch_calls_totcal").increment(1); | ||
| metrics::counter!("reth_al_prefetch_tx_with_access_list_total").increment(tx_count as u64); | ||
| metrics::counter!("reth_al_prefetch_keys_extracted_total").increment(key_count as u64); | ||
| metrics::histogram!("reth_al_prefetch_duration_seconds") | ||
| .record(elapsed_us as f64 / 1_000_000.0); | ||
|
|
||
| debug!( | ||
| target: "payload_builder::al_prefetch", | ||
| tx_count, | ||
| key_count, | ||
| elapsed_us, | ||
| "AL prefetch completed" | ||
| ); | ||
| } | ||
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
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The prefetch reads the same MDBX data on the same thread, sequentially