Skip to content
Closed
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
29 changes: 4 additions & 25 deletions crates/rbuilder/src/building/precompile_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,31 +58,10 @@ 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);

// get the result if it exists
if let Some(precompiles) = self.cache.lock().get_mut(&inputs.target_address) {
if let Some(result) = precompiles.get(&key) {
inc_precompile_cache_hits();
return result.clone().map(Some);
}
}

inc_precompile_cache_misses();

// call the precompile if cache miss
let output = self.precompile.run(context, inputs);

if let Some(output) = output.clone().transpose() {
// insert the result into the cache
self.cache
.lock()
.entry(inputs.target_address)
.or_insert(PrecompileResultCache::new(NonZeroUsize::new(2048).unwrap()))
.put(key, output);
}

output
// Skip the cache entirely — profiling shows 0 hits across 177K calls.
// The cache key includes gas_limit which varies per call, preventing hits.
// The Bytes clone + mutex lock/unlock overhead is pure waste.
self.precompile.run(context, inputs)
}

fn warm_addresses(&self) -> Box<impl Iterator<Item = Address>> {
Expand Down