Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions src/pool/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ pub struct AppendOrders<P: Platform> {
/// Defaults to `true`.
break_on_limit: bool,

/// Custom filters that can reject orders based on arbitrary criteria.
/// Each filter is a function that takes the current payload checkpoint and
/// an order, and returns true if the order should be included and false if
/// it should be skipped.
#[expect(clippy::type_complexity)]
filters: Vec<Box<dyn Fn(&Checkpoint<P>, &Order<P>) -> bool + Send + Sync>>,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you move it out to its own type


metrics: Metrics,
per_job: PerJobCounters,
}
Expand All @@ -83,6 +90,7 @@ impl<P: Platform> AppendOrders<P> {
max_new_bundles: None,
max_new_transactions: None,
break_on_limit: true,
filters: Vec::new(),
metrics: Metrics::default(),
per_job: PerJobCounters::default(),
}
Expand Down Expand Up @@ -128,6 +136,16 @@ impl<P: Platform> AppendOrders<P> {
self.break_on_limit = false;
self
}

/// Adds a custom filter that can reject orders based on arbitrary criteria.
#[must_use]
pub fn with_filter(
mut self,
filter: impl Fn(&Checkpoint<P>, &Order<P>) -> bool + Send + Sync + 'static,
) -> Self {
self.filters.push(Box::new(filter));
self
}
}

impl<P: Platform> Step<P> for AppendOrders<P> {
Expand Down Expand Up @@ -323,6 +341,14 @@ impl<'a, P: Platform> Run<'a, P> {
return true;
}

// Check custom filters
for filter in &self.step.filters {
if !filter(&self.payload, order) {
// Custom filter rejected this order
return true;
}
}

let order_blob_gas = order
.transactions()
.iter()
Expand Down
Loading