From 6f08a517e786c9d771bb727b0377134e8059e0e6 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 22 Sep 2025 12:53:45 -0400 Subject: [PATCH 1/2] refactor: refine the task loop and span it --- src/tasks/submit/flashbots/task.rs | 51 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/src/tasks/submit/flashbots/task.rs b/src/tasks/submit/flashbots/task.rs index b98bfc0a..002e2107 100644 --- a/src/tasks/submit/flashbots/task.rs +++ b/src/tasks/submit/flashbots/task.rs @@ -20,6 +20,7 @@ use signet_constants::SignetSystemConstants; use signet_types::SignRequest; use signet_zenith::{Alloy2718Coder, Zenith::BlockHeader, ZenithBlock}; use tokio::{sync::mpsc, task::JoinHandle}; +use tracing::Instrument; /// Errors that the `FlashbotsTask` can encounter. #[derive(Debug)] @@ -94,7 +95,7 @@ impl FlashbotsTask { self.constants.clone(), ); - let tx = prep.prep_transaction(&sim_result.env.prev_header).await.map_err(|err| { + let tx = prep.prep_transaction(&sim_result.sim_env.prev_header).await.map_err(|err| { error!(?err, "failed to prepare bumpable transaction"); FlashbotsError::PreparationError(err.to_string()) })?; @@ -224,37 +225,37 @@ impl FlashbotsTask { debug!("upstream task gone - exiting flashbots task"); break; }; - debug!(?sim_result.env.block_env.number, "simulation block received"); + + let span = sim_result.span(); + span_scoped!(span, debug!("simulation result received")); // Prepare a MEV bundle with the configured call type from the sim result - let bundle = if let Ok(bundle) = self.prepare(&sim_result).await { - debug!("bundle prepared"); - bundle - } else { - debug!("bundle preparation failed"); + let Ok(bundle) = self.prepare(&sim_result).instrument(span.clone()).await else { + span_scoped!(span, debug!("bundle preparation failed")); continue; }; // simulate the bundle against Flashbots then send the bundle - let sim_bundle_result = flashbots.simulate_bundle(bundle.clone()).await; - match sim_bundle_result { - Ok(_) => { - debug!("bundle simulation successful, ready to send"); - match flashbots.send_bundle(bundle).await { - Ok(bundle_hash) => { - debug!(?bundle_hash, "bundle successfully sent to Flashbots"); - } - Err(err) => { - error!(?err, "failed to send bundle to Flashbots"); - continue; - } - } - } - Err(err) => { - error!(?err, "bundle simulation failed"); - continue; - } + if let Err(err) = + flashbots.simulate_bundle(bundle.clone()).instrument(span.clone()).await + { + span_scoped!(span, debug!(%err, "bundle simulation failed")); + continue; } + + let _ = flashbots + .send_bundle(bundle) + .instrument(span.clone()) + .await + .inspect(|bundle_hash| { + span_scoped!( + span, + debug!(bunlde_hash = %bundle_hash.bundle_hash, "bundle sent to Flashbots") + ); + }) + .inspect_err(|err| { + span_scoped!(span, error!(?err, "failed to send bundle to Flashbots")); + }); } } From 42ac350f78d16a08a3fdb9d7d21ffaad2c191d81 Mon Sep 17 00:00:00 2001 From: James Date: Mon, 22 Sep 2025 14:57:17 -0400 Subject: [PATCH 2/2] chore: use more places --- src/macros.rs | 2 +- src/tasks/block/sim.rs | 7 ++----- src/tasks/env.rs | 4 +--- src/tasks/submit/builder_helper/submit.rs | 2 +- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index b5e598bb..a7b05fc5 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -3,7 +3,7 @@ macro_rules! span_scoped { ($span:expr, $level:ident!($($arg:tt)*)) => { $span.in_scope(|| { $level!($($arg)*); - }); + }) }; } diff --git a/src/tasks/block/sim.rs b/src/tasks/block/sim.rs index 91291142..3547ae7a 100644 --- a/src/tasks/block/sim.rs +++ b/src/tasks/block/sim.rs @@ -207,10 +207,7 @@ impl Simulator { let Some(sim_env) = self.sim_env.borrow_and_update().clone() else { return }; let span = sim_env.span(); - - span.in_scope(|| { - info!("new block environment received"); - }); + span_scoped!(span, info!("new block environment received")); // Calculate the deadline for this block simulation. // NB: This must happen _after_ taking a reference to the sim cache, @@ -222,7 +219,7 @@ impl Simulator { .handle_build(constants.clone(), sim_cache, finish_by, sim_env.block_env.clone()) .instrument(span.clone()) .await - .inspect_err(|err| span.in_scope(|| error!(%err, "error during block build"))) + .inspect_err(|err| span_scoped!(span, error!(%err, "error during block build"))) else { continue; }; diff --git a/src/tasks/env.rs b/src/tasks/env.rs index abc7b18a..24d89f2f 100644 --- a/src/tasks/env.rs +++ b/src/tasks/env.rs @@ -103,9 +103,7 @@ impl EnvTask { let mut headers = match self.ru_provider.subscribe_blocks().await { Ok(poller) => poller, Err(err) => { - span.in_scope(|| { - error!(%err, "Failed to subscribe to blocks"); - }); + span_scoped!(span, error!(%err, "Failed to subscribe to blocks")); return; } } diff --git a/src/tasks/submit/builder_helper/submit.rs b/src/tasks/submit/builder_helper/submit.rs index 1dbf0ee5..3c6485fc 100644 --- a/src/tasks/submit/builder_helper/submit.rs +++ b/src/tasks/submit/builder_helper/submit.rs @@ -115,7 +115,7 @@ impl BuilderHelperTask { // Set up a span for the send operation. We'll add this to the spawned // tasks let span = debug_span!("BuilderHelperTask::send_transaction", tx_hash = %tx.hash()); - span.in_scope(|| debug!("sending transaction to network")); + span_scoped!(span, debug!("sending transaction to network")); // send the tx via the primary host_provider let fut = spawn_provider_send!(self.provider(), &tx, &span);