@@ -23,6 +23,42 @@ use signet_constants::SignetSystemConstants;
23
23
use std:: { ops:: Range , time:: Instant } ;
24
24
use tokio:: { sync:: mpsc, task:: JoinHandle } ;
25
25
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.
26
62
macro_rules! spawn_provider_send {
27
63
( $provider: expr, $tx: expr) => {
28
64
{
@@ -37,6 +73,7 @@ macro_rules! spawn_provider_send {
37
73
} ;
38
74
}
39
75
76
+ /// Helper macro to check if the slot is still valid before submitting a block.
40
77
macro_rules! check_slot_still_valid {
41
78
( $self: expr, $initial_slot: expr) => {
42
79
if !$self. slot_still_valid( $initial_slot) {
@@ -265,25 +302,17 @@ impl SubmitTask {
265
302
// Fetch the previous host block, not the current host block which is currently being built
266
303
let prev_host_block = host_block_number - 1 ;
267
304
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
+ ) ;
287
316
288
317
// Prep the span we'll use for the transaction submission
289
318
let submission_span = debug_span ! (
@@ -302,39 +331,25 @@ impl SubmitTask {
302
331
self . config . clone ( ) ,
303
332
self . constants . clone ( ) ,
304
333
) ;
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
+ ) ;
318
339
319
340
// 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
+ ) ;
328
346
329
347
// 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
+ ) ;
338
353
}
339
354
}
340
355
0 commit comments