From a032ffceb3ef8e093476b9e0d0206e25479a316d Mon Sep 17 00:00:00 2001 From: kamalbuilds Date: Sun, 24 Aug 2025 23:17:03 +0530 Subject: [PATCH] Remove the duplicate definitions and functions from evm.rs and move the precompile cache --- crates/ethereum/evm/src/lib.rs | 42 ----------------------------- crates/hyperliquid-types/src/lib.rs | 21 +++++++++++++++ 2 files changed, 21 insertions(+), 42 deletions(-) diff --git a/crates/ethereum/evm/src/lib.rs b/crates/ethereum/evm/src/lib.rs index a4822d5f0..334051312 100644 --- a/crates/ethereum/evm/src/lib.rs +++ b/crates/ethereum/evm/src/lib.rs @@ -195,17 +195,6 @@ impl ConfigureEvmEnv for EthEvmConfig { } } -#[derive(Debug, Clone, Serialize, Deserialize)] -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)] -pub(crate) enum EvmBlock { - Reth115(SealedBlock), -} /// Custom EVM configuration. #[derive(Debug, Clone, Default)] @@ -215,16 +204,6 @@ pub struct HyperliquidEvmFactory { shared_state: Option, } -pub(crate) fn collect_s3_block(ingest_path: PathBuf, height: u64) -> Option { - let f = ((height - 1) / 1_000_000) * 1_000_000; - let s = ((height - 1) / 1_000) * 1_000; - let path = format!("{}/{f}/{s}/{height}.rmp.lz4", ingest_path.to_string_lossy()); - let file = std::fs::read(path).ok()?; - let mut decoder = lz4_flex::frame::FrameDecoder::new(&file[..]); - let blocks: Vec = rmp_serde::from_read(&mut decoder).unwrap(); - Some(blocks[0].clone()) -} - pub(crate) fn get_locally_sourced_precompiles_for_height( precompiles_cache: PrecompilesCache, height: u64, @@ -233,27 +212,6 @@ pub(crate) fn get_locally_sourced_precompiles_for_height( u_cache.remove(&height) } -pub(crate) fn collect_block( - ingest_path: PathBuf, - shared_state: Option, - height: u64, -) -> Option { - // Attempt to source precompile from the cache that is shared the binary level with the block - // ingestor. - if let Some(shared_state) = shared_state { - if let Some(calls) = - get_locally_sourced_precompiles_for_height(shared_state.precompiles_cache, height) - { - 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 { diff --git a/crates/hyperliquid-types/src/lib.rs b/crates/hyperliquid-types/src/lib.rs index b7c16cbea..e984da2fa 100644 --- a/crates/hyperliquid-types/src/lib.rs +++ b/crates/hyperliquid-types/src/lib.rs @@ -18,6 +18,27 @@ pub enum ReadPrecompileResult { UnexpectedError, } +/// ReadPrecompileCalls represents a collection of precompile calls with their results +#[derive(Debug, Clone, Serialize, Deserialize, Default)] +pub struct ReadPrecompileCalls(pub Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>); + +impl ReadPrecompileCalls { + /// Create an empty ReadPrecompileCalls + pub fn new() -> Self { + Self(Vec::new()) + } + + /// Create from a vector of precompile calls + pub fn from_vec(calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>) -> Self { + Self(calls) + } + + /// Get the inner vector + pub fn into_inner(self) -> Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)> { + self.0 + } +} + #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PrecompileData { pub precompiles: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>,