Skip to content

Commit 4a5aa7e

Browse files
prestwichdylanlott
authored andcommitted
chore: DRY
1 parent e80801d commit 4a5aa7e

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

src/tasks/submit/task.rs

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -302,25 +302,17 @@ impl SubmitTask {
302302
// Fetch the previous host block, not the current host block which is currently being built
303303
let prev_host_block = host_block_number - 1;
304304

305-
let prev_host_resp = self.provider().get_block_by_number(prev_host_block.into()).await;
306-
let prev_host = match prev_host_resp {
307-
Ok(Some(prev_host)) => prev_host,
308-
Ok(None) => {
309-
span.in_scope(|| {
310-
warn!(
311-
prev_host_block,
312-
"previous host block not found - skipping block submission"
313-
);
314-
});
315-
continue;
316-
}
317-
Err(e) => {
318-
span.in_scope(|| {
319-
error!(%e, "error fetching previous host block - skipping block submission");
320-
});
321-
continue;
322-
}
323-
};
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+
);
324316

325317
// Prep the span we'll use for the transaction submission
326318
let submission_span = debug_span!(
@@ -339,29 +331,18 @@ impl SubmitTask {
339331
self.config.clone(),
340332
self.constants.clone(),
341333
);
342-
let bumpable = match prep
343-
.prep_transaction(&prev_host.header)
344-
.instrument(submission_span.clone())
345-
.await
346-
{
347-
Ok(bumpable) => bumpable,
348-
Err(error) => {
349-
submission_span.in_scope(|| {
350-
error!(%error, "failed to prepare transaction for submission - skipping block submission");
351-
});
352-
continue;
353-
}
354-
};
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+
);
355339

356340
// Simulate the transaction to check for reverts
357-
if let Err(error) =
358-
self.sim_with_call(bumpable.req()).instrument(submission_span.clone()).await
359-
{
360-
submission_span.in_scope(|| {
361-
error!(%error, "simulation failed for transaction - skipping block submission");
362-
});
363-
continue;
364-
};
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+
);
365346

366347
// Now send the transaction
367348
let _ = res_unwrap_or_continue!(

0 commit comments

Comments
 (0)