Skip to content

Commit 3d2deb5

Browse files
committed
add filters for orders
1 parent 56acf48 commit 3d2deb5

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/pool/step.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ pub struct AppendOrders<P: Platform> {
6767
/// Defaults to `true`.
6868
break_on_limit: bool,
6969

70+
/// Custom filters that can reject orders based on arbitrary criteria.
71+
/// Each filter is a function that takes the current payload checkpoint and
72+
/// an order, and returns true if the order should be included and false if
73+
/// it should be skipped.
74+
#[expect(clippy::type_complexity)]
75+
filters: Vec<Box<dyn Fn(&Checkpoint<P>, &Order<P>) -> bool + Send + Sync>>,
76+
7077
metrics: Metrics,
7178
per_job: PerJobCounters,
7279
}
@@ -83,6 +90,7 @@ impl<P: Platform> AppendOrders<P> {
8390
max_new_bundles: None,
8491
max_new_transactions: None,
8592
break_on_limit: true,
93+
filters: Vec::new(),
8694
metrics: Metrics::default(),
8795
per_job: PerJobCounters::default(),
8896
}
@@ -128,6 +136,16 @@ impl<P: Platform> AppendOrders<P> {
128136
self.break_on_limit = false;
129137
self
130138
}
139+
140+
/// Adds a custom filter that can reject orders based on arbitrary criteria.
141+
#[must_use]
142+
pub fn with_filter(
143+
mut self,
144+
filter: impl Fn(&Checkpoint<P>, &Order<P>) -> bool + Send + Sync + 'static,
145+
) -> Self {
146+
self.filters.push(Box::new(filter));
147+
self
148+
}
131149
}
132150

133151
impl<P: Platform> Step<P> for AppendOrders<P> {
@@ -323,6 +341,14 @@ impl<'a, P: Platform> Run<'a, P> {
323341
return true;
324342
}
325343

344+
// Check custom filters
345+
for filter in &self.step.filters {
346+
if !filter(&self.payload, order) {
347+
// Custom filter rejected this order
348+
return true;
349+
}
350+
}
351+
326352
let order_blob_gas = order
327353
.transactions()
328354
.iter()

0 commit comments

Comments
 (0)