From e74f185d95df7a18734899826890dbd12811cb36 Mon Sep 17 00:00:00 2001 From: Matthias Seitz Date: Thu, 24 Oct 2024 15:28:25 +0200 Subject: [PATCH] feat: add BestTransactions::filter_transactions (#12041) --- crates/transaction-pool/src/traits.rs | 13 +++++++++++++ crates/transaction-pool/tests/it/best.rs | 10 ++++++++++ crates/transaction-pool/tests/it/main.rs | 2 ++ 3 files changed, 25 insertions(+) create mode 100644 crates/transaction-pool/tests/it/best.rs diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index eb9d35ad5..fa5e22ec0 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -761,6 +761,19 @@ pub trait BestTransactions: Iterator + Send { /// /// If set to true, no blob transactions will be returned. fn set_skip_blobs(&mut self, skip_blobs: bool); + + /// Creates an iterator which uses a closure to determine whether a transaction should be + /// returned by the iterator. + /// + /// All items the closure returns false for are marked as invalid via [`Self::mark_invalid`] and + /// descendant transactions will be skipped. + fn filter_transactions

(self, predicate: P) -> BestTransactionFilter + where + P: FnMut(&Self::Item) -> bool, + Self: Sized, + { + BestTransactionFilter::new(self, predicate) + } } impl BestTransactions for Box diff --git a/crates/transaction-pool/tests/it/best.rs b/crates/transaction-pool/tests/it/best.rs new file mode 100644 index 000000000..cd7a93eae --- /dev/null +++ b/crates/transaction-pool/tests/it/best.rs @@ -0,0 +1,10 @@ +//! Best transaction and filter testing + +use reth_transaction_pool::{noop::NoopTransactionPool, BestTransactions, TransactionPool}; + +#[test] +fn test_best_transactions() { + let noop = NoopTransactionPool::default(); + let mut best = noop.best_transactions().filter_transactions(|_| true); + assert!(best.next().is_none()); +} diff --git a/crates/transaction-pool/tests/it/main.rs b/crates/transaction-pool/tests/it/main.rs index ead33a328..7db2b14c9 100644 --- a/crates/transaction-pool/tests/it/main.rs +++ b/crates/transaction-pool/tests/it/main.rs @@ -9,4 +9,6 @@ mod listeners; #[cfg(feature = "test-utils")] mod pending; +mod best; + const fn main() {}