diff --git a/bin/reth/src/block_ingest.rs b/bin/reth/src/block_ingest.rs index a259cb29e..38b06dba5 100644 --- a/bin/reth/src/block_ingest.rs +++ b/bin/reth/src/block_ingest.rs @@ -207,7 +207,7 @@ impl BlockIngest { let mut u_pre_cache = precompiles_cache.lock(); for blk in new_blocks { let precompiles = PrecompileData { - precompiles: blk.read_precompile_calls.clone(), + precompiles: blk.read_precompile_calls.0.clone(), highest_precompile_address: blk.highest_precompile_address, }; let h = match &blk.block { diff --git a/bin/reth/src/serialized.rs b/bin/reth/src/serialized.rs index 8ea87c6fe..3206bcbb0 100644 --- a/bin/reth/src/serialized.rs +++ b/bin/reth/src/serialized.rs @@ -1,5 +1,5 @@ use alloy_primitives::{Address, Log}; -use reth_hyperliquid_types::{ReadPrecompileInput, ReadPrecompileResult}; +use reth_hyperliquid_types::{ReadPrecompileInput, ReadPrecompileResult, ReadPrecompileCalls}; use reth_primitives::{SealedBlock, Transaction}; use serde::{Deserialize, Serialize}; @@ -10,7 +10,7 @@ pub(crate) struct BlockAndReceipts { #[serde(default)] pub system_txs: Vec, #[serde(default)] - pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>, + pub read_precompile_calls: ReadPrecompileCalls, pub highest_precompile_address: Option
, } diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index 334051312..04ecfed9e 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -30,7 +30,6 @@ use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, EvmFactory, NextBlockEnvAt use reth_hyperliquid_types::PrecompileData; use reth_hyperliquid_types::{PrecompilesCache, ReadPrecompileInput, ReadPrecompileResult}; use reth_node_builder::HyperliquidSharedState; -use reth_primitives::SealedBlock; use reth_primitives::TransactionSigned; use reth_revm::context::result::{EVMError, HaltReason}; use reth_revm::handler::EthPrecompiles; @@ -43,7 +42,6 @@ use reth_revm::{ specification::hardfork::SpecId, }; use reth_revm::{Context, Inspector, MainContext}; -use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::path::PathBuf; @@ -223,28 +221,33 @@ impl EvmFactory for HyperliquidEvmFactory { type Context = EthEvmContext; fn create_evm(&self, db: DB, input: EvmEnv) -> Self::Evm { - let block = collect_block( - self.ingest_dir.clone().unwrap(), - self.shared_state.clone(), - input.block_env.number, - ) - .expect("Failed to collect a submitted block. If sourcing locally, make sure your local hl-node is producing blocks."); - let mut cache: HashMap<_, _> = block - .read_precompile_calls - .into_iter() - .map(|(address, calls)| (address, HashMap::from_iter(calls.into_iter()))) - .collect(); + // Try to get precompile data from the shared state cache + // This avoids the overhead of loading block data on every EVM creation + let mut cache: HashMap<_, _> = HashMap::new(); + + if let Some(ref shared_state) = self.shared_state { + if let Some(precompile_data) = get_locally_sourced_precompiles_for_height( + shared_state.precompiles_cache.clone(), + input.block_env.number, + ) { + cache = precompile_data + .precompiles + .into_iter() + .map(|(address, calls)| (address, HashMap::from_iter(calls.into_iter()))) + .collect(); - if input.block_env.number >= WARM_PRECOMPILES_BLOCK_NUMBER { - let highest_precompile_address = block - .highest_precompile_address - .unwrap_or(address!("0x000000000000000000000000000000000000080d")); - for i in 0x800.. { - let address = Address::from(U160::from(i)); - if address > highest_precompile_address { - break; + if input.block_env.number >= WARM_PRECOMPILES_BLOCK_NUMBER { + let highest_precompile_address = precompile_data + .highest_precompile_address + .unwrap_or(address!("0x000000000000000000000000000000000000080d")); + for i in 0x800.. { + let address = Address::from(U160::from(i)); + if address > highest_precompile_address { + break; + } + cache.entry(address).or_insert(HashMap::new()); + } } - cache.entry(address).or_insert(HashMap::new()); } }