chore: Simplify traits

This commit is contained in:
sprites0
2025-08-21 06:10:49 -04:00
parent 4be1aa83de
commit 2712cbb413
8 changed files with 27 additions and 363 deletions

View File

@ -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<WIRE: InterpreterTypes, H: Host + ?Sized>
}
*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 {

View File

@ -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

View File

@ -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<T: Transaction> {
pub base: T,
@ -25,12 +25,6 @@ impl<T: Transaction> HlTxEnv<T> {
}
}
impl Default for HlTxEnv<TxEnv> {
fn default() -> Self {
Self { base: TxEnv::default() }
}
}
impl<T: Transaction> Transaction for HlTxEnv<T> {
type AccessListItem<'a>
= T::AccessListItem<'a>

View File

@ -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()
}))
}
}

View File

@ -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<HlContext<DB>>,
P: PrecompileProvider<HlContext<DB>, Output = InterpreterResult>,
<DB as revm::Database>::Error: std::marker::Send + std::marker::Sync + 'static,
{
type DB = DB;
type Tx = HlTxEnv<TxEnv>;
@ -127,10 +126,6 @@ where
))
}
fn db_mut(&mut self) -> &mut Self::DB {
&mut self.journaled_state.database
}
fn finish(self) -> (Self::DB, EvmEnv<Self::Spec>) {
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,

View File

@ -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<Node> PoolBuilder<Node> for HlPoolBuilder
where
Node: FullNodeTypes<Types = HlNode>,
{
type Pool = HlTransactionPool;
type Pool = NoopTransactionPool<HlPooledTransaction>;
async fn build_pool(
self,
_ctx: &reth::builder::BuilderContext<Node>,
) -> eyre::Result<Self::Pool> {
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<Self::Consensus>,
) -> Result<Self, Self::TryFromConsensusError> {
unreachable!()
}
fn clone_into_consensus(&self) -> Recovered<Self::Consensus> {
unreachable!()
}
fn into_consensus(self) -> Recovered<Self::Consensus> {
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<TransactionEvents> {
unreachable!()
}
async fn add_transaction(
&self,
_origin: TransactionOrigin,
_transaction: Self::Transaction,
) -> PoolResult<AddedTransactionOutcome> {
Ok(AddedTransactionOutcome {
hash: TxHash::default(),
state: AddedTransactionState::Pending,
})
}
async fn add_transactions(
&self,
_origin: TransactionOrigin,
_transactions: Vec<Self::Transaction>,
) -> Vec<PoolResult<AddedTransactionOutcome>> {
vec![]
}
fn transaction_event_listener(&self, _tx_hash: TxHash) -> Option<TransactionEvents> {
None
}
fn all_transactions_event_listener(&self) -> AllTransactionsEvents<Self::Transaction> {
unreachable!()
}
fn pending_transactions_listener_for(
&self,
_kind: TransactionListenerKind,
) -> Receiver<TxHash> {
mpsc::channel(1).1
}
fn blob_transaction_sidecars_listener(&self) -> Receiver<NewBlobSidecar> {
mpsc::channel(1).1
}
fn new_transactions_listener_for(
&self,
_kind: TransactionListenerKind,
) -> Receiver<NewTransactionEvent<Self::Transaction>> {
mpsc::channel(1).1
}
fn pooled_transaction_hashes(&self) -> Vec<TxHash> {
vec![]
}
fn pooled_transaction_hashes_max(&self, _max: usize) -> Vec<TxHash> {
vec![]
}
fn pooled_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn pooled_transactions_max(
&self,
_max: usize,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn get_pooled_transaction_elements(
&self,
_tx_hashes: Vec<TxHash>,
_limit: GetPooledTransactionLimit,
) -> Vec<<Self::Transaction as PoolTransaction>::Pooled> {
vec![]
}
fn get_pooled_transaction_element(
&self,
_tx_hash: TxHash,
) -> Option<Recovered<<Self::Transaction as PoolTransaction>::Pooled>> {
None
}
fn best_transactions(
&self,
) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {
Box::new(std::iter::empty())
}
fn best_transactions_with_attributes(
&self,
_best_transactions_attributes: BestTransactionsAttributes,
) -> Box<dyn BestTransactions<Item = Arc<ValidPoolTransaction<Self::Transaction>>>> {
Box::new(std::iter::empty())
}
fn pending_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn pending_transactions_max(
&self,
_max: usize,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn queued_transactions(&self) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn all_transactions(&self) -> AllPoolTransactions<Self::Transaction> {
AllPoolTransactions::default()
}
fn remove_transactions(
&self,
_hashes: Vec<TxHash>,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn remove_transactions_and_descendants(
&self,
_hashes: Vec<TxHash>,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn remove_transactions_by_sender(
&self,
_sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn retain_unknown<A>(&self, _announcement: &mut A)
where
A: HandleMempoolData,
{
// do nothing
}
fn get(&self, _tx_hash: &TxHash) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
None
}
fn get_all(&self, _txs: Vec<TxHash>) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn on_propagated(&self, _txs: PropagatedTransactions) {
// do nothing
}
fn get_transactions_by_sender(
&self,
_sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn get_pending_transactions_with_predicate(
&self,
_predicate: impl FnMut(&ValidPoolTransaction<Self::Transaction>) -> bool,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn get_pending_transactions_by_sender(
&self,
_sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}
fn get_queued_transactions_by_sender(
&self,
_sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
unreachable!()
}
fn get_highest_transaction_by_sender(
&self,
_sender: Address,
) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
None
}
fn get_highest_consecutive_transaction_by_sender(
&self,
_sender: Address,
_on_chain_nonce: u64,
) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
None
}
fn get_transaction_by_sender_and_nonce(
&self,
_sender: Address,
_nonce: u64,
) -> Option<Arc<ValidPoolTransaction<Self::Transaction>>> {
None
}
fn get_transactions_by_origin(
&self,
_origin: TransactionOrigin,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
unreachable!()
}
fn get_pending_transactions_by_origin(
&self,
_origin: TransactionOrigin,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
unreachable!()
}
fn unique_senders(&self) -> HashSet<Address> {
unreachable!()
}
fn get_blob(
&self,
_tx_hash: TxHash,
) -> Result<Option<Arc<BlobTransactionSidecarVariant>>, BlobStoreError> {
unreachable!()
}
fn get_all_blobs(
&self,
_tx_hashes: Vec<TxHash>,
) -> Result<Vec<(TxHash, Arc<BlobTransactionSidecarVariant>)>, BlobStoreError> {
unreachable!()
}
fn get_all_blobs_exact(
&self,
_tx_hashes: Vec<TxHash>,
) -> Result<Vec<Arc<BlobTransactionSidecarVariant>>, BlobStoreError> {
unreachable!()
}
fn get_blobs_for_versioned_hashes_v1(
&self,
_versioned_hashes: &[B256],
) -> Result<Vec<Option<BlobAndProofV1>>, BlobStoreError> {
unreachable!()
}
fn get_blobs_for_versioned_hashes_v2(
&self,
_versioned_hashes: &[B256],
) -> Result<Option<Vec<BlobAndProofV2>>, BlobStoreError> {
unreachable!()
}
async fn add_transactions_with_origins(
&self,
_transactions: Vec<(TransactionOrigin, Self::Transaction)>,
) -> Vec<PoolResult<AddedTransactionOutcome>> {
unreachable!()
}
fn pending_and_queued_txn_count(&self) -> (usize, usize) {
unreachable!()
}
fn all_transaction_hashes(&self) -> Vec<TxHash> {
unreachable!()
}
}

View File

@ -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<N, Rpc> EthBlocks for HlEthApi<N, Rpc>
@ -17,7 +15,6 @@ where
EthApiError: FromEvmError<N::Evm>,
Rpc: RpcConvert<Primitives = N::Primitives, Error = EthApiError>,
{
}
impl<N, Rpc> LoadBlock for HlEthApi<N, Rpc>

View File

@ -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<N: RpcNodeCore, Rpc: RpcConvert> {
/// Gateway to node's core components.
pub(crate) eth_api: EthApiInner<N, Rpc>,
@ -242,18 +239,10 @@ impl<NetworkT> Default for HlEthApiBuilder<NetworkT> {
impl<N, NetworkT> EthApiBuilder<N> for HlEthApiBuilder<NetworkT>
where
N: FullNodeComponents<
Types: NodeTypes<ChainSpec: EthereumHardforks>,
Evm: ConfigureEvm<
NextBlockEnvCtx: BuildPendingEnv<HeaderTy<N::Types>>,
Primitives: NodePrimitives,
>,
> + RpcNodeCore<Primitives = PrimitivesTy<N::Types>>
+ FullNodeTypes<
Types: NodeTypes<
Primitives: NodePrimitives<Receipt = Receipt>,
ChainSpec = HlChainSpec,
>,
N: FullNodeComponents<Types: NodeTypes<ChainSpec = HlChainSpec>>
+ RpcNodeCore<
Primitives = PrimitivesTy<N::Types>,
Evm: ConfigureEvm<NextBlockEnvCtx: BuildPendingEnv<HeaderTy<N::Types>>>,
>,
NetworkT: RpcTypes,
HlRpcConvert<N, NetworkT>: RpcConvert<Network = NetworkT, Primitives = PrimitivesTy<N::Types>>,
@ -261,7 +250,6 @@ where
Provider = <N as FullNodeTypes>::Provider,
Pool = <N as FullNodeComponents>::Pool,
> + AddDevSigners,
<<N as RpcNodeCore>::Evm as ConfigureEvm>::NextBlockEnvCtx: BuildPendingEnv<HeaderTy<N::Types>>,
{
type EthApi = HlEthApi<N, HlRpcConvert<N, NetworkT>>;