From f2141925b0bbe0ad19e66110419f57325bcbae9c Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Wed, 11 Dec 2024 12:48:39 +0100 Subject: [PATCH] chore: rm associated type (#13292) --- crates/net/network/src/transactions/mod.rs | 6 +-- .../primitives/src/transaction/signed.rs | 2 - crates/primitives-traits/src/lib.rs | 1 - crates/primitives-traits/src/node.rs | 8 +-- .../primitives-traits/src/transaction/mod.rs | 1 - .../src/transaction/signed.rs | 20 +++---- .../src/transaction/tx_type.rs | 52 ------------------- crates/primitives/src/lib.rs | 1 - crates/primitives/src/transaction/mod.rs | 2 - crates/primitives/src/transaction/pooled.rs | 4 +- crates/primitives/src/transaction/tx_type.rs | 10 ---- 11 files changed, 17 insertions(+), 90 deletions(-) delete mode 100644 crates/primitives-traits/src/transaction/tx_type.rs diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index 4ed352353b72..7e87736cc49b 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -50,7 +50,7 @@ use reth_network_p2p::{ use reth_network_peers::PeerId; use reth_network_types::ReputationChangeKind; use reth_primitives::{transaction::SignedTransactionIntoRecoveredExt, TransactionSigned}; -use reth_primitives_traits::{SignedTransaction, TxType}; +use reth_primitives_traits::SignedTransaction; use reth_tokio_util::EventStream; use reth_transaction_pool::{ error::{PoolError, PoolResult}, @@ -1641,7 +1641,7 @@ impl FullTransactionsBuilder { /// /// If the transaction is unsuitable for broadcast or would exceed the softlimit, it is appended /// to list of pooled transactions, (e.g. 4844 transactions). - /// See also [`TxType::is_broadcastable_in_full`]. + /// See also [`SignedTransaction::is_broadcastable_in_full`]. fn push(&mut self, transaction: &PropagateTransaction) { // Do not send full 4844 transaction hashes to peers. // @@ -1651,7 +1651,7 @@ impl FullTransactionsBuilder { // via `GetPooledTransactions`. // // From: - if !transaction.transaction.tx_type().is_broadcastable_in_full() { + if !transaction.transaction.is_broadcastable_in_full() { self.pooled.push(transaction); return } diff --git a/crates/optimism/primitives/src/transaction/signed.rs b/crates/optimism/primitives/src/transaction/signed.rs index 41a63be3bf2e..5acf9b8a8ca7 100644 --- a/crates/optimism/primitives/src/transaction/signed.rs +++ b/crates/optimism/primitives/src/transaction/signed.rs @@ -70,8 +70,6 @@ impl OpTransactionSigned { } impl SignedTransaction for OpTransactionSigned { - type Type = OpTxType; - fn tx_hash(&self) -> &TxHash { self.hash.get_or_init(|| self.recalculate_hash()) } diff --git a/crates/primitives-traits/src/lib.rs b/crates/primitives-traits/src/lib.rs index 04d02be0b7dd..89cf6382ae54 100644 --- a/crates/primitives-traits/src/lib.rs +++ b/crates/primitives-traits/src/lib.rs @@ -27,7 +27,6 @@ pub mod transaction; pub use transaction::{ execute::FillTxEnv, signed::{FullSignedTx, SignedTransaction}, - tx_type::{FullTxType, TxType}, FullTransaction, Transaction, }; diff --git a/crates/primitives-traits/src/node.rs b/crates/primitives-traits/src/node.rs index 5b3691d2fdf7..0d46141da0c6 100644 --- a/crates/primitives-traits/src/node.rs +++ b/crates/primitives-traits/src/node.rs @@ -1,6 +1,6 @@ use crate::{ Block, BlockBody, BlockHeader, FullBlock, FullBlockBody, FullBlockHeader, FullReceipt, - FullSignedTx, FullTxType, Receipt, SignedTransaction, TxType, + FullSignedTx, Receipt, SignedTransaction, }; use core::fmt; @@ -15,9 +15,7 @@ pub trait NodePrimitives: /// Block body primitive. type BlockBody: BlockBody; /// Signed version of the transaction type. - type SignedTx: SignedTransaction + 'static; - /// Transaction envelope type ID. - type TxType: TxType + 'static; + type SignedTx: SignedTransaction + 'static; /// A receipt. type Receipt: Receipt; } @@ -29,7 +27,6 @@ where BlockHeader: FullBlockHeader, BlockBody: FullBlockBody, SignedTx: FullSignedTx, - TxType: FullTxType, Receipt: FullReceipt, > + Send + Sync @@ -49,7 +46,6 @@ impl FullNodePrimitives for T where BlockHeader: FullBlockHeader, BlockBody: FullBlockBody, SignedTx: FullSignedTx, - TxType: FullTxType, Receipt: FullReceipt, > + Send + Sync diff --git a/crates/primitives-traits/src/transaction/mod.rs b/crates/primitives-traits/src/transaction/mod.rs index b67e51024bf6..0608ded860e6 100644 --- a/crates/primitives-traits/src/transaction/mod.rs +++ b/crates/primitives-traits/src/transaction/mod.rs @@ -2,7 +2,6 @@ pub mod execute; pub mod signed; -pub mod tx_type; use crate::{InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde}; use core::{fmt, hash::Hash}; diff --git a/crates/primitives-traits/src/transaction/signed.rs b/crates/primitives-traits/src/transaction/signed.rs index 5e0a91b4da2b..4665467e8b39 100644 --- a/crates/primitives-traits/src/transaction/signed.rs +++ b/crates/primitives-traits/src/transaction/signed.rs @@ -1,6 +1,6 @@ //! API of a signed transaction. -use crate::{FillTxEnv, InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde, TxType}; +use crate::{FillTxEnv, InMemorySize, MaybeArbitrary, MaybeCompact, MaybeSerde}; use alloc::{fmt, vec::Vec}; use alloy_eips::eip2718::{Decodable2718, Encodable2718}; use alloy_primitives::{keccak256, Address, PrimitiveSignature, TxHash, B256}; @@ -31,20 +31,22 @@ pub trait SignedTransaction: + MaybeArbitrary + InMemorySize { - /// 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 signature. fn signature(&self) -> &PrimitiveSignature; + /// Returns whether this transaction type can be __broadcasted__ as full transaction over the + /// network. + /// + /// Some transactions are not broadcastable as objects and only allowed to be broadcasted as + /// hashes, e.g. because they missing context (e.g. blob sidecar). + fn is_broadcastable_in_full(&self) -> bool { + // EIP-4844 transactions are not broadcastable in full, only hashes are allowed. + !self.is_eip4844() + } + /// Recover signer from signature and hash. /// /// Returns `None` if the transaction's signature is invalid following [EIP-2](https://eips.ethereum.org/EIPS/eip-2), see also `reth_primitives::transaction::recover_signer`. diff --git a/crates/primitives-traits/src/transaction/tx_type.rs b/crates/primitives-traits/src/transaction/tx_type.rs deleted file mode 100644 index c60cd9cb3af4..000000000000 --- a/crates/primitives-traits/src/transaction/tx_type.rs +++ /dev/null @@ -1,52 +0,0 @@ -//! Abstraction of transaction envelope type ID. - -use crate::{InMemorySize, MaybeArbitrary, MaybeCompact}; -use alloy_consensus::Typed2718; -use alloy_primitives::{U64, U8}; -use core::fmt; - -/// Helper trait that unifies all behaviour required by transaction type ID to support full node -/// operations. -pub trait FullTxType: TxType + MaybeCompact {} - -impl FullTxType for T where T: TxType + MaybeCompact {} - -/// Trait representing the behavior of a transaction type. -pub trait TxType: - Send - + Sync - + Unpin - + Clone - + Copy - + Default - + fmt::Debug - + fmt::Display - + PartialEq - + Eq - + PartialEq - + Into - + Into - + TryFrom - + TryFrom - + TryFrom - + alloy_rlp::Encodable - + alloy_rlp::Decodable - + Typed2718 - + InMemorySize - + MaybeArbitrary -{ - /// Returns whether this transaction type can be __broadcasted__ as full transaction over the - /// network. - /// - /// Some transactions are not broadcastable as objects and only allowed to be broadcasted as - /// hashes, e.g. because they missing context (e.g. blob sidecar). - fn is_broadcastable_in_full(&self) -> bool { - // EIP-4844 transactions are not broadcastable in full, only hashes are allowed. - !self.is_eip4844() - } -} - -#[cfg(feature = "op")] -impl TxType for op_alloy_consensus::OpTxType {} - -impl TxType for alloy_consensus::TxType {} diff --git a/crates/primitives/src/lib.rs b/crates/primitives/src/lib.rs index 18fe1498b8a8..ab796d734abd 100644 --- a/crates/primitives/src/lib.rs +++ b/crates/primitives/src/lib.rs @@ -86,6 +86,5 @@ impl reth_primitives_traits::NodePrimitives for EthPrimitives { type BlockHeader = alloy_consensus::Header; type BlockBody = crate::BlockBody; type SignedTx = crate::TransactionSigned; - type TxType = crate::TxType; type Receipt = crate::Receipt; } diff --git a/crates/primitives/src/transaction/mod.rs b/crates/primitives/src/transaction/mod.rs index 13c71ce2094d..444090ad2950 100644 --- a/crates/primitives/src/transaction/mod.rs +++ b/crates/primitives/src/transaction/mod.rs @@ -1030,8 +1030,6 @@ impl TransactionSigned { } impl SignedTransaction for TransactionSigned { - type Type = TxType; - fn tx_hash(&self) -> &TxHash { self.hash.get_or_init(|| self.recalculate_hash()) } diff --git a/crates/primitives/src/transaction/pooled.rs b/crates/primitives/src/transaction/pooled.rs index b4790d028290..a5256583e59b 100644 --- a/crates/primitives/src/transaction/pooled.rs +++ b/crates/primitives/src/transaction/pooled.rs @@ -5,7 +5,7 @@ use super::{ error::TransactionConversionError, recover_signer_unchecked, signature::recover_signer, TxEip7702, }; -use crate::{BlobTransaction, RecoveredTx, Transaction, TransactionSigned, TxType}; +use crate::{BlobTransaction, RecoveredTx, Transaction, TransactionSigned}; use alloc::vec::Vec; use alloy_consensus::{ constants::EIP4844_TX_TYPE_ID, @@ -568,8 +568,6 @@ impl alloy_consensus::Transaction for PooledTransactionsElement { } impl SignedTransaction for PooledTransactionsElement { - type Type = TxType; - fn tx_hash(&self) -> &TxHash { match self { Self::Legacy(tx) => tx.hash(), diff --git a/crates/primitives/src/transaction/tx_type.rs b/crates/primitives/src/transaction/tx_type.rs index d0a4786dcf16..83f954387692 100644 --- a/crates/primitives/src/transaction/tx_type.rs +++ b/crates/primitives/src/transaction/tx_type.rs @@ -97,8 +97,6 @@ impl Typed2718 for TxType { } } -impl reth_primitives_traits::TxType for TxType {} - impl InMemorySize for TxType { /// Calculates a heuristic for the in-memory size of the [`TxType`]. #[inline] @@ -259,16 +257,8 @@ mod tests { use super::*; use alloy_primitives::hex; use reth_codecs::Compact; - use reth_primitives_traits::TxType as _; use rstest::rstest; - #[test] - fn is_broadcastable() { - assert!(TxType::Legacy.is_broadcastable_in_full()); - assert!(TxType::Eip1559.is_broadcastable_in_full()); - assert!(!TxType::Eip4844.is_broadcastable_in_full()); - } - #[rstest] #[case(U64::from(LEGACY_TX_TYPE_ID), Ok(TxType::Legacy))] #[case(U64::from(EIP2930_TX_TYPE_ID), Ok(TxType::Eip2930))]