diff --git a/bin/reth/src/block_ingest.rs b/bin/reth/src/block_ingest.rs index 090d845e8..09b99e9b6 100644 --- a/bin/reth/src/block_ingest.rs +++ b/bin/reth/src/block_ingest.rs @@ -12,7 +12,7 @@ use alloy_rpc_types::engine::{ use jsonrpsee::http_client::{transport::HttpBackend, HttpClient}; use reth::network::PeersHandleProvider; use reth_chainspec::{EthChainSpec, EthereumHardforks}; -use reth_hyperliquid_types::PrecompilesCache; +use reth_hyperliquid_types::{PrecompileData, PrecompilesCache}; use reth_node_api::{Block, FullNodeComponents, PayloadTypes}; use reth_node_builder::EngineTypes; use reth_node_builder::NodeTypesWithEngine; @@ -191,7 +191,10 @@ impl BlockIngest { let mut u_cache = cache.lock().await; let mut u_pre_cache = precompiles_cache.lock(); for blk in new_blocks { - let precompiles = blk.read_precompile_calls.clone(); + let precompiles = PrecompileData { + precompiles: blk.read_precompile_calls.clone(), + highest_precompile_address: blk.highest_precompile_address, + }; let h = match &blk.block { EvmBlock::Reth115(b) => { let block_number = b.header().number() as u64; diff --git a/bin/reth/src/main.rs b/bin/reth/src/main.rs index 08da17655..a19ff491a 100644 --- a/bin/reth/src/main.rs +++ b/bin/reth/src/main.rs @@ -9,7 +9,7 @@ mod serialized; mod spot_meta; mod tx_forwarder; -use std::{collections::BTreeMap, path::PathBuf, sync::Arc}; +use std::{collections::BTreeMap, sync::Arc}; use block_ingest::BlockIngest; use call_forwarder::CallForwarderApiServer; diff --git a/bin/reth/src/serialized.rs b/bin/reth/src/serialized.rs index 49dec5740..8ea87c6fe 100644 --- a/bin/reth/src/serialized.rs +++ b/bin/reth/src/serialized.rs @@ -11,6 +11,7 @@ pub(crate) struct BlockAndReceipts { pub system_txs: Vec, #[serde(default)] pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>, + pub highest_precompile_address: Option
, } #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/crates/ethereum/evm/src/execute.rs b/crates/ethereum/evm/src/execute.rs index 2c6293c09..fcbac3f83 100644 --- a/crates/ethereum/evm/src/execute.rs +++ b/crates/ethereum/evm/src/execute.rs @@ -27,12 +27,6 @@ use reth_primitives_traits::{transaction::signed::is_impersonated_tx, NodePrimit use reth_revm::{ context_interface::result::ResultAndState, db::State, state::Bytecode, DatabaseCommit, }; -use std::{ - cell::RefCell, - sync::Mutex, - time::{Duration, Instant}, -}; -use tracing::info; /// Factory for [`EthExecutionStrategy`]. #[derive(Debug, Clone)] diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index b601df299..a4822d5f0 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -21,14 +21,13 @@ use alloc::sync::Arc; use alloy_consensus::{BlockHeader, Header}; use alloy_evm::eth::EthEvmContext; pub use alloy_evm::EthEvm; -use alloy_primitives::Address; -use alloy_primitives::U160; -use alloy_primitives::U256; +use alloy_primitives::{address, Address, U160, U256}; use core::{convert::Infallible, fmt::Debug}; use parking_lot::RwLock; use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET}; use reth_evm::Database; use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, EvmFactory, NextBlockEnvAttributes}; +use reth_hyperliquid_types::PrecompileData; use reth_hyperliquid_types::{PrecompilesCache, ReadPrecompileInput, ReadPrecompileResult}; use reth_node_builder::HyperliquidSharedState; use reth_primitives::SealedBlock; @@ -200,6 +199,7 @@ impl ConfigureEvmEnv for EthEvmConfig { pub(crate) struct BlockAndReceipts { #[serde(default)] pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>, + pub highest_precompile_address: Option
, } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -228,7 +228,7 @@ pub(crate) fn collect_s3_block(ingest_path: PathBuf, height: u64) -> Option Option)>> { +) -> Option { let mut u_cache = precompiles_cache.lock(); u_cache.remove(&height) } @@ -244,13 +244,18 @@ pub(crate) fn collect_block( if let Some(calls) = get_locally_sourced_precompiles_for_height(shared_state.precompiles_cache, height) { - return Some(BlockAndReceipts { read_precompile_calls: calls }); + return Some(BlockAndReceipts { + read_precompile_calls: calls.precompiles, + highest_precompile_address: calls.highest_precompile_address, + }); } } // Fallback to s3 always collect_s3_block(ingest_path, height) } +const WARM_PRECOMPILES_BLOCK_NUMBER: u64 = 8_197_684; + impl EvmFactory for HyperliquidEvmFactory { type Evm, EthInterpreter>> = EthEvm>>; @@ -272,10 +277,16 @@ impl EvmFactory for HyperliquidEvmFactory { .map(|(address, calls)| (address, HashMap::from_iter(calls.into_iter()))) .collect(); - // NOTE: Hotfix but semantically correct. Will be removed once hl-node pipeline is updated (#17) - if input.block_env.number >= 7000000 { - for i in 0x800..=0x80D { - cache.entry(Address::from(U160::from(i))).or_insert(HashMap::new()); + 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; + } + cache.entry(address).or_insert(HashMap::new()); } } diff --git a/crates/ethereum/evm/src/precompile_replay.rs b/crates/ethereum/evm/src/precompile_replay.rs index 09b24d511..9293bb494 100644 --- a/crates/ethereum/evm/src/precompile_replay.rs +++ b/crates/ethereum/evm/src/precompile_replay.rs @@ -5,7 +5,7 @@ use reth_revm::{ context::{Cfg, ContextTr}, handler::{EthPrecompiles, PrecompileProvider}, interpreter::{Gas, InstructionResult, InterpreterResult}, - precompile::{PrecompileError, PrecompileErrors}, + precompile::PrecompileErrors, }; use std::{collections::HashMap, sync::Arc}; @@ -59,7 +59,7 @@ impl PrecompileProvider for ReplayPrecompile { let Some(get) = precompile_calls.get(&input) else { result.gas.spend_all(); result.result = InstructionResult::PrecompileError; - return Ok(Some(result)) + return Ok(Some(result)); }; return match *get { diff --git a/crates/hyperliquid-types/src/lib.rs b/crates/hyperliquid-types/src/lib.rs index 70d19119e..b7c16cbea 100644 --- a/crates/hyperliquid-types/src/lib.rs +++ b/crates/hyperliquid-types/src/lib.rs @@ -18,5 +18,10 @@ pub enum ReadPrecompileResult { UnexpectedError, } -pub type PrecompilesCache = - Arc)>>>>; +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct PrecompileData { + pub precompiles: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>, + pub highest_precompile_address: Option
, +} + +pub type PrecompilesCache = Arc>>;