perf(txpool): filter by sender id (#2080)

This commit is contained in:
Matthias Seitz
2023-04-02 20:39:28 +02:00
committed by GitHub
parent 481f60acee
commit 10af3ab8cf
4 changed files with 12 additions and 14 deletions

View File

@@ -5,6 +5,7 @@ use std::collections::HashMap;
/// An internal mapping of addresses.
///
/// This assigns a _unique_ `SenderId` for a new `Address`.
/// It has capacity for 2^64 unique addresses.
#[derive(Debug, Default)]
pub(crate) struct SenderIdentifiers {
/// The identifier to use next.
@@ -57,7 +58,6 @@ pub struct SenderId(u64);
impl SenderId {
/// Returns a `Bound` for `TransactionId` starting with nonce `0`
#[cfg(test)]
pub(crate) fn start_bound(self) -> std::ops::Bound<TransactionId> {
std::ops::Bound::Included(TransactionId::new(self, 0))
}

View File

@@ -330,12 +330,7 @@ where
&self,
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.pool
.pooled_transactions()
.iter()
.filter(|tx| tx.transaction.sender().eq(&sender))
.map(Arc::clone)
.collect()
self.pool.get_transactions_by_sender(sender)
}
}

View File

@@ -379,11 +379,8 @@ where
&self,
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.pooled_transactions()
.iter()
.filter(|tx| tx.transaction.sender().eq(&sender))
.map(Arc::clone)
.collect()
let sender_id = self.get_sender_id(sender);
self.pool.read().get_transactions_by_sender(sender_id)
}
/// Returns all the transactions belonging to the hashes.

View File

@@ -161,6 +161,14 @@ impl<T: TransactionOrdering> TxPool<T> {
txs.into_iter().filter_map(|tx| self.get(&tx))
}
/// Returns all transactions sent from the given sender.
pub(crate) fn get_transactions_by_sender(
&self,
sender: SenderId,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.all_transactions.txs_iter(sender).map(|(_, tx)| Arc::clone(&tx.transaction)).collect()
}
/// Updates the entire pool after a new block was mined.
///
/// This removes all mined transactions, updates according to the new base fee and rechecks
@@ -688,8 +696,6 @@ impl<T: PoolTransaction> AllTransactions<T> {
/// Returns an iterator over all transactions for the given sender, starting with the lowest
/// nonce
#[cfg(test)]
#[allow(unused)]
pub(crate) fn txs_iter(
&self,
sender: SenderId,