Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions crates/rbuilder-primitives/src/evm_inspector.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use ahash::HashMap;
use alloy_consensus::Transaction;
use alloy_primitives::{Address, B256, U256};
use alloy_rpc_types::AccessList;
use reth_primitives::{Recovered, TransactionSigned};
use revm::{
bytecode::opcode,
Expand All @@ -10,7 +9,6 @@ use revm::{
interpreter::{interpreter_types::Jumps, CallInputs, CallOutcome, Interpreter},
Inspector,
};
use revm_inspectors::access_list::AccessListInspector;

#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct SlotKey {
Expand Down Expand Up @@ -257,7 +255,6 @@ where

#[derive(Debug)]
pub struct RBuilderEVMInspector<'a> {
access_list_inspector: AccessListInspector,
used_state_inspector: Option<UsedStateEVMInspector<'a>>,
}

Expand All @@ -266,23 +263,15 @@ impl<'a> RBuilderEVMInspector<'a> {
tx: &Recovered<TransactionSigned>,
used_state_trace: Option<&'a mut UsedStateTrace>,
) -> Self {
let access_list_inspector =
AccessListInspector::new(tx.access_list().cloned().unwrap_or_default());

let mut used_state_inspector = used_state_trace.map(UsedStateEVMInspector::new);
if let Some(i) = &mut used_state_inspector {
i.use_tx_nonce(tx);
}

Self {
access_list_inspector,
used_state_inspector,
}
}

pub fn into_access_list(self) -> AccessList {
self.access_list_inspector.into_access_list()
}
}

impl<'a, CTX> Inspector<CTX> for RBuilderEVMInspector<'a>
Expand All @@ -292,7 +281,6 @@ where
{
#[inline]
fn step(&mut self, interp: &mut Interpreter, context: &mut CTX) {
self.access_list_inspector.step(interp, context);
if let Some(used_state_inspector) = &mut self.used_state_inspector {
used_state_inspector.step(interp, context);
}
Expand Down
33 changes: 31 additions & 2 deletions crates/rbuilder/src/building/order_commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,35 @@ where
Factory: EvmFactory,
{
let tx = tx_with_blobs.internal_tx_unsecure();

// Skip the AccessListInspector entirely — it calls step() on every EVM opcode
// just to track accessed addresses for the blocklist check. Instead, we check
// the blocklist against ResultAndState.state (EvmState = HashMap<Address, Account>)
// which already contains every address touched during execution.
// This eliminates ~50% of CPU overhead during block building.
if used_state_tracer.is_none() {
let mut evm = evm_factory.create_evm(db, evm_env);
let res = match evm.transact(tx) {
Ok(res) => res,
Err(err) => match err {
EVMError::Transaction(tx_err) => {
return Ok(Err(TransactionErr::InvalidTransaction(tx_err)))
}
EVMError::Database(_) | EVMError::Header(_) | EVMError::Custom(_) => {
return Err(err.into())
}
},
};
// Check blocklist against addresses in the execution state diff
if !blocklist.is_empty() && res.state.keys().any(|addr| blocklist.contains(addr)) {
return Ok(Err(TransactionErr::Blocklist));
}
return Ok(Ok(res));
}

// Slow path: used_state_tracer is active (parallel builder conflict detection).
// Still need the inspector for UsedStateEVMInspector, but we can skip AccessListInspector
// and use the state diff for blocklist checking instead.
let mut rbuilder_inspector = RBuilderEVMInspector::new(tx, used_state_tracer);

let mut evm = evm_factory.create_evm_with_inspector(db, evm_env, &mut rbuilder_inspector);
Expand All @@ -1177,8 +1206,8 @@ where
},
};
drop(evm);
let access_list = rbuilder_inspector.into_access_list();
if access_list.flatten().any(|(a, _)| blocklist.contains(&a)) {
// Use state diff for blocklist check instead of access list
if !blocklist.is_empty() && res.state.keys().any(|addr| blocklist.contains(addr)) {
return Ok(Err(TransactionErr::Blocklist));
}

Expand Down
9 changes: 6 additions & 3 deletions crates/rbuilder/src/building/precompile_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,11 @@ use std::{num::NonZeroUsize, sync::Arc};
#[derive(Deref, DerefMut, Default, Debug)]
pub struct PrecompileCache(HashMap<Address, PrecompileResultCache>);

/// Precompile result LRU cache stored by `(spec id, input, gas limit)` key.
pub type PrecompileResultCache = LruCache<(SpecId, Bytes, u64), Result<InterpreterResult, String>>;
/// Precompile result LRU cache stored by `(spec id, input)` key.
/// gas_limit is excluded because precompile results are deterministic given the same
/// spec and input — the gas limit only affects whether the call has enough gas to
/// complete, not the result itself.
pub type PrecompileResultCache = LruCache<(SpecId, Bytes), Result<InterpreterResult, String>>;

/// A custom precompile that contains the cache and precompile it wraps.
#[derive(Clone)]
Expand Down Expand Up @@ -58,7 +61,7 @@ impl<CTX: ContextTr, P: PrecompileProvider<CTX, Output = InterpreterResult>> Pre
context: &mut CTX,
inputs: &CallInputs,
) -> Result<Option<Self::Output>, String> {
let key = (self.spec, inputs.input.bytes(context), inputs.gas_limit);
let key = (self.spec, inputs.input.bytes(context));

// get the result if it exists
if let Some(precompiles) = self.cache.lock().get_mut(&inputs.target_address) {
Expand Down