diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index 1c93ae5497..9628dbb4f1 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -49,7 +49,7 @@ use reth_network_p2p::{ use reth_network_peers::PeerId; use reth_network_types::ReputationChangeKind; use reth_primitives::{PooledTransactionsElement, TransactionSigned}; -use reth_primitives_traits::{SignedTransaction, TransactionExt, TxType}; +use reth_primitives_traits::{SignedTransaction, TxType}; use reth_tokio_util::EventStream; use reth_transaction_pool::{ error::{PoolError, PoolResult}, @@ -1617,7 +1617,7 @@ impl FullTransactionsBuilder { // via `GetPooledTransactions`. // // From: - if !transaction.transaction.transaction().tx_type().is_broadcastable_in_full() { + if !transaction.transaction.tx_type().is_broadcastable_in_full() { self.pooled.push(transaction); return } @@ -1683,7 +1683,7 @@ impl PooledTransactionsHashesBuilder { Self::Eth68(msg) => { msg.hashes.push(*tx.tx_hash()); msg.sizes.push(tx.size); - msg.types.push(tx.transaction.transaction().tx_type().into()); + msg.types.push(tx.transaction.tx_type().into()); } } } diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index 5c969152d8..c149c6cd7e 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -29,7 +29,7 @@ pub use transaction::{ execute::FillTxEnv, signed::{FullSignedTx, SignedTransaction}, tx_type::{FullTxType, TxType}, - FullTransaction, Transaction, TransactionExt, + FullTransaction, Transaction, }; mod integer_list; diff --git a/crates/primitives-traits/src/transaction/mod.rs b/crates/primitives-traits/src/transaction/mod.rs index 7647c94496..f176382146 100644 --- a/crates/primitives-traits/src/transaction/mod.rs +++ b/crates/primitives-traits/src/transaction/mod.rs @@ -4,16 +4,13 @@ pub mod execute; pub mod signed; pub mod tx_type; +use crate::{InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde}; use core::{fmt, hash::Hash}; -use alloy_primitives::B256; - -use crate::{FullTxType, InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde, TxType}; - /// Helper trait that unifies all behaviour required by transaction to support full node operations. -pub trait FullTransaction: Transaction + MaybeCompact {} +pub trait FullTransaction: Transaction + MaybeCompact {} -impl FullTransaction for T where T: Transaction + MaybeCompact {} +impl FullTransaction for T where T: Transaction + MaybeCompact {} /// Abstraction of a transaction. pub trait Transaction: @@ -26,7 +23,7 @@ pub trait Transaction: + Eq + PartialEq + Hash - + TransactionExt + + alloy_consensus::Transaction + InMemorySize + MaybeSerde + MaybeArbitrary @@ -43,25 +40,9 @@ impl Transaction for T where + Eq + PartialEq + Hash - + TransactionExt + + alloy_consensus::Transaction + InMemorySize + MaybeSerde + MaybeArbitrary { } - -/// Extension trait of [`alloy_consensus::Transaction`]. -#[auto_impl::auto_impl(&, Arc)] -pub trait TransactionExt: alloy_consensus::Transaction { - /// Transaction envelope type ID. - type Type: TxType; - - /// Heavy operation that return signature hash over rlp encoded transaction. - /// It is only for signature signing or signer recovery. - fn signature_hash(&self) -> B256; - - /// Returns the transaction type. - fn tx_type(&self) -> Self::Type { - Self::Type::try_from(self.ty()).expect("should decode tx type id") - } -} diff --git a/crates/primitives-traits/src/transaction/signed.rs b/crates/primitives-traits/src/transaction/signed.rs index 563f3a6f33..64acbd3415 100644 --- a/crates/primitives-traits/src/transaction/signed.rs +++ b/crates/primitives-traits/src/transaction/signed.rs @@ -1,25 +1,15 @@ //! API of a signed transaction. +use crate::{FillTxEnv, InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde, TxType}; use alloc::fmt; -use core::hash::Hash; - use alloy_eips::eip2718::{Decodable2718, Encodable2718}; use alloy_primitives::{keccak256, Address, PrimitiveSignature, TxHash, B256}; - -use crate::{ - FillTxEnv, FullTransaction, InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde, Transaction, -}; +use core::hash::Hash; /// Helper trait that unifies all behaviour required by block to support full node operations. -pub trait FullSignedTx: - SignedTransaction + FillTxEnv + MaybeCompact -{ -} +pub trait FullSignedTx: SignedTransaction + FillTxEnv + MaybeCompact {} -impl FullSignedTx for T where - T: SignedTransaction + FillTxEnv + MaybeCompact -{ -} +impl FullSignedTx for T where T: SignedTransaction + FillTxEnv + MaybeCompact {} /// A signed transaction. #[auto_impl::auto_impl(&, Arc)] @@ -42,15 +32,17 @@ pub trait SignedTransaction: + MaybeArbitrary + InMemorySize { - /// Unsigned transaction type. - type Transaction: Transaction; + /// Transaction envelope type ID. + type Type: TxType; + + /// Returns the transaction type. + fn tx_type(&self) -> Self::Type { + Self::Type::try_from(self.ty()).expect("should decode tx type id") + } /// Returns reference to transaction hash. fn tx_hash(&self) -> &TxHash; - /// Returns reference to transaction. - fn transaction(&self) -> &Self::Transaction; - /// Returns reference to signature. fn signature(&self) -> &PrimitiveSignature; @@ -78,15 +70,3 @@ pub trait SignedTransaction: keccak256(self.encoded_2718()) } } - -/// Helper trait used in testing. -#[cfg(feature = "test-utils")] -pub trait SignedTransactionTesting: SignedTransaction { - /// Create a new signed transaction from a transaction and its signature. - /// - /// This will also calculate the transaction hash using its encoding. - fn from_transaction_and_signature( - transaction: Self::Transaction, - signature: PrimitiveSignature, - ) -> Self; -} diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 5900abb42c..1e313ca8b2 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1,5 +1,6 @@ //! Transaction types. +use alloc::vec::Vec; use alloy_consensus::{ transaction::RlpEcdsaTx, SignableTransaction, Transaction as _, TxEip1559, TxEip2930, TxEip4844, TxEip7702, TxLegacy, @@ -24,21 +25,23 @@ use once_cell as _; use once_cell::sync::{Lazy as LazyLock, OnceCell as OnceLock}; #[cfg(feature = "optimism")] use op_alloy_consensus::DepositTransaction; +#[cfg(feature = "optimism")] +use op_alloy_consensus::TxDeposit; use rayon::prelude::{IntoParallelIterator, ParallelIterator}; -use reth_primitives_traits::InMemorySize; +use reth_primitives_traits::{InMemorySize, SignedTransaction}; +use revm_primitives::{AuthorizationList, TxEnv}; use serde::{Deserialize, Serialize}; use signature::decode_with_eip155_chain_id; #[cfg(feature = "std")] use std::sync::{LazyLock, OnceLock}; +pub use compat::FillTxEnv; pub use error::{ InvalidTransactionError, TransactionConversionError, TryFromRecoveredTransactionError, }; pub use meta::TransactionMeta; pub use pooled::{PooledTransactionsElement, PooledTransactionsElementEcRecovered}; pub use sidecar::BlobTransaction; - -pub use compat::FillTxEnv; pub use signature::{recover_signer, recover_signer_unchecked}; pub use tx_type::TxType; pub use variant::TransactionSignedVariant; @@ -58,12 +61,6 @@ pub mod signature; pub(crate) mod util; mod variant; -use alloc::vec::Vec; -#[cfg(feature = "optimism")] -use op_alloy_consensus::TxDeposit; -use reth_primitives_traits::{transaction::TransactionExt, SignedTransaction}; -use revm_primitives::{AuthorizationList, TxEnv}; - /// Either a transaction hash or number. pub type TxHashOrNumber = BlockHashOrNumber; @@ -839,22 +836,6 @@ impl alloy_consensus::Transaction for Transaction { } } -impl TransactionExt for Transaction { - type Type = TxType; - - fn signature_hash(&self) -> B256 { - match self { - Self::Legacy(tx) => tx.signature_hash(), - Self::Eip2930(tx) => tx.signature_hash(), - Self::Eip1559(tx) => tx.signature_hash(), - Self::Eip4844(tx) => tx.signature_hash(), - Self::Eip7702(tx) => tx.signature_hash(), - #[cfg(feature = "optimism")] - _ => todo!("use op type for op"), - } - } -} - /// Signed transaction without its Hash. Used type for inserting into the DB. /// /// This can by converted to [`TransactionSigned`] by calling [`TransactionSignedNoHash::hash`]. @@ -1345,16 +1326,12 @@ impl TransactionSigned { } impl SignedTransaction for TransactionSigned { - type Transaction = Transaction; + type Type = TxType; fn tx_hash(&self) -> &TxHash { self.hash_ref() } - fn transaction(&self) -> &Self::Transaction { - &self.transaction - } - fn signature(&self) -> &Signature { &self.signature }