@@ -67,6 +67,12 @@ 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+ filters : Vec < Box < dyn Fn ( & Checkpoint < P > , & Order < P > ) -> bool + Send + Sync > > ,
75+
7076 metrics : Metrics ,
7177 per_job : PerJobCounters ,
7278}
@@ -83,6 +89,7 @@ impl<P: Platform> AppendOrders<P> {
8389 max_new_bundles : None ,
8490 max_new_transactions : None ,
8591 break_on_limit : true ,
92+ filters : Vec :: new ( ) ,
8693 metrics : Metrics :: default ( ) ,
8794 per_job : PerJobCounters :: default ( ) ,
8895 }
@@ -128,6 +135,16 @@ impl<P: Platform> AppendOrders<P> {
128135 self . break_on_limit = false ;
129136 self
130137 }
138+
139+ /// Adds a custom filter that can reject orders based on arbitrary criteria.
140+ #[ must_use]
141+ pub fn with_filter (
142+ mut self ,
143+ filter : impl Fn ( & Checkpoint < P > , & Order < P > ) -> bool + Send + Sync + ' static ,
144+ ) -> Self {
145+ self . filters . push ( Box :: new ( filter) ) ;
146+ self
147+ }
131148}
132149
133150impl < P : Platform > Step < P > for AppendOrders < P > {
@@ -323,6 +340,14 @@ impl<'a, P: Platform> Run<'a, P> {
323340 return true ;
324341 }
325342
343+ // Check custom filters
344+ for filter in & self . step . filters {
345+ if !filter ( & self . payload , order) {
346+ // Custom filter rejected this order
347+ return true ;
348+ }
349+ }
350+
326351 let order_blob_gas = order
327352 . transactions ( )
328353 . iter ( )
0 commit comments