From 388af87f59a6f3c3f1fc34f26f0632a9fe86a209 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 26 Nov 2024 13:41:38 +0100 Subject: [PATCH 1/2] feat: use pooled AT for get_pooled_transactions --- crates/net/network/src/transactions/mod.rs | 8 ++++++-- crates/transaction-pool/src/lib.rs | 14 ++++++++++++-- crates/transaction-pool/src/noop.rs | 17 ++++++++++++++--- crates/transaction-pool/src/pool/mod.rs | 18 +++++++++++++++--- crates/transaction-pool/src/traits.rs | 11 ++++++++++- 5 files changed, 57 insertions(+), 11 deletions(-) diff --git a/crates/net/network/src/transactions/mod.rs b/crates/net/network/src/transactions/mod.rs index 9628dbb4f1ba..6e0a3b2f327f 100644 --- a/crates/net/network/src/transactions/mod.rs +++ b/crates/net/network/src/transactions/mod.rs @@ -961,6 +961,8 @@ impl TransactionsManager where Pool: TransactionPool + 'static, <::Transaction as PoolTransaction>::Consensus: Into, + <::Transaction as PoolTransaction>::Pooled: + Into, { /// Request handler for an incoming request for transactions fn on_get_pooled_transactions( @@ -974,14 +976,14 @@ where let _ = response.send(Ok(PooledTransactions::default())); return } - let transactions = self.pool.get_pooled_transaction_elements( + let transactions = self.pool.get_pooled_transactions_as::( request.0, GetPooledTransactionLimit::ResponseSizeSoftLimit( self.transaction_fetcher.info.soft_limit_byte_size_pooled_transactions_response, ), ); - trace!(target: "net::tx::propagation", sent_txs=?transactions.iter().map(|tx| *tx.hash()), "Sending requested transactions to peer"); + trace!(target: "net::tx::propagation", sent_txs=?transactions.iter().map(|tx| tx.tx_hash()), "Sending requested transactions to peer"); // we sent a response at which point we assume that the peer is aware of the // transactions @@ -1291,6 +1293,8 @@ impl Future for TransactionsManager where Pool: TransactionPool + Unpin + 'static, <::Transaction as PoolTransaction>::Consensus: Into, + <::Transaction as PoolTransaction>::Pooled: + Into, { type Output = (); diff --git a/crates/transaction-pool/src/lib.rs b/crates/transaction-pool/src/lib.rs index 83e3b78c6b8a..1c383e8edf01 100644 --- a/crates/transaction-pool/src/lib.rs +++ b/crates/transaction-pool/src/lib.rs @@ -156,7 +156,6 @@ use alloy_primitives::{Address, TxHash, B256, U256}; use aquamarine as _; use reth_eth_wire_types::HandleMempoolData; use reth_execution_types::ChangedAccount; -use reth_primitives::PooledTransactionsElement; use reth_storage_api::StateProviderFactory; use std::{collections::HashSet, sync::Arc}; use tokio::sync::mpsc::Receiver; @@ -416,10 +415,21 @@ where &self, tx_hashes: Vec, limit: GetPooledTransactionLimit, - ) -> Vec { + ) -> Vec<<::Transaction as PoolTransaction>::Pooled> { self.pool.get_pooled_transaction_elements(tx_hashes, limit) } + fn get_pooled_transactions_as

( + &self, + tx_hashes: Vec, + limit: GetPooledTransactionLimit, + ) -> Vec

+ where + ::Pooled: Into

