From 8c015c176a6cf541fd81933170cea5b29cb20da9 Mon Sep 17 00:00:00 2001 From: Thomas Coratger <60488569+tcoratger@users.noreply.github.com> Date: Mon, 4 Sep 2023 17:03:55 +0200 Subject: [PATCH] feat(txpool): add `skip_blob_transactions` function to `BestTransactions` (#4455) Co-authored-by: Matthias Seitz --- crates/transaction-pool/src/pool/best.rs | 18 +++++++++++++++++- crates/transaction-pool/src/pool/pending.rs | 1 + crates/transaction-pool/src/traits.rs | 7 +++++++ 3 files changed, 25 insertions(+), 1 deletion(-) diff --git a/crates/transaction-pool/src/pool/best.rs b/crates/transaction-pool/src/pool/best.rs index 5fc5ebc93137..5b0ab07c5684 100644 --- a/crates/transaction-pool/src/pool/best.rs +++ b/crates/transaction-pool/src/pool/best.rs @@ -29,6 +29,10 @@ impl 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 Iterator for BestTransactionsWithBasefee { @@ -72,6 +76,8 @@ pub(crate) struct BestTransactions { /// These new pending transactions are inserted into this iterator's pool before yielding the /// next value pub(crate) new_transaction_receiver: Option>>, + /// Flag to control whether to skip blob transactions (EIP4844). + pub(crate) skip_blobs: bool, } impl BestTransactions { @@ -134,6 +140,10 @@ impl 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 Iterator for BestTransactions { @@ -161,7 +171,13 @@ impl Iterator for BestTransactions { 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) + } } } } diff --git a/crates/transaction-pool/src/pool/pending.rs b/crates/transaction-pool/src/pool/pending.rs index 65be2a7c1e85..0708f1c8840e 100644 --- a/crates/transaction-pool/src/pool/pending.rs +++ b/crates/transaction-pool/src/pool/pending.rs @@ -89,6 +89,7 @@ impl PendingPool { independent: self.independent_transactions.clone(), invalid: Default::default(), new_transaction_receiver: Some(self.new_transaction_notifier.subscribe()), + skip_blobs: false, } } diff --git a/crates/transaction-pool/src/traits.rs b/crates/transaction-pool/src/traits.rs index 862ce14baab9..506ced4941e6 100644 --- a/crates/transaction-pool/src/traits.rs +++ b/crates/transaction-pool/src/traits.rs @@ -570,6 +570,11 @@ 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. @@ -577,6 +582,8 @@ impl BestTransactions for std::iter::Empty { 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