Skip to content

Commit

Permalink
feat: Extend Maybeconditional with helper fn (#14511)
Browse files Browse the repository at this point in the history
  • Loading branch information
programskillforverification authored Feb 15, 2025
1 parent cb615cf commit 22badc8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 6 additions & 0 deletions crates/optimism/txpool/src/conditional.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Additional support for pooled transactions with [`TransactionConditional`]
use alloy_consensus::conditional::BlockConditionalAttributes;
use alloy_rpc_types_eth::erc4337::TransactionConditional;

/// Helper trait that allows attaching a [`TransactionConditional`].
Expand All @@ -10,6 +11,11 @@ pub trait MaybeConditionalTransaction {
/// Get attached [`TransactionConditional`] if any.
fn conditional(&self) -> Option<&TransactionConditional>;

/// Check if the conditional has exceeded the block attributes.
fn has_exceeded_block_attributes(&self, block_attr: &BlockConditionalAttributes) -> bool {
self.conditional().map(|tc| tc.has_exceeded_block_attributes(block_attr)).unwrap_or(false)
}

/// Helper that sets the conditional and returns the instance again
fn with_conditional(mut self, conditional: TransactionConditional) -> Self
where
Expand Down
6 changes: 2 additions & 4 deletions crates/optimism/txpool/src/maintain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,8 @@ where
};
let mut to_remove = Vec::new();
for tx in &pool.pooled_transactions() {
if let Some(conditional) = tx.transaction.conditional() {
if conditional.has_exceeded_block_attributes(&block_attr) {
to_remove.push(*tx.hash());
}
if tx.transaction.has_exceeded_block_attributes(&block_attr) {
to_remove.push(*tx.hash());
}
}
let _ = pool.remove_transactions(to_remove);
Expand Down

0 comments on commit 22badc8

Please sign in to comment.