feat(txpool): add skip_blob_transactions function to BestTransactions (#4455)

Co-authored-by: Matthias Seitz <matthias.seitz@outlook.de>
This commit is contained in:
Thomas Coratger
2023-09-04 17:03:55 +02:00
committed by GitHub
parent d9334ee6cf
commit 8c015c176a
3 changed files with 25 additions and 1 deletions

View File

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

View File

@ -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,
}
}

View File

@ -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<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