@@ -48,7 +48,30 @@ pub struct SimResult {
4848 /// The block built with the successfully simulated transactions
4949 pub block : BuiltBlock ,
5050 /// The block environment the transactions were simulated against.
51- pub env : SimEnv ,
51+ pub sim_env : SimEnv ,
52+ }
53+
54+ impl SimResult {
55+ /// Returns the block number of the built block.
56+ pub const fn block_number ( & self ) -> u64 {
57+ self . block . block_number ( )
58+ }
59+
60+ /// Returns the host block number for the built block.
61+ pub const fn host_block_number ( & self ) -> u64 {
62+ self . sim_env . host_block_number ( )
63+ }
64+
65+ /// Returns a reference to the tracing span associated with this simulation
66+ /// result.
67+ pub const fn span ( & self ) -> & tracing:: Span {
68+ self . sim_env . span ( )
69+ }
70+
71+ /// Clones the span for use in other tasks.
72+ pub fn clone_span ( & self ) -> tracing:: Span {
73+ self . sim_env . clone_span ( )
74+ }
5275}
5376
5477impl Simulator {
@@ -182,27 +205,31 @@ impl Simulator {
182205 return ;
183206 }
184207 let Some ( sim_env) = self . sim_env . borrow_and_update ( ) . clone ( ) else { return } ;
185- let block_number = sim_env. block_env . number . to :: < u64 > ( ) ;
186- info ! ( block_number, "new block environment received" ) ;
208+
209+ let span = sim_env. span ( ) ;
210+
211+ span. in_scope ( || {
212+ info ! ( "new block environment received" ) ;
213+ } ) ;
187214
188215 // Calculate the deadline for this block simulation.
189216 // NB: This must happen _after_ taking a reference to the sim cache,
190217 // waiting for a new block, and checking current slot authorization.
191218 let finish_by = self . calculate_deadline ( ) ;
192219 let sim_cache = cache. clone ( ) ;
193- match self
220+
221+ let Ok ( block) = self
194222 . handle_build ( constants. clone ( ) , sim_cache, finish_by, sim_env. block_env . clone ( ) )
223+ . instrument ( span. clone ( ) )
195224 . await
196- {
197- Ok ( block) => {
198- debug ! ( block = ?block. block_number( ) , tx_count = block. transactions( ) . len( ) , "built simulated block" ) ;
199- let _ = submit_sender. send ( SimResult { block, env : sim_env } ) ;
200- }
201- Err ( e) => {
202- error ! ( err = %e, "failed to build block" ) ;
203- continue ;
204- }
205- }
225+ . inspect_err ( |err| span. in_scope ( || error ! ( %err, "error during block build" ) ) )
226+ else {
227+ continue ;
228+ } ;
229+
230+ let _guard = span. clone ( ) . entered ( ) ;
231+ debug ! ( block = ?block. block_number( ) , tx_count = block. transactions( ) . len( ) , "built simulated block" ) ;
232+ let _ = submit_sender. send ( SimResult { block, sim_env } ) ;
206233 }
207234 }
208235
0 commit comments