feat: use pooled AT for get_pooled_transactions (#12876)

This commit is contained in:
Matthias Seitz
2024-11-26 14:00:50 +01:00
committed by GitHub
parent c19b8e1a2b
commit 277631092d
5 changed files with 58 additions and 12 deletions

View File

@ -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(
@ -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
@ -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 = ();

View File

@ -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<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,

View File

@ -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<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![]
}

View File

@ -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<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());
@ -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,

View File

@ -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.
///