Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: use pooled AT for get_pooled_transactions #12876

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions crates/net/network/src/transactions/mod.rs
Original file line number Diff line number Diff line change
@@ -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 = ();

14 changes: 12 additions & 2 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
17 changes: 14 additions & 3 deletions crates/transaction-pool/src/noop.rs
Original file line number Diff line number Diff line change
@@ -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![]
}

20 changes: 16 additions & 4 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
11 changes: 10 additions & 1 deletion crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
@@ -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.
///