From 8951b430dae5d0a7323230255b7662d49b9a600c Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 22 Oct 2025 18:23:49 -0600 Subject: [PATCH 1/2] improve spans use in flashbots submit --- src/tasks/submit/builder_helper.rs | 3 +- src/tasks/submit/flashbots.rs | 76 ++++++++++++++++++------------ 2 files changed, 48 insertions(+), 31 deletions(-) diff --git a/src/tasks/submit/builder_helper.rs b/src/tasks/submit/builder_helper.rs index 8539f81..6bd4d02 100644 --- a/src/tasks/submit/builder_helper.rs +++ b/src/tasks/submit/builder_helper.rs @@ -262,8 +262,7 @@ impl BuilderHelperTask { let host_block_number = sim_result.host_block_number(); let span = sim_result.sim_env.span.clone(); - - span_debug!(span, "submit channel received block"); + span_debug!(span, "builder helper task received block"); // Don't submit empty blocks if sim_result.block.is_empty() { diff --git a/src/tasks/submit/flashbots.rs b/src/tasks/submit/flashbots.rs index a5a2d1a..47be28c 100644 --- a/src/tasks/submit/flashbots.rs +++ b/src/tasks/submit/flashbots.rs @@ -14,7 +14,7 @@ use alloy::{ use eyre::OptionExt; use init4_bin_base::{deps::metrics::counter, utils::signer::LocalOrAws}; use tokio::{sync::mpsc, task::JoinHandle}; -use tracing::{Instrument, debug}; +use tracing::{Instrument, debug, debug_span}; /// Handles construction, simulation, and submission of rollup blocks to the /// Flashbots network. @@ -117,40 +117,58 @@ impl FlashbotsTask { debug!("upstream task gone - exiting flashbots task"); break; }; - let span = sim_result.span(); - span_debug!(span, "received sim result"); + + let span = sim_result.sim_env.clone_span(); + + // Don't submit empty blocks + if sim_result.block.is_empty() { + counter!("signet.builder.flashbots.empty_block").increment(1); + span_debug!(span, "received empty block - skipping"); + continue; + } + span_debug!(span, "flashbots task received block"); // Prepare a MEV bundle with the configured call type from the sim result - let Ok(bundle) = - self.prepare(&sim_result).instrument(span.clone()).await.inspect_err(|error| { - counter!("signet.builder.flashbots.bundle_prep_failures").increment(1); - span_debug!(span, %error, "bundle preparation failed"); - }) - else { + let res = self.prepare(&sim_result).instrument(span.clone()).await; + let Ok(bundle) = res else { + counter!("signet.builder.flashbots.bundle_prep_failures").increment(1); + let error = res.unwrap_err(); + span_debug!(span, %error, "bundle preparation failed"); continue; }; - // Send the bundle to Flashbots - let response = self - .flashbots() - .send_mev_bundle(bundle.clone()) - .with_auth(self.signer.clone()) - .await; - - match response { - Ok(resp) => { - counter!("signet.builder.flashbots.bundles_submitted").increment(1); - span_debug!( - span, - hash = resp.map(|r| r.bundle_hash.to_string()), - "received bundle hash after submitted to flashbots" - ); - } - Err(err) => { - counter!("signet.builder.flashbots.submission_failures").increment(1); - span_error!(span, %err, "MEV bundle submission failed - error returned"); - } + // Make a child span to cover submission + let submit_span = debug_span!( + parent: &span, + "flashbots.submit", + ); + + // Send the bundle to Flashbots, instrumenting the send future so all + // events inside the async send are attributed to the submit span. + let response = async { + self.flashbots() + .send_mev_bundle(bundle.clone()) + .with_auth(self.signer.clone()) + .into_future() + .instrument(submit_span.clone()) + .await } + .await; + + let Ok(resp) = &response else { + counter!("signet.builder.flashbots.submission_failures").increment(1); + if let Err(err) = &response { + span_error!(submit_span, %err, "MEV bundle submission failed - error returned"); + } + continue; + }; + + counter!("signet.builder.flashbots.bundles_submitted").increment(1); + span_debug!( + submit_span, + hash = resp.as_ref().map(|r| r.bundle_hash.to_string()), + "received bundle hash after submitted to flashbots" + ); } } From ed532a1869ebcb56a135782165d17141f7b16277 Mon Sep 17 00:00:00 2001 From: dylan Date: Thu, 23 Oct 2025 12:00:55 -0600 Subject: [PATCH 2/2] cleanup --- src/tasks/submit/flashbots.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/tasks/submit/flashbots.rs b/src/tasks/submit/flashbots.rs index 47be28c..92cc0e4 100644 --- a/src/tasks/submit/flashbots.rs +++ b/src/tasks/submit/flashbots.rs @@ -155,20 +155,20 @@ impl FlashbotsTask { } .await; - let Ok(resp) = &response else { - counter!("signet.builder.flashbots.submission_failures").increment(1); - if let Err(err) = &response { + match response { + Ok(resp) => { + counter!("signet.builder.flashbots.bundles_submitted").increment(1); + span_debug!( + submit_span, + hash = resp.map(|r| r.bundle_hash.to_string()), + "received bundle hash after submitted to flashbots" + ); + } + Err(err) => { + counter!("signet.builder.flashbots.submission_failures").increment(1); span_error!(submit_span, %err, "MEV bundle submission failed - error returned"); } - continue; - }; - - counter!("signet.builder.flashbots.bundles_submitted").increment(1); - span_debug!( - submit_span, - hash = resp.as_ref().map(|r| r.bundle_hash.to_string()), - "received bundle hash after submitted to flashbots" - ); + } } }