mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Merge pull request #21 from hl-archive-node/feat/highest-precompile-addresses
feat: highest precompile addresses
This commit is contained in:
@ -12,7 +12,7 @@ use alloy_rpc_types::engine::{
|
|||||||
use jsonrpsee::http_client::{transport::HttpBackend, HttpClient};
|
use jsonrpsee::http_client::{transport::HttpBackend, HttpClient};
|
||||||
use reth::network::PeersHandleProvider;
|
use reth::network::PeersHandleProvider;
|
||||||
use reth_chainspec::{EthChainSpec, EthereumHardforks};
|
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_api::{Block, FullNodeComponents, PayloadTypes};
|
||||||
use reth_node_builder::EngineTypes;
|
use reth_node_builder::EngineTypes;
|
||||||
use reth_node_builder::NodeTypesWithEngine;
|
use reth_node_builder::NodeTypesWithEngine;
|
||||||
@ -191,7 +191,10 @@ impl BlockIngest {
|
|||||||
let mut u_cache = cache.lock().await;
|
let mut u_cache = cache.lock().await;
|
||||||
let mut u_pre_cache = precompiles_cache.lock();
|
let mut u_pre_cache = precompiles_cache.lock();
|
||||||
for blk in new_blocks {
|
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 {
|
let h = match &blk.block {
|
||||||
EvmBlock::Reth115(b) => {
|
EvmBlock::Reth115(b) => {
|
||||||
let block_number = b.header().number() as u64;
|
let block_number = b.header().number() as u64;
|
||||||
|
|||||||
@ -9,7 +9,7 @@ mod serialized;
|
|||||||
mod spot_meta;
|
mod spot_meta;
|
||||||
mod tx_forwarder;
|
mod tx_forwarder;
|
||||||
|
|
||||||
use std::{collections::BTreeMap, path::PathBuf, sync::Arc};
|
use std::{collections::BTreeMap, sync::Arc};
|
||||||
|
|
||||||
use block_ingest::BlockIngest;
|
use block_ingest::BlockIngest;
|
||||||
use call_forwarder::CallForwarderApiServer;
|
use call_forwarder::CallForwarderApiServer;
|
||||||
|
|||||||
@ -11,6 +11,7 @@ pub(crate) struct BlockAndReceipts {
|
|||||||
pub system_txs: Vec<SystemTx>,
|
pub system_txs: Vec<SystemTx>,
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>,
|
pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>,
|
||||||
|
pub highest_precompile_address: Option<Address>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
|||||||
@ -27,12 +27,6 @@ use reth_primitives_traits::{transaction::signed::is_impersonated_tx, NodePrimit
|
|||||||
use reth_revm::{
|
use reth_revm::{
|
||||||
context_interface::result::ResultAndState, db::State, state::Bytecode, DatabaseCommit,
|
context_interface::result::ResultAndState, db::State, state::Bytecode, DatabaseCommit,
|
||||||
};
|
};
|
||||||
use std::{
|
|
||||||
cell::RefCell,
|
|
||||||
sync::Mutex,
|
|
||||||
time::{Duration, Instant},
|
|
||||||
};
|
|
||||||
use tracing::info;
|
|
||||||
|
|
||||||
/// Factory for [`EthExecutionStrategy`].
|
/// Factory for [`EthExecutionStrategy`].
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|||||||
@ -21,14 +21,13 @@ use alloc::sync::Arc;
|
|||||||
use alloy_consensus::{BlockHeader, Header};
|
use alloy_consensus::{BlockHeader, Header};
|
||||||
use alloy_evm::eth::EthEvmContext;
|
use alloy_evm::eth::EthEvmContext;
|
||||||
pub use alloy_evm::EthEvm;
|
pub use alloy_evm::EthEvm;
|
||||||
use alloy_primitives::Address;
|
use alloy_primitives::{address, Address, U160, U256};
|
||||||
use alloy_primitives::U160;
|
|
||||||
use alloy_primitives::U256;
|
|
||||||
use core::{convert::Infallible, fmt::Debug};
|
use core::{convert::Infallible, fmt::Debug};
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET};
|
use reth_chainspec::{ChainSpec, EthChainSpec, MAINNET};
|
||||||
use reth_evm::Database;
|
use reth_evm::Database;
|
||||||
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, EvmFactory, NextBlockEnvAttributes};
|
use reth_evm::{ConfigureEvm, ConfigureEvmEnv, EvmEnv, EvmFactory, NextBlockEnvAttributes};
|
||||||
|
use reth_hyperliquid_types::PrecompileData;
|
||||||
use reth_hyperliquid_types::{PrecompilesCache, ReadPrecompileInput, ReadPrecompileResult};
|
use reth_hyperliquid_types::{PrecompilesCache, ReadPrecompileInput, ReadPrecompileResult};
|
||||||
use reth_node_builder::HyperliquidSharedState;
|
use reth_node_builder::HyperliquidSharedState;
|
||||||
use reth_primitives::SealedBlock;
|
use reth_primitives::SealedBlock;
|
||||||
@ -200,6 +199,7 @@ impl ConfigureEvmEnv for EthEvmConfig {
|
|||||||
pub(crate) struct BlockAndReceipts {
|
pub(crate) struct BlockAndReceipts {
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>,
|
pub read_precompile_calls: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>,
|
||||||
|
pub highest_precompile_address: Option<Address>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
@ -228,7 +228,7 @@ pub(crate) fn collect_s3_block(ingest_path: PathBuf, height: u64) -> Option<Bloc
|
|||||||
pub(crate) fn get_locally_sourced_precompiles_for_height(
|
pub(crate) fn get_locally_sourced_precompiles_for_height(
|
||||||
precompiles_cache: PrecompilesCache,
|
precompiles_cache: PrecompilesCache,
|
||||||
height: u64,
|
height: u64,
|
||||||
) -> Option<Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>> {
|
) -> Option<PrecompileData> {
|
||||||
let mut u_cache = precompiles_cache.lock();
|
let mut u_cache = precompiles_cache.lock();
|
||||||
u_cache.remove(&height)
|
u_cache.remove(&height)
|
||||||
}
|
}
|
||||||
@ -244,13 +244,18 @@ pub(crate) fn collect_block(
|
|||||||
if let Some(calls) =
|
if let Some(calls) =
|
||||||
get_locally_sourced_precompiles_for_height(shared_state.precompiles_cache, height)
|
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
|
// Fallback to s3 always
|
||||||
collect_s3_block(ingest_path, height)
|
collect_s3_block(ingest_path, height)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const WARM_PRECOMPILES_BLOCK_NUMBER: u64 = 8_197_684;
|
||||||
|
|
||||||
impl EvmFactory<EvmEnv> for HyperliquidEvmFactory {
|
impl EvmFactory<EvmEnv> for HyperliquidEvmFactory {
|
||||||
type Evm<DB: Database, I: Inspector<EthEvmContext<DB>, EthInterpreter>> =
|
type Evm<DB: Database, I: Inspector<EthEvmContext<DB>, EthInterpreter>> =
|
||||||
EthEvm<DB, I, ReplayPrecompile<EthEvmContext<DB>>>;
|
EthEvm<DB, I, ReplayPrecompile<EthEvmContext<DB>>>;
|
||||||
@ -272,10 +277,16 @@ impl EvmFactory<EvmEnv> for HyperliquidEvmFactory {
|
|||||||
.map(|(address, calls)| (address, HashMap::from_iter(calls.into_iter())))
|
.map(|(address, calls)| (address, HashMap::from_iter(calls.into_iter())))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// NOTE: Hotfix but semantically correct. Will be removed once hl-node pipeline is updated (#17)
|
if input.block_env.number >= WARM_PRECOMPILES_BLOCK_NUMBER {
|
||||||
if input.block_env.number >= 7000000 {
|
let highest_precompile_address = block
|
||||||
for i in 0x800..=0x80D {
|
.highest_precompile_address
|
||||||
cache.entry(Address::from(U160::from(i))).or_insert(HashMap::new());
|
.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());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use reth_revm::{
|
|||||||
context::{Cfg, ContextTr},
|
context::{Cfg, ContextTr},
|
||||||
handler::{EthPrecompiles, PrecompileProvider},
|
handler::{EthPrecompiles, PrecompileProvider},
|
||||||
interpreter::{Gas, InstructionResult, InterpreterResult},
|
interpreter::{Gas, InstructionResult, InterpreterResult},
|
||||||
precompile::{PrecompileError, PrecompileErrors},
|
precompile::PrecompileErrors,
|
||||||
};
|
};
|
||||||
use std::{collections::HashMap, sync::Arc};
|
use std::{collections::HashMap, sync::Arc};
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ impl<CTX: ContextTr> PrecompileProvider for ReplayPrecompile<CTX> {
|
|||||||
let Some(get) = precompile_calls.get(&input) else {
|
let Some(get) = precompile_calls.get(&input) else {
|
||||||
result.gas.spend_all();
|
result.gas.spend_all();
|
||||||
result.result = InstructionResult::PrecompileError;
|
result.result = InstructionResult::PrecompileError;
|
||||||
return Ok(Some(result))
|
return Ok(Some(result));
|
||||||
};
|
};
|
||||||
|
|
||||||
return match *get {
|
return match *get {
|
||||||
|
|||||||
@ -18,5 +18,10 @@ pub enum ReadPrecompileResult {
|
|||||||
UnexpectedError,
|
UnexpectedError,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type PrecompilesCache =
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
Arc<Mutex<BTreeMap<u64, Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>>>>;
|
pub struct PrecompileData {
|
||||||
|
pub precompiles: Vec<(Address, Vec<(ReadPrecompileInput, ReadPrecompileResult)>)>,
|
||||||
|
pub highest_precompile_address: Option<Address>,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub type PrecompilesCache = Arc<Mutex<BTreeMap<u64, PrecompileData>>>;
|
||||||
|
|||||||
Reference in New Issue
Block a user