Skip to content

Commit

Permalink
feat: add pending|queued txs pool helpers (#12128)
Browse files Browse the repository at this point in the history
  • Loading branch information
lean-apple authored Oct 28, 2024
1 parent 9c92761 commit 6e7a2a4
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 1 deletion.
14 changes: 14 additions & 0 deletions crates/transaction-pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,20 @@ where
self.pool.get_transactions_by_sender(sender)
}

fn get_pending_transactions_by_sender(
&self,
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.pool.get_pending_transactions_by_sender(sender)
}

fn get_queued_transactions_by_sender(
&self,
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
self.pool.get_queued_transactions_by_sender(sender)
}

fn get_highest_transaction_by_sender(
&self,
sender: Address,
Expand Down
14 changes: 14 additions & 0 deletions crates/transaction-pool/src/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ impl TransactionPool for NoopTransactionPool {
vec![]
}

fn get_pending_transactions_by_sender(
&self,
_sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}

fn get_queued_transactions_by_sender(
&self,
_sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>> {
vec![]
}

fn get_highest_transaction_by_sender(
&self,
_sender: Address,
Expand Down
18 changes: 18 additions & 0 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,24 @@ where
self.get_pool_data().get_transactions_by_sender(sender_id)
}

/// Returns all queued transactions of the address by sender
pub(crate) fn get_queued_transactions_by_sender(
&self,
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
let sender_id = self.get_sender_id(sender);
self.get_pool_data().pending_txs_by_sender(sender_id)
}

/// Returns all pending transactions of the address by sender
pub(crate) fn get_pending_transactions_by_sender(
&self,
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
let sender_id = self.get_sender_id(sender);
self.get_pool_data().queued_txs_by_sender(sender_id)
}

/// Returns the highest transaction of the address
pub(crate) fn get_highest_transaction_by_sender(
&self,
Expand Down
23 changes: 23 additions & 0 deletions crates/transaction-pool/src/pool/txpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,26 @@ impl<T: TransactionOrdering> TxPool<T> {
self.pending_pool.all()
}

/// Returns all pending transactions for the specified sender
pub(crate) fn pending_txs_by_sender(
&self,
sender: SenderId,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.pending_transactions_iter().filter(|tx| tx.sender_id() == sender).collect()
}

/// Returns all transactions from parked pools
pub(crate) fn queued_transactions(&self) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.basefee_pool.all().chain(self.queued_pool.all()).collect()
}

/// Returns an iterator over all transactions from parked pools
pub(crate) fn queued_transactions_iter(
&self,
) -> impl Iterator<Item = Arc<ValidPoolTransaction<T::Transaction>>> + '_ {
self.basefee_pool.all().chain(self.queued_pool.all())
}

/// Returns queued and pending transactions for the specified sender
pub fn queued_and_pending_txs_by_sender(
&self,
Expand All @@ -377,6 +392,14 @@ impl<T: TransactionOrdering> TxPool<T> {
(self.queued_pool.get_txs_by_sender(sender), self.pending_pool.get_txs_by_sender(sender))
}

/// Returns all queued transactions for the specified sender
pub(crate) fn queued_txs_by_sender(
&self,
sender: SenderId,
) -> Vec<Arc<ValidPoolTransaction<T::Transaction>>> {
self.queued_transactions_iter().filter(|tx| tx.sender_id() == sender).collect()
}

/// Returns `true` if the transaction with the given hash is already included in this pool.
pub(crate) fn contains(&self, tx_hash: &TxHash) -> bool {
self.all_transactions.contains(tx_hash)
Expand Down
14 changes: 13 additions & 1 deletion crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,18 @@ pub trait TransactionPool: Send + Sync + Clone {
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;

/// Returns all pending transactions sent by a given user
fn get_pending_transactions_by_sender(
&self,
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;

/// Returns all queued transactions sent by a given user
fn get_queued_transactions_by_sender(
&self,
sender: Address,
) -> Vec<Arc<ValidPoolTransaction<Self::Transaction>>>;

/// Returns the highest transaction sent by a given user
fn get_highest_transaction_by_sender(
&self,
Expand Down Expand Up @@ -1332,7 +1344,7 @@ impl TryFrom<TransactionSignedEcRecovered> for EthPooledTransaction {
}
EIP4844_TX_TYPE_ID => {
// doesn't have a blob sidecar
return Err(TryFromRecoveredTransactionError::BlobSidecarMissing)
return Err(TryFromRecoveredTransactionError::BlobSidecarMissing);
}
unsupported => {
// unsupported transaction type
Expand Down

0 comments on commit 6e7a2a4

Please sign in to comment.