@@ -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,18 +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 Ok ( Some ( prev_host) ) = self
269
- . provider ( )
270
- . get_block_by_number ( prev_host_block. into ( ) )
271
- . into_future ( )
272
- . instrument ( span. clone ( ) )
273
- . await
274
- else {
275
- span. in_scope ( || {
276
- warn ! ( ru_block_number, host_block_number, "failed to get previous host block" )
277
- } ) ;
278
- continue ;
279
- } ;
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
+ ) ;
280
316
281
317
// Prep the span we'll use for the transaction submission
282
318
let submission_span = debug_span ! (
@@ -295,39 +331,25 @@ impl SubmitTask {
295
331
self . config . clone ( ) ,
296
332
self . constants . clone ( ) ,
297
333
) ;
298
- let bumpable = match prep
299
- . prep_transaction ( & prev_host. header )
300
- . instrument ( submission_span. clone ( ) )
301
- . await
302
- {
303
- Ok ( bumpable) => bumpable,
304
- Err ( error) => {
305
- submission_span. in_scope ( || {
306
- error ! ( %error, "failed to prepare transaction for submission" ) ;
307
- } ) ;
308
- continue ;
309
- }
310
- } ;
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
+ ) ;
311
339
312
340
// Simulate the transaction to check for reverts
313
- if let Err ( error) =
314
- self . sim_with_call ( bumpable. req ( ) ) . instrument ( submission_span. clone ( ) ) . await
315
- {
316
- submission_span. in_scope ( || {
317
- error ! ( %error, "simulation failed for transaction" ) ;
318
- } ) ;
319
- continue ;
320
- } ;
341
+ 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
+ ) ;
321
346
322
347
// Now send the transaction
323
- if let Err ( error) =
324
- self . retrying_send ( bumpable, 3 ) . instrument ( submission_span. clone ( ) ) . await
325
- {
326
- submission_span. in_scope ( || {
327
- error ! ( %error, "error dispatching block to host chain" ) ;
328
- } ) ;
329
- continue ;
330
- }
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
+ ) ;
331
353
}
332
354
}
333
355
0 commit comments