From 8951b430dae5d0a7323230255b7662d49b9a600c Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 22 Oct 2025 18:23:49 -0600 Subject: [PATCH 1/4] 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/4] 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" - ); + } } } From 1e6f8255654045193a1cb608b84f8b4291b20d23 Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 29 Oct 2025 13:14:13 -0600 Subject: [PATCH 3/4] cleanup --- src/tasks/submit/flashbots.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/tasks/submit/flashbots.rs b/src/tasks/submit/flashbots.rs index 92cc0e4..12f2df6 100644 --- a/src/tasks/submit/flashbots.rs +++ b/src/tasks/submit/flashbots.rs @@ -145,15 +145,13 @@ impl FlashbotsTask { // 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 response = self + .flashbots() + .send_mev_bundle(bundle.clone()) + .with_auth(self.signer.clone()) + .into_future() + .instrument(submit_span.clone()) + .await; match response { Ok(resp) => { From 92732c3f876a7532ab6721684264c43304be51c0 Mon Sep 17 00:00:00 2001 From: dylan Date: Thu, 30 Oct 2025 12:45:07 -0600 Subject: [PATCH 4/4] refactor the prepare block in flashbots task --- src/tasks/submit/flashbots.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/tasks/submit/flashbots.rs b/src/tasks/submit/flashbots.rs index 12f2df6..3da495a 100644 --- a/src/tasks/submit/flashbots.rs +++ b/src/tasks/submit/flashbots.rs @@ -129,12 +129,14 @@ impl FlashbotsTask { span_debug!(span, "flashbots task received block"); // Prepare a MEV bundle with the configured call type from the sim result - 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; + let result = + 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"); + }); + let bundle = match result { + Ok(bundle) => bundle, + Err(_) => continue, }; // Make a child span to cover submission