fix: replace tx_hash method with TxHashRef trait bound (#18357) (#18362)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
emmmm
2025-09-22 05:31:17 -04:00
committed by GitHub
parent 3ebfd7a25e
commit 9806e07cf8
28 changed files with 92 additions and 91 deletions

View File

@@ -4,14 +4,14 @@ use crate::common::{
AccessRights, CliComponentsBuilder, CliNodeComponents, CliNodeTypes, Environment,
EnvironmentArgs,
};
use alloy_consensus::{BlockHeader, TxReceipt};
use alloy_consensus::{transaction::TxHashRef, BlockHeader, TxReceipt};
use clap::Parser;
use eyre::WrapErr;
use reth_chainspec::{EthChainSpec, EthereumHardforks, Hardforks};
use reth_cli::chainspec::ChainSpecParser;
use reth_consensus::FullConsensus;
use reth_evm::{execute::Executor, ConfigureEvm};
use reth_primitives_traits::{format_gas_throughput, BlockBody, GotExpected, SignedTransaction};
use reth_primitives_traits::{format_gas_throughput, BlockBody, GotExpected};
use reth_provider::{
BlockNumReader, BlockReader, ChainSpecProvider, DatabaseProviderFactory, ReceiptProvider,
StaticFileProviderFactory, TransactionVariant,

View File

@@ -10,7 +10,8 @@ use reth_primitives_traits::{
constants::{
GAS_LIMIT_BOUND_DIVISOR, MAXIMUM_GAS_LIMIT_BLOCK, MAX_TX_GAS_LIMIT_OSAKA, MINIMUM_GAS_LIMIT,
},
Block, BlockBody, BlockHeader, GotExpected, SealedBlock, SealedHeader, SignedTransaction,
transaction::TxHashRef,
Block, BlockBody, BlockHeader, GotExpected, SealedBlock, SealedHeader,
};
/// The maximum RLP length of a block, defined in [EIP-7934](https://eips.ethereum.org/EIPS/eip-7934).

View File

@@ -1,5 +1,5 @@
use crate::{network::NetworkTestContext, payload::PayloadTestContext, rpc::RpcTestContext};
use alloy_consensus::BlockHeader;
use alloy_consensus::{transaction::TxHashRef, BlockHeader};
use alloy_eips::BlockId;
use alloy_primitives::{BlockHash, BlockNumber, Bytes, Sealable, B256};
use alloy_rpc_types_engine::ForkchoiceState;
@@ -14,7 +14,7 @@ use reth_node_api::{
PrimitivesTy,
};
use reth_node_builder::{rpc::RethRpcAddOns, FullNode, NodeTypes};
use reth_node_core::primitives::SignedTransaction;
use reth_payload_primitives::{BuiltPayload, PayloadBuilderAttributes};
use reth_provider::{
BlockReader, BlockReaderIdExt, CanonStateNotificationStream, CanonStateSubscriptions,

View File

@@ -1,4 +1,5 @@
use crate::tree::MeteredStateHook;
use alloy_consensus::transaction::TxHashRef;
use alloy_evm::{
block::{BlockExecutor, ExecutableTx},
Evm,

View File

@@ -20,12 +20,13 @@ use crate::tree::{
precompile_cache::{CachedPrecompile, PrecompileCacheMap},
ExecutionEnv, StateProviderBuilder,
};
use alloy_consensus::transaction::TxHashRef;
use alloy_evm::Database;
use alloy_primitives::{keccak256, map::B256Set, B256};
use metrics::{Counter, Gauge, Histogram};
use reth_evm::{execute::ExecutableTxFor, ConfigureEvm, Evm, EvmFor, SpecFor};
use reth_metrics::Metrics;
use reth_primitives_traits::{NodePrimitives, SignedTransaction};
use reth_primitives_traits::NodePrimitives;
use reth_provider::{BlockReader, StateProviderFactory, StateReader};
use reth_revm::{database::StateProviderDatabase, db::BundleState, state::EvmState};
use reth_trie::MultiProofTargets;

View File

@@ -3,7 +3,7 @@
use alloc::vec::Vec;
use alloy_consensus::{
transaction::{RlpEcdsaDecodableTx, RlpEcdsaEncodableTx, SignerRecoverable},
transaction::{RlpEcdsaDecodableTx, RlpEcdsaEncodableTx, SignerRecoverable, TxHashRef},
EthereumTxEnvelope, SignableTransaction, Signed, TxEip1559, TxEip2930, TxEip4844, TxEip7702,
TxLegacy, TxType, Typed2718,
};
@@ -658,12 +658,14 @@ impl SignerRecoverable for TransactionSigned {
}
}
impl SignedTransaction for TransactionSigned {
impl TxHashRef for TransactionSigned {
fn tx_hash(&self) -> &TxHash {
self.hash.get_or_init(|| self.recalculate_hash())
}
}
impl SignedTransaction for TransactionSigned {}
#[cfg(test)]
mod tests {
use super::*;

View File

@@ -801,7 +801,7 @@ pub struct BlockRangeUpdate {
#[cfg(test)]
mod tests {
use super::*;
use alloy_consensus::Typed2718;
use alloy_consensus::{transaction::TxHashRef, Typed2718};
use alloy_eips::eip2718::Encodable2718;
use alloy_primitives::{b256, hex, Signature, U256};
use reth_ethereum_primitives::{Transaction, TransactionSigned};

View File

@@ -1,5 +1,7 @@
//! Transactions management for the p2p network.
use alloy_consensus::transaction::TxHashRef;
/// Aggregation on configurable parameters for [`TransactionsManager`].
pub mod config;
/// Default and spec'd bounds.

View File

@@ -4,7 +4,7 @@
use crate::transaction::OpTransaction;
use alloc::vec::Vec;
use alloy_consensus::{
transaction::{RlpEcdsaDecodableTx, RlpEcdsaEncodableTx, SignerRecoverable},
transaction::{RlpEcdsaDecodableTx, RlpEcdsaEncodableTx, SignerRecoverable, TxHashRef},
Sealed, SignableTransaction, Signed, Transaction, TxEip1559, TxEip2930, TxEip7702, TxLegacy,
Typed2718,
};
@@ -142,11 +142,13 @@ impl SignerRecoverable for OpTransactionSigned {
}
}
impl SignedTransaction for OpTransactionSigned {
impl TxHashRef for OpTransactionSigned {
fn tx_hash(&self) -> &TxHash {
self.hash.get_or_init(|| self.recalculate_hash())
}
}
impl SignedTransaction for OpTransactionSigned {
fn recalculate_hash(&self) -> B256 {
keccak256(self.encoded_2718())
}

View File

@@ -5,7 +5,10 @@ use crate::{
MaybeSerdeBincodeCompat, SignedTransaction,
};
use alloc::{fmt, vec::Vec};
use alloy_consensus::{transaction::Recovered, Transaction, Typed2718};
use alloy_consensus::{
transaction::{Recovered, TxHashRef},
Transaction, Typed2718,
};
use alloy_eips::{eip2718::Encodable2718, eip4895::Withdrawals};
use alloy_primitives::{Address, Bytes, B256};

View File

@@ -659,7 +659,8 @@ mod rpc_compat {
use crate::{block::error::BlockRecoveryError, SealedHeader};
use alloc::vec::Vec;
use alloy_consensus::{
transaction::Recovered, Block as CBlock, BlockBody, BlockHeader, Sealable,
transaction::{Recovered, TxHashRef},
Block as CBlock, BlockBody, BlockHeader, Sealable,
};
use alloy_rpc_types_eth::{Block, BlockTransactions, BlockTransactionsKind, TransactionInfo};

View File

@@ -3,7 +3,10 @@ use crate::{
transaction::signed::{RecoveryError, SignedTransaction},
};
use alloc::vec::Vec;
use alloy_consensus::{transaction::SignerRecoverable, EthereumTxEnvelope, Transaction};
use alloy_consensus::{
transaction::{SignerRecoverable, TxHashRef},
EthereumTxEnvelope, Transaction,
};
use alloy_eips::{
eip2718::{Eip2718Error, Eip2718Result, IsTyped2718},
eip2930::AccessList,
@@ -155,19 +158,23 @@ where
}
}
impl<B, T> SignedTransaction for Extended<B, T>
impl<B, T> TxHashRef for Extended<B, T>
where
B: SignedTransaction + IsTyped2718,
T: SignedTransaction,
B: TxHashRef,
T: TxHashRef,
{
fn tx_hash(&self) -> &TxHash {
match self {
Self::BuiltIn(tx) => tx.tx_hash(),
Self::Other(tx) => tx.tx_hash(),
}
delegate!(self => tx.tx_hash())
}
}
impl<B, T> SignedTransaction for Extended<B, T>
where
B: SignedTransaction + IsTyped2718 + TxHashRef,
T: SignedTransaction + TxHashRef,
{
}
impl<B, T> Typed2718 for Extended<B, T>
where
B: Typed2718,

View File

@@ -18,7 +18,9 @@ pub mod signed;
pub mod error;
pub mod recover;
pub use alloy_consensus::transaction::{SignerRecoverable, TransactionInfo, TransactionMeta};
pub use alloy_consensus::transaction::{
SignerRecoverable, TransactionInfo, TransactionMeta, TxHashRef,
};
use crate::{InMemorySize, MaybeCompact, MaybeSerde};
use core::{fmt, hash::Hash};

View File

@@ -3,11 +3,11 @@
use crate::{InMemorySize, MaybeCompact, MaybeSerde, MaybeSerdeBincodeCompat};
use alloc::fmt;
use alloy_consensus::{
transaction::{Recovered, RlpEcdsaEncodableTx, SignerRecoverable},
transaction::{Recovered, RlpEcdsaEncodableTx, SignerRecoverable, TxHashRef},
EthereumTxEnvelope, SignableTransaction,
};
use alloy_eips::eip2718::{Decodable2718, Encodable2718};
use alloy_primitives::{keccak256, Address, Signature, TxHash, B256};
use alloy_primitives::{keccak256, Address, Signature, B256};
use alloy_rlp::{Decodable, Encodable};
use core::hash::Hash;
@@ -45,10 +45,8 @@ pub trait SignedTransaction:
+ MaybeSerde
+ InMemorySize
+ SignerRecoverable
+ TxHashRef
{
/// Returns reference to transaction hash.
fn tx_hash(&self) -> &TxHash;
/// Returns whether this transaction type can be __broadcasted__ as full transaction over the
/// network.
///
@@ -136,15 +134,6 @@ where
T: RlpEcdsaEncodableTx + SignableTransaction<Signature> + Unpin,
Self: Clone + PartialEq + Eq + Decodable + Decodable2718 + MaybeSerde + InMemorySize,
{
fn tx_hash(&self) -> &TxHash {
match self {
Self::Legacy(tx) => tx.hash(),
Self::Eip2930(tx) => tx.hash(),
Self::Eip1559(tx) => tx.hash(),
Self::Eip7702(tx) => tx.hash(),
Self::Eip4844(tx) => tx.hash(),
}
}
}
#[cfg(feature = "op")]
@@ -152,26 +141,7 @@ mod op {
use super::*;
use op_alloy_consensus::{OpPooledTransaction, OpTxEnvelope};
impl SignedTransaction for OpPooledTransaction {
fn tx_hash(&self) -> &TxHash {
match self {
Self::Legacy(tx) => tx.hash(),
Self::Eip2930(tx) => tx.hash(),
Self::Eip1559(tx) => tx.hash(),
Self::Eip7702(tx) => tx.hash(),
}
}
}
impl SignedTransaction for OpPooledTransaction {}
impl SignedTransaction for OpTxEnvelope {
fn tx_hash(&self) -> &TxHash {
match self {
Self::Legacy(tx) => tx.hash(),
Self::Eip2930(tx) => tx.hash(),
Self::Eip1559(tx) => tx.hash(),
Self::Eip7702(tx) => tx.hash(),
Self::Deposit(tx) => tx.hash_ref(),
}
}
}
impl SignedTransaction for OpTxEnvelope {}
}

View File

@@ -5,15 +5,13 @@ use crate::{
node::RpcNodeCoreExt, EthApiTypes, FromEthApiError, FullEthApiTypes, RpcBlock, RpcNodeCore,
RpcReceipt,
};
use alloy_consensus::TxReceipt;
use alloy_consensus::{transaction::TxHashRef, TxReceipt};
use alloy_eips::BlockId;
use alloy_rlp::Encodable;
use alloy_rpc_types_eth::{Block, BlockTransactions, Index};
use futures::Future;
use reth_node_api::BlockBody;
use reth_primitives_traits::{
AlloyBlockHeader, RecoveredBlock, SealedHeader, SignedTransaction, TransactionMeta,
};
use reth_primitives_traits::{AlloyBlockHeader, RecoveredBlock, SealedHeader, TransactionMeta};
use reth_rpc_convert::{transaction::ConvertReceiptInput, RpcConvert, RpcHeader};
use reth_storage_api::{BlockIdReader, BlockReader, ProviderHeader, ProviderReceipt, ProviderTx};
use reth_transaction_pool::{PoolTransaction, TransactionPool};

View File

@@ -7,7 +7,7 @@ use super::{LoadBlock, LoadPendingBlock, LoadState, LoadTransaction, SpawnBlocki
use crate::{
helpers::estimate::EstimateCall, FromEvmError, FullEthApiTypes, RpcBlock, RpcNodeCore,
};
use alloy_consensus::BlockHeader;
use alloy_consensus::{transaction::TxHashRef, BlockHeader};
use alloy_eips::eip2930::AccessListResult;
use alloy_evm::overrides::{apply_block_overrides, apply_state_overrides, OverrideBlockHashes};
use alloy_network::TransactionBuilder;
@@ -24,7 +24,7 @@ use reth_evm::{
TxEnvFor,
};
use reth_node_api::BlockBody;
use reth_primitives_traits::{Recovered, SignedTransaction};
use reth_primitives_traits::Recovered;
use reth_revm::{
database::StateProviderDatabase,
db::{CacheDB, State},

View File

@@ -2,7 +2,7 @@
use super::{Call, LoadBlock, LoadPendingBlock, LoadState, LoadTransaction};
use crate::FromEvmError;
use alloy_consensus::BlockHeader;
use alloy_consensus::{transaction::TxHashRef, BlockHeader};
use alloy_primitives::B256;
use alloy_rpc_types_eth::{BlockId, TransactionInfo};
use futures::Future;
@@ -12,7 +12,7 @@ use reth_evm::{
evm::EvmFactoryExt, system_calls::SystemCaller, tracing::TracingCtx, ConfigureEvm, Database,
Evm, EvmEnvFor, EvmFor, HaltReasonFor, InspectorFor, TxEnvFor,
};
use reth_primitives_traits::{BlockBody, Recovered, RecoveredBlock, SignedTransaction};
use reth_primitives_traits::{BlockBody, Recovered, RecoveredBlock};
use reth_revm::{database::StateProviderDatabase, db::CacheDB};
use reth_rpc_eth_types::{
cache::db::{StateCacheDb, StateCacheDbRefMutWrapper, StateProviderTraitObjWrapper},

View File

@@ -8,7 +8,7 @@ use crate::{
RpcTransaction,
};
use alloy_consensus::{
transaction::{SignerRecoverable, TransactionMeta},
transaction::{SignerRecoverable, TransactionMeta, TxHashRef},
BlockHeader, Transaction,
};
use alloy_dyn_abi::TypedData;

View File

@@ -7,7 +7,7 @@ use crate::{
},
EthApiError, RevertError,
};
use alloy_consensus::{BlockHeader, Transaction as _};
use alloy_consensus::{transaction::TxHashRef, BlockHeader, Transaction as _};
use alloy_eips::eip2718::WithEncoded;
use alloy_network::TransactionBuilder;
use alloy_rpc_types_eth::{
@@ -19,9 +19,7 @@ use reth_evm::{
execute::{BlockBuilder, BlockBuilderOutcome, BlockExecutor},
Evm,
};
use reth_primitives_traits::{
BlockBody as _, BlockTy, NodePrimitives, Recovered, RecoveredBlock, SignedTransaction,
};
use reth_primitives_traits::{BlockBody as _, BlockTy, NodePrimitives, Recovered, RecoveredBlock};
use reth_rpc_convert::{RpcBlock, RpcConvert, RpcTxReq};
use reth_rpc_server_types::result::rpc_err;
use reth_storage_api::noop::NoopProvider;

View File

@@ -1,4 +1,7 @@
use alloy_consensus::{transaction::SignerRecoverable, BlockHeader};
use alloy_consensus::{
transaction::{SignerRecoverable, TxHashRef},
BlockHeader,
};
use alloy_eips::{eip2718::Encodable2718, BlockId, BlockNumberOrTag};
use alloy_genesis::ChainConfig;
use alloy_primitives::{uint, Address, Bytes, B256};
@@ -16,9 +19,7 @@ use async_trait::async_trait;
use jsonrpsee::core::RpcResult;
use reth_chainspec::{ChainSpecProvider, EthChainSpec, EthereumHardforks};
use reth_evm::{execute::Executor, ConfigureEvm, EvmEnvFor, TxEnvFor};
use reth_primitives_traits::{
Block as _, BlockBody, ReceiptWithBloom, RecoveredBlock, SignedTransaction,
};
use reth_primitives_traits::{Block as _, BlockBody, ReceiptWithBloom, RecoveredBlock};
use reth_revm::{
database::StateProviderDatabase,
db::{CacheDB, State},

View File

@@ -1,13 +1,13 @@
//! `Eth` bundle implementation and helpers.
use alloy_consensus::{EnvKzgSettings, Transaction as _};
use alloy_consensus::{transaction::TxHashRef, EnvKzgSettings, Transaction as _};
use alloy_eips::eip7840::BlobParams;
use alloy_primitives::{uint, Keccak256, U256};
use alloy_rpc_types_mev::{EthCallBundle, EthCallBundleResponse, EthCallBundleTransactionResult};
use jsonrpsee::core::RpcResult;
use reth_chainspec::{ChainSpecProvider, EthChainSpec};
use reth_evm::{ConfigureEvm, Evm};
use reth_primitives_traits::SignedTransaction;
use reth_revm::{database::StateProviderDatabase, db::CacheDB};
use reth_rpc_eth_api::{
helpers::{Call, EthTransactions, LoadPendingBlock},

View File

@@ -1,6 +1,6 @@
//! `Eth` Sim bundle implementation and helpers.
use alloy_consensus::BlockHeader;
use alloy_consensus::{transaction::TxHashRef, BlockHeader};
use alloy_eips::BlockNumberOrTag;
use alloy_evm::overrides::apply_block_overrides;
use alloy_primitives::U256;
@@ -11,7 +11,7 @@ use alloy_rpc_types_mev::{
};
use jsonrpsee::core::RpcResult;
use reth_evm::{ConfigureEvm, Evm};
use reth_primitives_traits::{Recovered, SignedTransaction};
use reth_primitives_traits::Recovered;
use reth_revm::{database::StateProviderDatabase, db::CacheDB};
use reth_rpc_api::MevSimApiServer;
use reth_rpc_eth_api::{

View File

@@ -19,7 +19,7 @@ use crate::{
TransactionsProviderExt, TrieWriter,
};
use alloy_consensus::{
transaction::{SignerRecoverable, TransactionMeta},
transaction::{SignerRecoverable, TransactionMeta, TxHashRef},
BlockHeader, Header, TxReceipt,
};
use alloy_eips::{eip2718::Encodable2718, BlockHashOrNumber};
@@ -47,7 +47,7 @@ use reth_execution_types::{Chain, ExecutionOutcome};
use reth_node_types::{BlockTy, BodyTy, HeaderTy, NodeTypes, ReceiptTy, TxTy};
use reth_primitives_traits::{
Account, Block as _, BlockBody as _, Bytecode, GotExpected, NodePrimitives, RecoveredBlock,
SealedHeader, SignedTransaction, StorageEntry,
SealedHeader, StorageEntry,
};
use reth_prune_types::{
PruneCheckpoint, PruneMode, PruneModes, PruneSegment, MINIMUM_PRUNING_DISTANCE,

View File

@@ -5,7 +5,11 @@ use crate::{
StateProviderBox, StateProviderFactory, StateReader, StateRootProvider, TransactionVariant,
TransactionsProvider,
};
use alloy_consensus::{constants::EMPTY_ROOT_HASH, transaction::TransactionMeta, BlockHeader};
use alloy_consensus::{
constants::EMPTY_ROOT_HASH,
transaction::{TransactionMeta, TxHashRef},
BlockHeader,
};
use alloy_eips::{BlockHashOrNumber, BlockId, BlockNumberOrTag};
use alloy_primitives::{
keccak256, map::HashMap, Address, BlockHash, BlockNumber, Bytes, StorageKey, StorageValue,
@@ -22,7 +26,7 @@ use reth_ethereum_primitives::EthPrimitives;
use reth_execution_types::ExecutionOutcome;
use reth_primitives_traits::{
Account, Block, BlockBody, Bytecode, GotExpected, NodePrimitives, RecoveredBlock, SealedHeader,
SignedTransaction, SignerRecoverable,
SignerRecoverable,
};
use reth_prune_types::PruneModes;
use reth_stages_types::{StageCheckpoint, StageId};

View File

@@ -7,7 +7,7 @@ use crate::{
traits::{CanonicalStateUpdate, EthPoolTransaction, TransactionPool, TransactionPoolExt},
BlockInfo, PoolTransaction, PoolUpdateKind, TransactionOrigin,
};
use alloy_consensus::{BlockHeader, Typed2718};
use alloy_consensus::{transaction::TxHashRef, BlockHeader, Typed2718};
use alloy_eips::{BlockNumberOrTag, Decodable2718, Encodable2718};
use alloy_primitives::{Address, BlockHash, BlockNumber};
use alloy_rlp::{Bytes, Encodable};

View File

@@ -60,7 +60,7 @@ use crate::{
validate::ValidPoolTransaction,
AddedTransactionOutcome, AllTransactionsEvents,
};
use alloy_consensus::{error::ValueError, BlockHeader, Signed, Typed2718};
use alloy_consensus::{error::ValueError, transaction::TxHashRef, BlockHeader, Signed, Typed2718};
use alloy_eips::{
eip2718::{Encodable2718, WithEncoded},
eip2930::AccessList,

View File

@@ -1,7 +1,9 @@
use crate::primitives::{CustomTransaction, TxPayment};
use alloy_consensus::{
crypto::RecoveryError, error::ValueError, transaction::SignerRecoverable, Signed,
TransactionEnvelope,
crypto::RecoveryError,
error::ValueError,
transaction::{SignerRecoverable, TxHashRef},
Signed, TransactionEnvelope,
};
use alloy_primitives::{Address, Sealed, B256};
use op_alloy_consensus::{OpPooledTransaction, OpTransaction, TxDeposit};
@@ -70,15 +72,17 @@ impl SignerRecoverable for CustomPooledTransaction {
}
}
impl SignedTransaction for CustomPooledTransaction {
impl TxHashRef for CustomPooledTransaction {
fn tx_hash(&self) -> &B256 {
match self {
CustomPooledTransaction::Op(tx) => SignedTransaction::tx_hash(tx),
CustomPooledTransaction::Op(tx) => tx.tx_hash(),
CustomPooledTransaction::Payment(tx) => tx.hash(),
}
}
}
impl SignedTransaction for CustomPooledTransaction {}
impl InMemorySize for CustomPooledTransaction {
fn size(&self) -> usize {
match self {

View File

@@ -1,6 +1,8 @@
use super::TxPayment;
use alloy_consensus::{
crypto::RecoveryError, transaction::SignerRecoverable, Signed, TransactionEnvelope,
crypto::RecoveryError,
transaction::{SignerRecoverable, TxHashRef},
Signed, TransactionEnvelope,
};
use alloy_eips::Encodable2718;
use alloy_primitives::{Sealed, Signature, B256};
@@ -121,15 +123,17 @@ impl SignerRecoverable for CustomTransaction {
}
}
impl SignedTransaction for CustomTransaction {
impl TxHashRef for CustomTransaction {
fn tx_hash(&self) -> &B256 {
match self {
CustomTransaction::Op(tx) => SignedTransaction::tx_hash(tx),
CustomTransaction::Op(tx) => TxHashRef::tx_hash(tx),
CustomTransaction::Payment(tx) => tx.hash(),
}
}
}
impl SignedTransaction for CustomTransaction {}
impl InMemorySize for CustomTransaction {
fn size(&self) -> usize {
match self {