Skip to content
Merged
Show file tree
Hide file tree
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
12 changes: 10 additions & 2 deletions crates/transaction-pool/src/pool/best.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ impl<T: TransactionOrdering> crate::traits::BestTransactions for BestTransaction
fn mark_invalid(&mut self, tx: &Self::Item) {
BestTransactions::mark_invalid(&mut self.best, tx)
}

fn no_updates(&mut self) {
self.best.no_updates()
}
}

impl<T: TransactionOrdering> Iterator for BestTransactionsWithBasefee<T> {
Expand Down Expand Up @@ -67,7 +71,7 @@ pub(crate) struct BestTransactions<T: TransactionOrdering> {
///
/// These new pending transactions are inserted into this iterator's pool before yielding the
/// next value
pub(crate) new_transaction_reciever: Receiver<PendingTransaction<T>>,
pub(crate) new_transaction_receiver: Option<Receiver<PendingTransaction<T>>>,
}

impl<T: TransactionOrdering> BestTransactions<T> {
Expand All @@ -87,7 +91,7 @@ impl<T: TransactionOrdering> BestTransactions<T> {
/// Non-blocking read on the new pending transactions subscription channel
fn try_recv(&mut self) -> Option<PendingTransaction<T>> {
loop {
match self.new_transaction_reciever.try_recv() {
match self.new_transaction_receiver.as_mut()?.try_recv() {
Ok(tx) => return Some(tx),
// note TryRecvError::Lagged can be returned here, which is an error that attempts
// to correct itself on consecutive try_recv() attempts
Expand Down Expand Up @@ -126,6 +130,10 @@ impl<T: TransactionOrdering> crate::traits::BestTransactions for BestTransaction
fn mark_invalid(&mut self, tx: &Self::Item) {
BestTransactions::mark_invalid(self, tx)
}

fn no_updates(&mut self) {
self.new_transaction_receiver.take();
}
}

impl<T: TransactionOrdering> Iterator for BestTransactions<T> {
Expand Down
2 changes: 1 addition & 1 deletion crates/transaction-pool/src/pool/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ impl<T: TransactionOrdering> PendingPool<T> {
all: self.by_id.clone(),
independent: self.independent_transactions.clone(),
invalid: Default::default(),
new_transaction_reciever: self.new_transaction_notifier.subscribe(),
new_transaction_receiver: Some(self.new_transaction_notifier.subscribe()),
}
}

Expand Down
9 changes: 9 additions & 0 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -487,11 +487,20 @@ pub trait BestTransactions: Iterator + Send {
/// In other words, this must remove the given transaction _and_ drain all transaction that
/// depend on it.
fn mark_invalid(&mut self, transaction: &Self::Item);

/// An iterator may be able to receive additional pending transactions that weren't present it
/// the pool when it was created.
///
/// This ensures that iterator will return the best transaction that it currently knows and not
/// listen to pool updates.
fn no_updates(&mut self);
}

/// A no-op implementation that yields no transactions.
impl<T> BestTransactions for std::iter::Empty<T> {
fn mark_invalid(&mut self, _tx: &T) {}

fn no_updates(&mut self) {}
}

/// Trait for transaction types used inside the pool
Expand Down