Skip to content

fix: use spans properly in submit task #112

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

Closed
wants to merge 4 commits into from
Closed
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
67 changes: 20 additions & 47 deletions src/tasks/submit/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use alloy::{
use eyre::bail;
use init4_bin_base::deps::{
metrics::{counter, histogram},
tracing::{Instrument, debug, debug_span, error, info, warn},
tracing::{debug, debug_span, error, info, warn},
};
use signet_constants::SignetSystemConstants;
use std::time::Instant;
Expand Down Expand Up @@ -130,21 +130,16 @@ impl SubmitTask {
retry_limit: usize,
) -> eyre::Result<ControlFlow> {
let submitting_start_time = Instant::now();
let now = utils::now();
let (expected_slot, start, end) = self.calculate_slot_window();
debug!(expected_slot, start, end, now, "calculating target slot window");
debug!(expected_slot, start, end, "calculating target slot window");

let mut req = bumpable.req().clone();

// Retry loop
let result = loop {
let span = debug_span!(
"SubmitTask::retrying_send",
retries = bumpable.bump_count(),
nonce = bumpable.req().nonce,
);
debug!(retries = bumpable.bump_count(), nonce = ?req.nonce, "attempting transaction send");

let inbound_result = match self.send_transaction(req).instrument(span.clone()).await {
let inbound_result = match self.send_transaction(req.clone()).await {
Ok(control_flow) => control_flow,
Err(error) => {
if let Some(value) = self.slot_still_valid(expected_slot) {
Expand All @@ -156,8 +151,6 @@ impl SubmitTask {
}
};

let guard = span.entered();

match inbound_result {
ControlFlow::Retry => {
if let Some(value) = self.slot_still_valid(expected_slot) {
Expand All @@ -170,7 +163,6 @@ impl SubmitTask {
debug!("retries exceeded - skipping block");
return Ok(ControlFlow::Skip);
}
drop(guard);
debug!(retries = bumpable.bump_count(), start, end, "retrying block");
continue;
}
Expand Down Expand Up @@ -230,44 +222,33 @@ impl SubmitTask {
let ru_block_number = sim_result.block.block_number();
let host_block_number = self.constants.rollup_block_to_host_block_num(ru_block_number);

// Don't submit empty blocks
if sim_result.block.is_empty() {
debug!(ru_block_number, "received empty block - skipping");
continue;
}

// Create a span for the entire block processing operation
let span = debug_span!(
"SubmitTask::loop",
ru_block_number,
host_block_number,
block_tx_count = sim_result.block.tx_count(),
);
let guard = span.enter();

let _guard = span.enter();
debug!(ru_block_number, "submit channel received block");

// Don't submit empty blocks
if sim_result.block.is_empty() {
debug!(ru_block_number, "received empty block - skipping");
continue;
}

// drop guard before await
drop(guard);

let Ok(Some(prev_host)) = self
.provider()
.get_block_by_number(host_block_number.into())
.into_future()
.instrument(span.clone())
.await
let prev_host_number = host_block_number - 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a drive-by or was it related to the panic?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's another bug, actually, just was part of the same PR. I think it's the reason why the builder isn't submitting blocks in dev-net right now. I will build and submit this into a new PR since the span fixes are addressed in #113.

let Ok(Some(prev_host)) =
self.provider().get_block_by_number(prev_host_number.into()).into_future().await
else {
let _guard = span.enter();
warn!(ru_block_number, host_block_number, "failed to get previous host block");
continue;
};

// Prep the span we'll use for the transaction submission
let submission_span = debug_span!(
parent: span,
"SubmitTask::tx_submission",
debug!(
tx_count = sim_result.block.tx_count(),
host_block_number,
ru_block_number,
host_block_number, ru_block_number, "preparing transaction submission"
);

// Prepare the transaction request for submission
Expand All @@ -278,11 +259,7 @@ impl SubmitTask {
self.config.clone(),
self.constants,
);
let bumpable = match prep
.prep_transaction(&prev_host.header)
.instrument(submission_span.clone())
.await
{
let bumpable = match prep.prep_transaction(&prev_host.header).await {
Ok(bumpable) => bumpable,
Err(error) => {
error!(%error, "failed to prepare transaction for submission");
Expand All @@ -291,17 +268,13 @@ impl SubmitTask {
};

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

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