, + { + self.pool.get_pooled_transactions_as(tx_hashes, limit) + } + fn get_pooled_transaction_element( &self, tx_hash: TxHash, diff --git a/crates/transaction-pool/src/noop.rs b/crates/transaction-pool/src/noop.rs index 79901fe18d08..3a068d3a5936 100644 --- a/crates/transaction-pool/src/noop.rs +++ b/crates/transaction-pool/src/noop.rs @@ -13,8 +13,8 @@ use crate::{ validate::ValidTransaction, AllPoolTransactions, AllTransactionsEvents, BestTransactions, BlockInfo, EthPoolTransaction, EthPooledTransaction, NewTransactionEvent, PoolResult, PoolSize, PoolTransaction, - PooledTransactionsElement, PropagatedTransactions, TransactionEvents, TransactionOrigin, - TransactionPool, TransactionValidationOutcome, TransactionValidator, ValidPoolTransaction, + PropagatedTransactions, TransactionEvents, TransactionOrigin, TransactionPool, + TransactionValidationOutcome, TransactionValidator, ValidPoolTransaction, }; use alloy_eips::{ eip1559::ETHEREUM_BLOCK_GAS_LIMIT, @@ -135,7 +135,18 @@ impl TransactionPool for NoopTransactionPool { &self, _tx_hashes: Vec, _limit: GetPooledTransactionLimit, - ) -> Vec { + ) -> Vec<::Pooled> { + vec![] + } + + fn get_pooled_transactions_as( + &self, + _tx_hashes: Vec, + _limit: GetPooledTransactionLimit, + ) -> Vec + where + ::Pooled: Into, + { vec![] } diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 4a035f8e42a8..8efb98355309 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -88,7 +88,6 @@ use reth_eth_wire_types::HandleMempoolData; use reth_execution_types::ChangedAccount; use alloy_eips::eip4844::BlobTransactionSidecar; -use reth_primitives::PooledTransactionsElement; use std::{ collections::{HashMap, HashSet}, fmt, @@ -340,14 +339,27 @@ where } } - /// Returns converted [`PooledTransactionsElement`] for the given transaction hashes. + /// Returns pooled transactions for the given transaction hashes. pub(crate) fn get_pooled_transaction_elements( &self, tx_hashes: Vec, limit: GetPooledTransactionLimit, - ) -> Vec + ) -> Vec<<::Transaction as PoolTransaction>::Pooled> where ::Transaction: EthPoolTransaction, + { + self.get_pooled_transactions_as(tx_hashes, limit) + } + + /// Returns pooled transactions for the given transaction hashes as the requested type. + pub(crate) fn get_pooled_transactions_as

( + &self, + tx_hashes: Vec, + limit: GetPooledTransactionLimit, + ) -> Vec

+ where + ::Transaction: EthPoolTransaction, + <::Transaction as PoolTransaction>::Pooled: Into

, { let transactions = self.get_all(tx_hashes); let mut elements = Vec::with_capacity(transactions.len()); diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 742b95cff380..2973e36f7a6f 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -231,7 +231,16 @@ pub trait TransactionPool: Send + Sync + Clone { &self, tx_hashes: Vec, limit: GetPooledTransactionLimit, - ) -> Vec; + ) -> Vec<::Pooled>; + + /// Returns the pooled transaction variant for the given transaction hash as the requested type. + fn get_pooled_transactions_as( + &self, + tx_hashes: Vec, + limit: GetPooledTransactionLimit, + ) -> Vec + where + ::Pooled: Into; /// Returns the pooled transaction variant for the given transaction hash. /// From edb1fa3e2b8d940426baeb91c51bd4ad0aee4bf6 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Tue, 26 Nov 2024 13:45:15 +0100 Subject: [PATCH 2/2] docs --- crates/transaction-pool/src/pool/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/transaction-pool/src/pool/mod.rs b/crates/transaction-pool/src/pool/mod.rs index 8efb98355309..b5391b6e8d73 100644 --- a/crates/transaction-pool/src/pool/mod.rs +++ b/crates/transaction-pool/src/pool/mod.rs @@ -381,7 +381,7 @@ where elements } - /// Returns converted [`PooledTransactionsElement`] for the given transaction hash. + /// Returns converted pooled transaction for the given transaction hash. pub(crate) fn get_pooled_transaction_element( &self, tx_hash: TxHash,