Skip to content

Commit

Permalink
chore: rm associated type (#13292)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Dec 11, 2024
1 parent fa340b5 commit f214192
Show file tree
Hide file tree
Showing 11 changed files with 17 additions and 90 deletions.
6 changes: 3 additions & 3 deletions crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -1641,7 +1641,7 @@ impl<T: SignedTransaction> FullTransactionsBuilder<T> {
///
/// 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<T>) {
// Do not send full 4844 transaction hashes to peers.
//
Expand All @@ -1651,7 +1651,7 @@ impl<T: SignedTransaction> FullTransactionsBuilder<T> {
// via `GetPooledTransactions`.
//
// From: <https://eips.ethereum.org/EIPS/eip-4844#networking>
if !transaction.transaction.tx_type().is_broadcastable_in_full() {
if !transaction.transaction.is_broadcastable_in_full() {
self.pooled.push(transaction);
return
}
Expand Down
2 changes: 0 additions & 2 deletions crates/optimism/primitives/src/transaction/signed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
1 change: 0 additions & 1 deletion crates/primitives-traits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub mod transaction;
pub use transaction::{
execute::FillTxEnv,
signed::{FullSignedTx, SignedTransaction},
tx_type::{FullTxType, TxType},
FullTransaction, Transaction,
};

Expand Down
8 changes: 2 additions & 6 deletions crates/primitives-traits/src/node.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
Block, BlockBody, BlockHeader, FullBlock, FullBlockBody, FullBlockHeader, FullReceipt,
FullSignedTx, FullTxType, Receipt, SignedTransaction, TxType,
FullSignedTx, Receipt, SignedTransaction,
};
use core::fmt;

Expand All @@ -15,9 +15,7 @@ pub trait NodePrimitives:
/// Block body primitive.
type BlockBody: BlockBody<Transaction = Self::SignedTx, OmmerHeader = Self::BlockHeader>;
/// Signed version of the transaction type.
type SignedTx: SignedTransaction<Type = Self::TxType> + 'static;
/// Transaction envelope type ID.
type TxType: TxType + 'static;
type SignedTx: SignedTransaction + 'static;
/// A receipt.
type Receipt: Receipt;
}
Expand All @@ -29,7 +27,6 @@ where
BlockHeader: FullBlockHeader,
BlockBody: FullBlockBody<Transaction = Self::SignedTx>,
SignedTx: FullSignedTx,
TxType: FullTxType,
Receipt: FullReceipt,
> + Send
+ Sync
Expand All @@ -49,7 +46,6 @@ impl<T> FullNodePrimitives for T where
BlockHeader: FullBlockHeader,
BlockBody: FullBlockBody<Transaction = Self::SignedTx>,
SignedTx: FullSignedTx,
TxType: FullTxType,
Receipt: FullReceipt,
> + Send
+ Sync
Expand Down
1 change: 0 additions & 1 deletion crates/primitives-traits/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
20 changes: 11 additions & 9 deletions crates/primitives-traits/src/transaction/signed.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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`.
Expand Down
52 changes: 0 additions & 52 deletions crates/primitives-traits/src/transaction/tx_type.rs

This file was deleted.

1 change: 0 additions & 1 deletion crates/primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 0 additions & 2 deletions crates/primitives/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
4 changes: 1 addition & 3 deletions crates/primitives/src/transaction/pooled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
Expand Down
10 changes: 0 additions & 10 deletions crates/primitives/src/transaction/tx_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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))]
Expand Down

0 comments on commit f214192

Please sign in to comment.