mirror of
https://github.com/paradigmxyz/reth.git
synced 2026-01-29 09:08:05 -05:00
feat: provide a way to opt out of pool updates (#4270)
This commit is contained in:
@@ -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> {
|
||||
@@ -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> {
|
||||
@@ -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
|
||||
@@ -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> {
|
||||
|
||||
@@ -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()),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -509,11 +509,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
|
||||
|
||||
Reference in New Issue
Block a user