1- use  alloy_primitives:: { utils:: format_ether,  U256 } ; 
1+ use  alloy_primitives:: { utils:: format_ether,  Address ,   TxHash ,   U256 } ; 
22use  reth_provider:: StateProvider ; 
33use  std:: { 
44    cmp:: max, 
@@ -7,7 +7,7 @@ use std::{
77} ; 
88use  time:: OffsetDateTime ; 
99use  tokio_util:: sync:: CancellationToken ; 
10- use  tracing:: { debug,  error,  trace} ; 
10+ use  tracing:: { debug,  error,  trace,  warn } ; 
1111
1212use  crate :: { 
1313    building:: { 
@@ -21,7 +21,10 @@ use crate::{
2121    telemetry:: { self ,  add_block_fill_time,  add_order_simulation_time} , 
2222    utils:: { check_block_hash_reader_health,  elapsed_ms,  HistoricalBlockError } , 
2323} ; 
24- use  rbuilder_primitives:: { order_statistics:: OrderStatistics ,  SimValue ,  SimulatedOrder } ; 
24+ use  rbuilder_primitives:: { 
25+     order_statistics:: OrderStatistics ,  SimValue ,  SimulatedOrder , 
26+     TransactionSignedEcRecoveredWithBlobs , 
27+ } ; 
2528
2629use  super :: Block ; 
2730
@@ -157,6 +160,10 @@ pub struct BlockBuildingHelperFromProvider<
157160     cancel_on_fatal_error :  CancellationToken , 
158161
159162    finalize_adjustment_state :  Option < FinalizeAdjustmentState > , 
163+ 
164+     /// If an order execution duration (commit_order) is greater than this, we will log a warning with some info about the order. 
165+      /// This probably should not be implemented here and should be a wrapper but this is simpler. 
166+      max_order_execution_duration_warning :  Option < Duration > , 
160167} 
161168
162169#[ derive( Debug ,  thiserror:: Error ) ]  
@@ -209,6 +216,7 @@ impl BlockBuildingHelperFromProvider<NullPartialBlockExecutionTracer> {
209216        discard_txs :  bool , 
210217        available_orders_statistics :  OrderStatistics , 
211218        cancel_on_fatal_error :  CancellationToken , 
219+         max_order_execution_duration_warning :  Option < Duration > , 
212220    )  -> Result < Self ,  BlockBuildingHelperError >  { 
213221        BlockBuildingHelperFromProvider :: new_with_execution_tracer ( 
214222            built_block_id, 
@@ -220,6 +228,7 @@ impl BlockBuildingHelperFromProvider<NullPartialBlockExecutionTracer> {
220228            available_orders_statistics, 
221229            cancel_on_fatal_error, 
222230            NullPartialBlockExecutionTracer  { } , 
231+             max_order_execution_duration_warning, 
223232        ) 
224233    } 
225234} 
@@ -244,6 +253,7 @@ impl<
244253        available_orders_statistics :  OrderStatistics , 
245254        cancel_on_fatal_error :  CancellationToken , 
246255        partial_block_execution_tracer :  PartialBlockExecutionTracerType , 
256+         max_order_execution_duration_warning :  Option < Duration > , 
247257    )  -> Result < Self ,  BlockBuildingHelperError >  { 
248258        let  last_committed_block = building_ctx. block ( )  - 1 ; 
249259        check_block_hash_reader_health ( last_committed_block,  & state_provider) ?; 
@@ -280,6 +290,7 @@ impl<
280290            built_block_trace, 
281291            cancel_on_fatal_error, 
282292            finalize_adjustment_state :  None , 
293+             max_order_execution_duration_warning, 
283294        } ) 
284295    } 
285296
@@ -464,6 +475,52 @@ impl<
464475        } ; 
465476        Ok ( FinalizeBlockResult  {  block } ) 
466477    } 
478+ 
479+     fn  trace_slow_order_execution ( 
480+         & self , 
481+         order :  & SimulatedOrder , 
482+         sim_time :  Duration , 
483+         result :  & Result < Result < ExecutionResult ,  ExecutionError > ,  CriticalCommitOrderError > , 
484+     )  { 
485+         #[ derive( Debug ) ]  
486+         #[ allow( dead_code) ]  
487+         struct  TxInfo  { 
488+             pub  hash :  TxHash , 
489+             pub  signer :  Address , 
490+             pub  to :  Option < Address > , 
491+         } 
492+         impl  From < & TransactionSignedEcRecoveredWithBlobs >  for  TxInfo  { 
493+             fn  from ( tx :  & TransactionSignedEcRecoveredWithBlobs )  -> Self  { 
494+                 Self  { 
495+                     hash :  tx. hash ( ) , 
496+                     signer :  tx. signer ( ) , 
497+                     to :  tx. to ( ) , 
498+                 } 
499+             } 
500+         } 
501+         impl  TxInfo  { 
502+             fn  parse_order ( order :  & SimulatedOrder )  -> Vec < Self >  { 
503+                 order
504+                     . order 
505+                     . list_txs ( ) 
506+                     . iter ( ) 
507+                     . map ( |( tx,  _) | ( * tx) . into ( ) ) 
508+                     . collect :: < Vec < _ > > ( ) 
509+             } 
510+         } 
511+         match  result { 
512+             Ok ( Ok ( result) )  => { 
513+                 warn ! ( ?sim_time, builder_name=self . builder_name, id = ?order. id( ) , tob_sim_value = ?order. sim_value, txs = ?TxInfo :: parse_order( order) , 
514+                     space_used = ?result. space_used, coinbase_profit = ?result. coinbase_profit, inplace_sim = ?result. inplace_sim,  "Slow order ok execution" ) ; 
515+             } 
516+             Ok ( Err ( err) )  => { 
517+                 warn ! ( ?err, ?sim_time, builder_name=self . builder_name, id = ?order. id( ) , tob_sim_value = ?order. sim_value, txs = ?TxInfo :: parse_order( order) ,  "Slow order failed execution." ) ; 
518+             } 
519+             Err ( err)  => { 
520+                 warn ! ( ?err, ?sim_time, builder_name=self . builder_name, id = ?order. id( ) , tob_sim_value = ?order. sim_value, txs = ?TxInfo :: parse_order( order) ,  "Slow order critical execution error." ) ; 
521+             } 
522+         } 
523+     } 
467524} 
468525
469526impl < 
@@ -487,6 +544,13 @@ impl<
487544            result_filter, 
488545        ) ; 
489546        let  sim_time = start. elapsed ( ) ; 
547+         if  self 
548+             . max_order_execution_duration_warning 
549+             . is_some_and ( |max_dur| sim_time > max_dur) 
550+         { 
551+             self . trace_slow_order_execution ( order,  sim_time,  & result) ; 
552+         } 
553+ 
490554        let  ( result,  sim_ok)  = match  result { 
491555            Ok ( ok_result)  => match  ok_result { 
492556                Ok ( res)  => { 
0 commit comments