Skip to content

Commit

Permalink
feat: use pooled AT for get_pooled_transactions (#12876)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse authored Nov 26, 2024
1 parent c19b8e1 commit 2776310
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 12 deletions.
8 changes: 6 additions & 2 deletions crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,8 @@ impl<Pool> TransactionsManager<Pool>
where
Pool: TransactionPool + 'static,
<<Pool as TransactionPool>::Transaction as PoolTransaction>::Consensus: Into<TransactionSigned>,
<<Pool as TransactionPool>::Transaction as PoolTransaction>::Pooled:
Into<PooledTransactionsElement>,
{
/// Request handler for an incoming request for transactions
fn on_get_pooled_transactions(
Expand All @@ -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::<PooledTransactionsElement>(
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
Expand Down Expand Up @@ -1291,6 +1293,8 @@ impl<Pool> Future for TransactionsManager<Pool>
where
Pool: TransactionPool + Unpin + 'static,
<<Pool as TransactionPool>::Transaction as PoolTransaction>::Consensus: Into<TransactionSigned>,
<<Pool as TransactionPool>::Transaction as PoolTransaction>::Pooled:
Into<PooledTransactionsElement>,
{
type Output = ();

Expand Down
14 changes: 12 additions & 2 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -416,10 +415,21 @@ where
&self,
tx_hashes: Vec<TxHash>,
limit: GetPooledTransactionLimit,
) -> Vec<PooledTransactionsElement> {
) -> Vec<<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled> {
self.pool.get_pooled_transaction_elements(tx_hashes, limit)
}

fn get_pooled_transactions_as<P>(
&self,
tx_hashes: Vec<TxHash>,
limit: GetPooledTransactionLimit,
) -> Vec<P>
where
<Self::Transaction as PoolTransaction>::Pooled: Into<P>,
{
self.pool.get_pooled_transactions_as(tx_hashes, limit)
}

fn get_pooled_transaction_element(
&self,
tx_hash: TxHash,
Expand Down
17 changes: 14 additions & 3 deletions crates/transaction-pool/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -135,7 +135,18 @@ impl TransactionPool for NoopTransactionPool {
&self,
_tx_hashes: Vec<TxHash>,
_limit: GetPooledTransactionLimit,
) -> Vec<PooledTransactionsElement> {
) -> Vec<<Self::Transaction as PoolTransaction>::Pooled> {
vec![]
}

fn get_pooled_transactions_as<T>(
&self,
_tx_hashes: Vec<TxHash>,
_limit: GetPooledTransactionLimit,
) -> Vec<T>
where
<Self::Transaction as PoolTransaction>::Pooled: Into<T>,
{
vec![]
}

Expand Down
20 changes: 16 additions & 4 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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<TxHash>,
limit: GetPooledTransactionLimit,
) -> Vec<PooledTransactionsElement>
) -> Vec<<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled>
where
<V as TransactionValidator>::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<P>(
&self,
tx_hashes: Vec<TxHash>,
limit: GetPooledTransactionLimit,
) -> Vec<P>
where
<V as TransactionValidator>::Transaction: EthPoolTransaction,
<<V as TransactionValidator>::Transaction as PoolTransaction>::Pooled: Into<P>,
{
let transactions = self.get_all(tx_hashes);
let mut elements = Vec::with_capacity(transactions.len());
Expand All @@ -369,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,
Expand Down
11 changes: 10 additions & 1 deletion crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,16 @@ pub trait TransactionPool: Send + Sync + Clone {
&self,
tx_hashes: Vec<TxHash>,
limit: GetPooledTransactionLimit,
) -> Vec<PooledTransactionsElement>;
) -> Vec<<Self::Transaction as PoolTransaction>::Pooled>;

/// Returns the pooled transaction variant for the given transaction hash as the requested type.
fn get_pooled_transactions_as<T>(
&self,
tx_hashes: Vec<TxHash>,
limit: GetPooledTransactionLimit,
) -> Vec<T>
where
<Self::Transaction as PoolTransaction>::Pooled: Into<T>;

/// Returns the pooled transaction variant for the given transaction hash.
///
Expand Down

0 comments on commit 2776310

Please sign in to comment.