diff --git a/Cargo.lock b/Cargo.lock index f94e0e8f89..865c1d4fcc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5108,6 +5108,7 @@ dependencies = [ "rand 0.8.5", "reth-metrics-derive", "reth-primitives", + "reth-rlp", "ruint", "serde", "thiserror", diff --git a/crates/transaction-pool/Cargo.toml b/crates/transaction-pool/Cargo.toml index 3b8fefc4dc..2ecd3f202a 100644 --- a/crates/transaction-pool/Cargo.toml +++ b/crates/transaction-pool/Cargo.toml @@ -17,8 +17,9 @@ normal = [ [dependencies] -# eth +# reth reth-primitives = { path = "../primitives" } +reth-rlp = { path = "../rlp" } # async/futures async-trait = "0.1" diff --git a/crates/transaction-pool/src/test_utils/mock.rs b/crates/transaction-pool/src/test_utils/mock.rs index ba88d15ebd..118e8a8e98 100644 --- a/crates/transaction-pool/src/test_utils/mock.rs +++ b/crates/transaction-pool/src/test_utils/mock.rs @@ -13,7 +13,7 @@ use rand::{ }; use reth_primitives::{ Address, FromRecoveredTransaction, IntoRecoveredTransaction, Transaction, TransactionKind, - TransactionSignedEcRecovered, TxEip1559, TxHash, TxLegacy, H256, U128, U256, + TransactionSignedEcRecovered, TxEip1559, TxHash, TxLegacy, TxType, H256, U128, U256, }; use std::{ops::Range, sync::Arc, time::Instant}; @@ -345,6 +345,17 @@ impl PoolTransaction for MockTransaction { fn size(&self) -> usize { 0 } + + fn tx_type(&self) -> u8 { + match self { + MockTransaction::Legacy { .. } => TxType::Legacy.into(), + MockTransaction::Eip1559 { .. } => TxType::EIP1559.into(), + } + } + + fn encoded_length(&self) -> usize { + 0 + } } impl FromRecoveredTransaction for MockTransaction { diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index d9b9461b0b..e9bec85652 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -3,6 +3,7 @@ use reth_primitives::{ Address, FromRecoveredTransaction, IntoRecoveredTransaction, PeerId, Transaction, TransactionKind, TransactionSignedEcRecovered, TxHash, H256, U256, }; +use reth_rlp::Encodable; use std::{collections::HashMap, fmt, sync::Arc}; use tokio::sync::mpsc::Receiver; @@ -287,6 +288,12 @@ pub trait PoolTransaction: fmt::Debug + Send + Sync + FromRecoveredTransaction { /// Returns a measurement of the heap usage of this type and all its internals. fn size(&self) -> usize; + + /// Returns the transaction type + fn tx_type(&self) -> u8; + + /// Returns the length of the rlp encoded object + fn encoded_length(&self) -> usize; } /// The default [PoolTransaction] for the [Pool](crate::Pool). @@ -372,6 +379,16 @@ impl PoolTransaction for PooledTransaction { fn size(&self) -> usize { self.transaction.transaction.input().len() } + + /// Returns the transaction type + fn tx_type(&self) -> u8 { + self.transaction.tx_type().into() + } + + /// Returns the length of the rlp encoded object + fn encoded_length(&self) -> usize { + self.transaction.length() + } } impl FromRecoveredTransaction for PooledTransaction {