From 2712cbb413817335112396992817317d1747f432 Mon Sep 17 00:00:00 2001 From: sprites0 <199826320+sprites0@users.noreply.github.com> Date: Thu, 21 Aug 2025 06:10:49 -0400 Subject: [PATCH] chore: Simplify traits --- src/evm/api/patch.rs | 6 +- src/evm/spec.rs | 2 - src/evm/transaction.rs | 8 +- src/hl_node_compliance.rs | 13 +- src/node/evm/mod.rs | 25 +--- src/node/pool.rs | 301 +------------------------------------- src/node/rpc/block.rs | 11 +- src/node/rpc/mod.rs | 24 +-- 8 files changed, 27 insertions(+), 363 deletions(-) diff --git a/src/evm/api/patch.rs b/src/evm/api/patch.rs index c7cd1ee68..0fce3045f 100644 --- a/src/evm/api/patch.rs +++ b/src/evm/api/patch.rs @@ -22,7 +22,8 @@ macro_rules! _count { ($($arg:tt)*) => { _count!(@count $($arg)*) }; } -/// Pops n values from the stack and returns the top value. Fails the instruction if n values can't be popped. +/// Pops n values from the stack and returns the top value. Fails the instruction if n values can't +/// be popped. #[macro_export] #[collapse_debuginfo(yes)] macro_rules! popn_top { @@ -62,7 +63,8 @@ pub fn blockhash_returning_placeholder } *number = if diff <= BLOCK_HASH_HISTORY { - // NOTE: This is HL-specific modifcation that returns the placeholder hash before specific block. + // NOTE: This is HL-specific modifcation that returns the placeholder hash before specific + // block. let hash = keccak256(as_u64_saturated!(requested_number).to_string().as_bytes()); U256::from_be_bytes(hash.0) } else { diff --git a/src/evm/spec.rs b/src/evm/spec.rs index 6d3e06646..8edd9e985 100644 --- a/src/evm/spec.rs +++ b/src/evm/spec.rs @@ -4,8 +4,6 @@ use std::str::FromStr; #[repr(u8)] #[derive(Clone, Copy, Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Default)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -#[allow(non_camel_case_types)] -#[allow(clippy::upper_case_acronyms)] pub enum HlSpecId { #[default] V1, // V1 diff --git a/src/evm/transaction.rs b/src/evm/transaction.rs index 8f1dc6702..db82f5a21 100644 --- a/src/evm/transaction.rs +++ b/src/evm/transaction.rs @@ -13,7 +13,7 @@ use revm::{ #[auto_impl(&, &mut, Box, Arc)] pub trait HlTxTr: Transaction {} -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] pub struct HlTxEnv { pub base: T, @@ -25,12 +25,6 @@ impl HlTxEnv { } } -impl Default for HlTxEnv { - fn default() -> Self { - Self { base: TxEnv::default() } - } -} - impl Transaction for HlTxEnv { type AccessListItem<'a> = T::AccessListItem<'a> diff --git a/src/hl_node_compliance.rs b/src/hl_node_compliance.rs index 7a56c8910..3cb91b7de 100644 --- a/src/hl_node_compliance.rs +++ b/src/hl_node_compliance.rs @@ -1,7 +1,7 @@ use alloy_consensus::TxReceipt; -use alloy_network::ReceiptResponse; use alloy_eips::{BlockId, BlockNumberOrTag}; use alloy_json_rpc::RpcObject; +use alloy_network::ReceiptResponse; use alloy_primitives::{B256, U256}; use alloy_rpc_types::{ pubsub::{Params, SubscriptionKind}, @@ -379,8 +379,8 @@ where let res = self.eth_api.block_transaction_count_by_hash(hash).instrument(engine_span!()).await?; Ok(res.map(|count| { - count - - U256::from(system_tx_count_for_block(&*self.eth_api, BlockId::Hash(hash.into()))) + count - + U256::from(system_tx_count_for_block(&*self.eth_api, BlockId::Hash(hash.into()))) })) } @@ -408,12 +408,7 @@ where trace!(target: "rpc::eth", ?block_id, "Serving eth_getBlockReceipts"); let res = self.eth_api.block_receipts(block_id).instrument(engine_span!()).await?; Ok(res.map(|receipts| { - receipts - .into_iter() - .filter(|receipt| { - receipt.cumulative_gas_used() > 0 - }) - .collect() + receipts.into_iter().filter(|receipt| receipt.cumulative_gas_used() > 0).collect() })) } } diff --git a/src/node/evm/mod.rs b/src/node/evm/mod.rs index 232e35350..bad92e601 100644 --- a/src/node/evm/mod.rs +++ b/src/node/evm/mod.rs @@ -12,7 +12,7 @@ use reth::{ api::FullNodeTypes, builder::{components::ExecutorBuilder, BuilderContext}, }; -use reth_evm::{Evm, EvmEnv}; +use reth_evm::{Database, Evm, EvmEnv}; use revm::{ context::{ result::{EVMError, ExecutionResult, HaltReason, Output, ResultAndState, SuccessReason}, @@ -21,7 +21,7 @@ use revm::{ handler::{instructions::EthInstructions, EthPrecompiles, PrecompileProvider}, interpreter::{interpreter::EthInterpreter, InterpreterResult}, state::EvmState, - Context, Database, ExecuteEvm, InspectEvm, Inspector, + Context, ExecuteEvm, InspectEvm, Inspector, }; use std::ops::{Deref, DerefMut}; @@ -75,7 +75,6 @@ where DB: Database, I: Inspector>, P: PrecompileProvider, Output = InterpreterResult>, - ::Error: std::marker::Send + std::marker::Sync + 'static, { type DB = DB; type Tx = HlTxEnv; @@ -127,10 +126,6 @@ where )) } - fn db_mut(&mut self) -> &mut Self::DB { - &mut self.journaled_state.database - } - fn finish(self) -> (Self::DB, EvmEnv) { let Context { block: block_env, cfg: cfg_env, journaled_state, .. } = self.inner.0.ctx; @@ -141,22 +136,6 @@ where self.inspect = enabled; } - fn precompiles_mut(&mut self) -> &mut Self::Precompiles { - &mut self.inner.0.precompiles - } - - fn inspector_mut(&mut self) -> &mut Self::Inspector { - &mut self.inner.0.inspector - } - - fn precompiles(&self) -> &Self::Precompiles { - &self.inner.0.precompiles - } - - fn inspector(&self) -> &Self::Inspector { - &self.inner.0.inspector - } - fn components(&self) -> (&Self::DB, &Self::Inspector, &Self::Precompiles) { ( &self.inner.0.ctx.journaled_state.database, diff --git a/src/node/pool.rs b/src/node/pool.rs index 0a75b60ef..7fc087fc8 100644 --- a/src/node/pool.rs +++ b/src/node/pool.rs @@ -10,44 +10,30 @@ use crate::node::{primitives::TransactionSigned, HlNode}; use alloy_consensus::{ error::ValueError, EthereumTxEnvelope, Transaction as TransactionTrait, TxEip4844, }; -use alloy_eips::{ - eip4844::BlobAndProofV2, eip7594::BlobTransactionSidecarVariant, eip7702::SignedAuthorization, - Typed2718, -}; +use alloy_eips::{eip7702::SignedAuthorization, Typed2718}; use alloy_primitives::{Address, Bytes, ChainId, TxHash, TxKind, B256, U256}; use alloy_rpc_types::AccessList; -use alloy_rpc_types_engine::BlobAndProofV1; use reth::{ - api::FullNodeTypes, - builder::components::PoolBuilder, - transaction_pool::{PoolResult, PoolSize, PoolTransaction, TransactionOrigin, TransactionPool}, + api::FullNodeTypes, builder::components::PoolBuilder, transaction_pool::PoolTransaction, }; -use reth_eth_wire::HandleMempoolData; use reth_ethereum_primitives::PooledTransactionVariant; use reth_primitives::Recovered; use reth_primitives_traits::InMemorySize; -use reth_transaction_pool::{ - error::InvalidPoolTransactionError, pool::AddedTransactionState, AddedTransactionOutcome, - AllPoolTransactions, AllTransactionsEvents, BestTransactions, BestTransactionsAttributes, - BlobStoreError, BlockInfo, EthPoolTransaction, GetPooledTransactionLimit, NewBlobSidecar, - NewTransactionEvent, PropagatedTransactions, TransactionEvents, TransactionListenerKind, - ValidPoolTransaction, -}; -use std::{collections::HashSet, sync::Arc}; -use tokio::sync::mpsc::{self, Receiver}; +use reth_transaction_pool::{noop::NoopTransactionPool, EthPoolTransaction}; +use std::sync::Arc; pub struct HlPoolBuilder; impl PoolBuilder for HlPoolBuilder where Node: FullNodeTypes, { - type Pool = HlTransactionPool; + type Pool = NoopTransactionPool; async fn build_pool( self, _ctx: &reth::builder::BuilderContext, ) -> eyre::Result { - Ok(HlTransactionPool) + Ok(NoopTransactionPool::new()) } } @@ -125,16 +111,6 @@ impl PoolTransaction for HlPooledTransaction { type Consensus = TransactionSigned; type Pooled = PooledTransactionVariant; - fn try_from_consensus( - _tx: Recovered, - ) -> Result { - unreachable!() - } - - fn clone_into_consensus(&self) -> Recovered { - unreachable!() - } - fn into_consensus(self) -> Recovered { unreachable!() } @@ -162,13 +138,6 @@ impl PoolTransaction for HlPooledTransaction { fn encoded_length(&self) -> usize { 0 } - - fn ensure_max_init_code_size( - &self, - _max_init_code_size: usize, - ) -> Result<(), InvalidPoolTransactionError> { - Ok(()) - } } impl EthPoolTransaction for HlPooledTransaction { @@ -198,261 +167,3 @@ impl EthPoolTransaction for HlPooledTransaction { Ok(()) } } - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub struct HlTransactionPool; -impl TransactionPool for HlTransactionPool { - type Transaction = HlPooledTransaction; - - fn pool_size(&self) -> PoolSize { - PoolSize::default() - } - - fn block_info(&self) -> BlockInfo { - BlockInfo::default() - } - - async fn add_transaction_and_subscribe( - &self, - _origin: TransactionOrigin, - _transaction: Self::Transaction, - ) -> PoolResult { - unreachable!() - } - - async fn add_transaction( - &self, - _origin: TransactionOrigin, - _transaction: Self::Transaction, - ) -> PoolResult { - Ok(AddedTransactionOutcome { - hash: TxHash::default(), - state: AddedTransactionState::Pending, - }) - } - - async fn add_transactions( - &self, - _origin: TransactionOrigin, - _transactions: Vec, - ) -> Vec> { - vec![] - } - - fn transaction_event_listener(&self, _tx_hash: TxHash) -> Option { - None - } - - fn all_transactions_event_listener(&self) -> AllTransactionsEvents { - unreachable!() - } - - fn pending_transactions_listener_for( - &self, - _kind: TransactionListenerKind, - ) -> Receiver { - mpsc::channel(1).1 - } - - fn blob_transaction_sidecars_listener(&self) -> Receiver { - mpsc::channel(1).1 - } - - fn new_transactions_listener_for( - &self, - _kind: TransactionListenerKind, - ) -> Receiver> { - mpsc::channel(1).1 - } - fn pooled_transaction_hashes(&self) -> Vec { - vec![] - } - fn pooled_transaction_hashes_max(&self, _max: usize) -> Vec { - vec![] - } - fn pooled_transactions(&self) -> Vec>> { - vec![] - } - fn pooled_transactions_max( - &self, - _max: usize, - ) -> Vec>> { - vec![] - } - fn get_pooled_transaction_elements( - &self, - _tx_hashes: Vec, - _limit: GetPooledTransactionLimit, - ) -> Vec<::Pooled> { - vec![] - } - fn get_pooled_transaction_element( - &self, - _tx_hash: TxHash, - ) -> Option::Pooled>> { - None - } - fn best_transactions( - &self, - ) -> Box>>> { - Box::new(std::iter::empty()) - } - fn best_transactions_with_attributes( - &self, - _best_transactions_attributes: BestTransactionsAttributes, - ) -> Box>>> { - Box::new(std::iter::empty()) - } - fn pending_transactions(&self) -> Vec>> { - vec![] - } - fn pending_transactions_max( - &self, - _max: usize, - ) -> Vec>> { - vec![] - } - fn queued_transactions(&self) -> Vec>> { - vec![] - } - fn all_transactions(&self) -> AllPoolTransactions { - AllPoolTransactions::default() - } - fn remove_transactions( - &self, - _hashes: Vec, - ) -> Vec>> { - vec![] - } - fn remove_transactions_and_descendants( - &self, - _hashes: Vec, - ) -> Vec>> { - vec![] - } - fn remove_transactions_by_sender( - &self, - _sender: Address, - ) -> Vec>> { - vec![] - } - fn retain_unknown(&self, _announcement: &mut A) - where - A: HandleMempoolData, - { - // do nothing - } - fn get(&self, _tx_hash: &TxHash) -> Option>> { - None - } - fn get_all(&self, _txs: Vec) -> Vec>> { - vec![] - } - fn on_propagated(&self, _txs: PropagatedTransactions) { - // do nothing - } - fn get_transactions_by_sender( - &self, - _sender: Address, - ) -> Vec>> { - vec![] - } - fn get_pending_transactions_with_predicate( - &self, - _predicate: impl FnMut(&ValidPoolTransaction) -> bool, - ) -> Vec>> { - vec![] - } - fn get_pending_transactions_by_sender( - &self, - _sender: Address, - ) -> Vec>> { - vec![] - } - fn get_queued_transactions_by_sender( - &self, - _sender: Address, - ) -> Vec>> { - unreachable!() - } - fn get_highest_transaction_by_sender( - &self, - _sender: Address, - ) -> Option>> { - None - } - fn get_highest_consecutive_transaction_by_sender( - &self, - _sender: Address, - _on_chain_nonce: u64, - ) -> Option>> { - None - } - fn get_transaction_by_sender_and_nonce( - &self, - _sender: Address, - _nonce: u64, - ) -> Option>> { - None - } - fn get_transactions_by_origin( - &self, - _origin: TransactionOrigin, - ) -> Vec>> { - unreachable!() - } - fn get_pending_transactions_by_origin( - &self, - _origin: TransactionOrigin, - ) -> Vec>> { - unreachable!() - } - fn unique_senders(&self) -> HashSet
{ - unreachable!() - } - fn get_blob( - &self, - _tx_hash: TxHash, - ) -> Result>, BlobStoreError> { - unreachable!() - } - fn get_all_blobs( - &self, - _tx_hashes: Vec, - ) -> Result)>, BlobStoreError> { - unreachable!() - } - fn get_all_blobs_exact( - &self, - _tx_hashes: Vec, - ) -> Result>, BlobStoreError> { - unreachable!() - } - fn get_blobs_for_versioned_hashes_v1( - &self, - _versioned_hashes: &[B256], - ) -> Result>, BlobStoreError> { - unreachable!() - } - fn get_blobs_for_versioned_hashes_v2( - &self, - _versioned_hashes: &[B256], - ) -> Result>, BlobStoreError> { - unreachable!() - } - - async fn add_transactions_with_origins( - &self, - _transactions: Vec<(TransactionOrigin, Self::Transaction)>, - ) -> Vec> { - unreachable!() - } - - fn pending_and_queued_txn_count(&self) -> (usize, usize) { - unreachable!() - } - - fn all_transaction_hashes(&self) -> Vec { - unreachable!() - } -} diff --git a/src/node/rpc/block.rs b/src/node/rpc/block.rs index fe3b017ed..c9a70c83c 100644 --- a/src/node/rpc/block.rs +++ b/src/node/rpc/block.rs @@ -1,14 +1,12 @@ - use crate::node::rpc::HlEthApi; -use reth::{ - rpc::server_types::eth::{ - builder::config::PendingBlockKind, error::FromEvmError, EthApiError, PendingBlock, - }, +use reth::rpc::server_types::eth::{ + builder::config::PendingBlockKind, error::FromEvmError, EthApiError, PendingBlock, }; use reth_rpc_eth_api::{ helpers::{ pending_block::PendingEnvBuilder, EthBlocks, LoadBlock, LoadPendingBlock, LoadReceipt, - }, RpcConvert, RpcNodeCore + }, + RpcConvert, RpcNodeCore, }; impl EthBlocks for HlEthApi @@ -17,7 +15,6 @@ where EthApiError: FromEvmError, Rpc: RpcConvert, { - } impl LoadBlock for HlEthApi diff --git a/src/node/rpc/mod.rs b/src/node/rpc/mod.rs index e87a15066..ce55a65c7 100644 --- a/src/node/rpc/mod.rs +++ b/src/node/rpc/mod.rs @@ -6,12 +6,11 @@ use reth::{ rpc::{EthApiBuilder, EthApiCtx}, FullNodeComponents, }, - primitives::EthereumHardforks, rpc::{ eth::{core::EthApiInner, DevSigner, FullEthApiServer}, server_types::eth::{ - receipt::EthReceiptConverter, - EthApiError, EthStateCache, FeeHistoryCache, GasPriceOracle, + receipt::EthReceiptConverter, EthApiError, EthStateCache, FeeHistoryCache, + GasPriceOracle, }, }, tasks::{ @@ -20,7 +19,6 @@ use reth::{ }, }; use reth_evm::ConfigureEvm; -use reth_primitives::{NodePrimitives, Receipt}; use reth_provider::{ChainSpecProvider, ProviderHeader, ProviderTx}; use reth_rpc::RpcTypes; use reth_rpc_eth_api::{ @@ -41,7 +39,6 @@ pub mod engine_api; mod transaction; /// Container type `HlEthApi` -#[allow(missing_debug_implementations)] pub(crate) struct HlEthApiInner { /// Gateway to node's core components. pub(crate) eth_api: EthApiInner, @@ -242,18 +239,10 @@ impl Default for HlEthApiBuilder { impl EthApiBuilder for HlEthApiBuilder where - N: FullNodeComponents< - Types: NodeTypes, - Evm: ConfigureEvm< - NextBlockEnvCtx: BuildPendingEnv>, - Primitives: NodePrimitives, - >, - > + RpcNodeCore> - + FullNodeTypes< - Types: NodeTypes< - Primitives: NodePrimitives, - ChainSpec = HlChainSpec, - >, + N: FullNodeComponents> + + RpcNodeCore< + Primitives = PrimitivesTy, + Evm: ConfigureEvm>>, >, NetworkT: RpcTypes, HlRpcConvert: RpcConvert>, @@ -261,7 +250,6 @@ where Provider = ::Provider, Pool = ::Pool, > + AddDevSigners, - <::Evm as ConfigureEvm>::NextBlockEnvCtx: BuildPendingEnv>, { type EthApi = HlEthApi>;