Skip to content

Commit

Permalink
feat(txpool): add skip_blob_transactions function to `BestTransacti…
Browse files Browse the repository at this point in the history
…ons` (paradigmxyz#4455)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
  • Loading branch information
tcoratger and mattsse authored Sep 4, 2023
1 parent d9334ee commit 8c015c1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
18 changes: 17 additions & 1 deletion crates/transaction-pool/src/pool/best.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ impl<T: TransactionOrdering> crate::traits::BestTransactions for BestTransaction
fn no_updates(&mut self) {
self.best.no_updates()
}

fn set_skip_blobs(&mut self, skip_blobs: bool) {
self.best.set_skip_blobs(skip_blobs)
}
}

impl<T: TransactionOrdering> Iterator for BestTransactionsWithBasefee<T> {
Expand Down Expand Up @@ -72,6 +76,8 @@ 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_receiver: Option<Receiver<PendingTransaction<T>>>,
/// Flag to control whether to skip blob transactions (EIP4844).
pub(crate) skip_blobs: bool,
}

impl<T: TransactionOrdering> BestTransactions<T> {
Expand Down Expand Up @@ -134,6 +140,10 @@ impl<T: TransactionOrdering> crate::traits::BestTransactions for BestTransaction
fn no_updates(&mut self) {
self.new_transaction_receiver.take();
}

fn set_skip_blobs(&mut self, skip_blobs: bool) {
self.skip_blobs = skip_blobs;
}
}

impl<T: TransactionOrdering> Iterator for BestTransactions<T> {
Expand Down Expand Up @@ -161,7 +171,13 @@ impl<T: TransactionOrdering> Iterator for BestTransactions<T> {
self.independent.insert(unlocked.clone());
}

return Some(best.transaction)
if self.skip_blobs && best.transaction.transaction.is_eip4844() {
// blobs should be skipped, marking the as invalid will ensure that no dependent
// transactions are returned
self.mark_invalid(&best.transaction)
} else {
return Some(best.transaction)
}
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/transaction-pool/src/pool/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl<T: TransactionOrdering> PendingPool<T> {
independent: self.independent_transactions.clone(),
invalid: Default::default(),
new_transaction_receiver: Some(self.new_transaction_notifier.subscribe()),
skip_blobs: false,
}
}

Expand Down
7 changes: 7 additions & 0 deletions crates/transaction-pool/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,13 +570,20 @@ pub trait BestTransactions: Iterator + Send {
/// This ensures that iterator will return the best transaction that it currently knows and not
/// listen to pool updates.
fn no_updates(&mut self);

/// Set the skip_blobs flag to control whether to skip blob transactions (is_eip4844).
///
/// This flag will control whether the iterator skips blob transactions or not.
fn set_skip_blobs(&mut self, skip_blobs: bool);
}

/// 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) {}

fn set_skip_blobs(&mut self, _skip_blobs: bool) {}
}

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

0 comments on commit 8c015c1

Please sign in to comment.