Skip to content

feat: improve tracing when failing to retrieve a host block #141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
104 changes: 63 additions & 41 deletions src/tasks/submit/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,42 @@ use signet_constants::SignetSystemConstants;
use std::{ops::Range, time::Instant};
use tokio::{sync::mpsc, task::JoinHandle};

/// Helper macro to log an event within a span that is not currently entered.
macro_rules! span_scoped {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have a bunch of utility macros across all of our repos and i wonder at which point we might wanna pull the most useful ones into somewhere like bin-base

($span:expr, $level:ident!($($arg:tt)*)) => {
$span.in_scope(|| {
$level!($($arg)*);
});
};
}

/// Helper macro to unwrap a result or continue the loop with a tracing event.
macro_rules! res_unwrap_or_continue {
($result:expr, $span:expr, $level:ident!($($arg:tt)*)) => {
match $result {
Ok(value) => value,
Err(err) => {
span_scoped!($span, $level!(%err, $($arg)*));
continue;
}
}
};
}

/// Helper macro to unwrap an option or continue the loop with a tracing event.
macro_rules! opt_unwrap_or_continue {
($option:expr, $span:expr, $level:ident!($($arg:tt)*)) => {
match $option {
Some(value) => value,
None => {
span_scoped!($span, $level!($($arg)*));
continue;
}
}
};
}

/// Helper macro to spawn a tokio task that broadcasts a tx.
macro_rules! spawn_provider_send {
($provider:expr, $tx:expr) => {
{
Expand All @@ -37,6 +73,7 @@ macro_rules! spawn_provider_send {
};
}

/// Helper macro to check if the slot is still valid before submitting a block.
macro_rules! check_slot_still_valid {
($self:expr, $initial_slot:expr) => {
if !$self.slot_still_valid($initial_slot) {
Expand Down Expand Up @@ -265,18 +302,17 @@ impl SubmitTask {
// Fetch the previous host block, not the current host block which is currently being built
let prev_host_block = host_block_number - 1;

let Ok(Some(prev_host)) = self
.provider()
.get_block_by_number(prev_host_block.into())
.into_future()
.instrument(span.clone())
.await
else {
span.in_scope(|| {
warn!(ru_block_number, host_block_number, "failed to get previous host block")
});
continue;
};
// If we encounter a provider error, log it and skip.
let prev_host_resp_opt = res_unwrap_or_continue!(
self.provider().get_block_by_number(prev_host_block.into()).await,
span,
error!("error fetching previous host block - skipping block submission")
);
let prev_host = opt_unwrap_or_continue!(
prev_host_resp_opt,
span,
warn!(prev_host_block, "previous host block not found - skipping block submission")
);

// Prep the span we'll use for the transaction submission
let submission_span = debug_span!(
Expand All @@ -295,39 +331,25 @@ impl SubmitTask {
self.config.clone(),
self.constants.clone(),
);
let bumpable = match prep
.prep_transaction(&prev_host.header)
.instrument(submission_span.clone())
.await
{
Ok(bumpable) => bumpable,
Err(error) => {
submission_span.in_scope(|| {
error!(%error, "failed to prepare transaction for submission");
});
continue;
}
};
let bumpable = res_unwrap_or_continue!(
prep.prep_transaction(&prev_host.header).instrument(submission_span.clone()).await,
submission_span,
error!("failed to prepare transaction for submission - skipping block submission")
);

// Simulate the transaction to check for reverts
if let Err(error) =
self.sim_with_call(bumpable.req()).instrument(submission_span.clone()).await
{
submission_span.in_scope(|| {
error!(%error, "simulation failed for transaction");
});
continue;
};
res_unwrap_or_continue!(
self.sim_with_call(bumpable.req()).instrument(submission_span.clone()).await,
submission_span,
error!("simulation failed for transaction - skipping block submission")
);

// Now send the transaction
if let Err(error) =
self.retrying_send(bumpable, 3).instrument(submission_span.clone()).await
{
submission_span.in_scope(|| {
error!(%error, "error dispatching block to host chain");
});
continue;
}
let _ = res_unwrap_or_continue!(
self.retrying_send(bumpable, 3).instrument(submission_span.clone()).await,
submission_span,
error!("error dispatching block to host chain")
);
}
}

Expand Down