@@ -23,6 +23,42 @@ use signet_constants::SignetSystemConstants;
2323use std:: { ops:: Range , time:: Instant } ;
2424use tokio:: { sync:: mpsc, task:: JoinHandle } ;
2525
26+ /// Helper macro to log an event within a span that is not currently entered.
27+ macro_rules! span_scoped {
28+ ( $span: expr, $level: ident!( $( $arg: tt) * ) ) => {
29+ $span. in_scope( || {
30+ $level!( $( $arg) * ) ;
31+ } ) ;
32+ } ;
33+ }
34+
35+ /// Helper macro to unwrap a result or continue the loop with a tracing event.
36+ macro_rules! res_unwrap_or_continue {
37+ ( $result: expr, $span: expr, $level: ident!( $( $arg: tt) * ) ) => {
38+ match $result {
39+ Ok ( value) => value,
40+ Err ( err) => {
41+ span_scoped!( $span, $level!( %err, $( $arg) * ) ) ;
42+ continue ;
43+ }
44+ }
45+ } ;
46+ }
47+
48+ /// Helper macro to unwrap an option or continue the loop with a tracing event.
49+ macro_rules! opt_unwrap_or_continue {
50+ ( $option: expr, $span: expr, $level: ident!( $( $arg: tt) * ) ) => {
51+ match $option {
52+ Some ( value) => value,
53+ None => {
54+ span_scoped!( $span, $level!( $( $arg) * ) ) ;
55+ continue ;
56+ }
57+ }
58+ } ;
59+ }
60+
61+ /// Helper macro to spawn a tokio task that broadcasts a tx.
2662macro_rules! spawn_provider_send {
2763 ( $provider: expr, $tx: expr) => {
2864 {
@@ -37,6 +73,7 @@ macro_rules! spawn_provider_send {
3773 } ;
3874}
3975
76+ /// Helper macro to check if the slot is still valid before submitting a block.
4077macro_rules! check_slot_still_valid {
4178 ( $self: expr, $initial_slot: expr) => {
4279 if !$self. slot_still_valid( $initial_slot) {
@@ -265,25 +302,17 @@ impl SubmitTask {
265302 // Fetch the previous host block, not the current host block which is currently being built
266303 let prev_host_block = host_block_number - 1 ;
267304
268- let prev_host_resp = self . provider ( ) . get_block_by_number ( prev_host_block. into ( ) ) . await ;
269- let prev_host = match prev_host_resp {
270- Ok ( Some ( prev_host) ) => prev_host,
271- Ok ( None ) => {
272- span. in_scope ( || {
273- warn ! (
274- prev_host_block,
275- "previous host block not found - skipping block submission"
276- ) ;
277- } ) ;
278- continue ;
279- }
280- Err ( e) => {
281- span. in_scope ( || {
282- error ! ( %e, "error fetching previous host block - skipping block submission" ) ;
283- } ) ;
284- continue ;
285- }
286- } ;
305+ // If we encounter a provider error, log it and skip.
306+ let prev_host_resp_opt = res_unwrap_or_continue ! (
307+ self . provider( ) . get_block_by_number( prev_host_block. into( ) ) . await ,
308+ span,
309+ error!( "error fetching previous host block - skipping block submission" )
310+ ) ;
311+ let prev_host = opt_unwrap_or_continue ! (
312+ prev_host_resp_opt,
313+ span,
314+ warn!( prev_host_block, "previous host block not found - skipping block submission" )
315+ ) ;
287316
288317 // Prep the span we'll use for the transaction submission
289318 let submission_span = debug_span ! (
@@ -302,39 +331,25 @@ impl SubmitTask {
302331 self . config . clone ( ) ,
303332 self . constants . clone ( ) ,
304333 ) ;
305- let bumpable = match prep
306- . prep_transaction ( & prev_host. header )
307- . instrument ( submission_span. clone ( ) )
308- . await
309- {
310- Ok ( bumpable) => bumpable,
311- Err ( error) => {
312- submission_span. in_scope ( || {
313- error ! ( %error, "failed to prepare transaction for submission - skipping block submission" ) ;
314- } ) ;
315- continue ;
316- }
317- } ;
334+ let bumpable = res_unwrap_or_continue ! (
335+ prep. prep_transaction( & prev_host. header) . instrument( submission_span. clone( ) ) . await ,
336+ submission_span,
337+ error!( "failed to prepare transaction for submission - skipping block submission" )
338+ ) ;
318339
319340 // Simulate the transaction to check for reverts
320- if let Err ( error) =
321- self . sim_with_call ( bumpable. req ( ) ) . instrument ( submission_span. clone ( ) ) . await
322- {
323- submission_span. in_scope ( || {
324- error ! ( %error, "simulation failed for transaction - skipping block submission" ) ;
325- } ) ;
326- continue ;
327- } ;
341+ let _ = res_unwrap_or_continue ! (
342+ self . sim_with_call( bumpable. req( ) ) . instrument( submission_span. clone( ) ) . await ,
343+ submission_span,
344+ error!( "simulation failed for transaction - skipping block submission" )
345+ ) ;
328346
329347 // Now send the transaction
330- if let Err ( error) =
331- self . retrying_send ( bumpable, 3 ) . instrument ( submission_span. clone ( ) ) . await
332- {
333- submission_span. in_scope ( || {
334- error ! ( %error, "error dispatching block to host chain" ) ;
335- } ) ;
336- continue ;
337- }
348+ let _ = res_unwrap_or_continue ! (
349+ self . retrying_send( bumpable, 3 ) . instrument( submission_span. clone( ) ) . await ,
350+ submission_span,
351+ error!( "error dispatching block to host chain" )
352+ ) ;
338353 }
339354 }
340355
0 commit comments