From 403a444b3b015260feee01eb6ce545759aa2613b Mon Sep 17 00:00:00 2001 From: James Date: Wed, 17 Sep 2025 15:45:47 -0400 Subject: [PATCH] chore: pass block-associated span with simenv and simresult --- src/tasks/block/sim.rs | 55 +++++++++++++++++------ src/tasks/env.rs | 27 ++++++++++- src/tasks/submit/builder_helper/submit.rs | 10 +---- 3 files changed, 69 insertions(+), 23 deletions(-) diff --git a/src/tasks/block/sim.rs b/src/tasks/block/sim.rs index 1c3b6bed..91291142 100644 --- a/src/tasks/block/sim.rs +++ b/src/tasks/block/sim.rs @@ -48,7 +48,30 @@ pub struct SimResult { /// The block built with the successfully simulated transactions pub block: BuiltBlock, /// The block environment the transactions were simulated against. - pub env: SimEnv, + pub sim_env: SimEnv, +} + +impl SimResult { + /// Returns the block number of the built block. + pub const fn block_number(&self) -> u64 { + self.block.block_number() + } + + /// Returns the host block number for the built block. + pub const fn host_block_number(&self) -> u64 { + self.sim_env.host_block_number() + } + + /// Returns a reference to the tracing span associated with this simulation + /// result. + pub const fn span(&self) -> &tracing::Span { + self.sim_env.span() + } + + /// Clones the span for use in other tasks. + pub fn clone_span(&self) -> tracing::Span { + self.sim_env.clone_span() + } } impl Simulator { @@ -182,27 +205,31 @@ impl Simulator { return; } let Some(sim_env) = self.sim_env.borrow_and_update().clone() else { return }; - let block_number = sim_env.block_env.number.to::(); - info!(block_number, "new block environment received"); + + let span = sim_env.span(); + + span.in_scope(|| { + info!("new block environment received"); + }); // Calculate the deadline for this block simulation. // NB: This must happen _after_ taking a reference to the sim cache, // waiting for a new block, and checking current slot authorization. let finish_by = self.calculate_deadline(); let sim_cache = cache.clone(); - match self + + let Ok(block) = self .handle_build(constants.clone(), sim_cache, finish_by, sim_env.block_env.clone()) + .instrument(span.clone()) .await - { - Ok(block) => { - debug!(block = ?block.block_number(), tx_count = block.transactions().len(), "built simulated block"); - let _ = submit_sender.send(SimResult { block, env: sim_env }); - } - Err(e) => { - error!(err = %e, "failed to build block"); - continue; - } - } + .inspect_err(|err| span.in_scope(|| error!(%err, "error during block build"))) + else { + continue; + }; + + let _guard = span.clone().entered(); + debug!(block = ?block.block_number(), tx_count = block.transactions().len(), "built simulated block"); + let _ = submit_sender.send(SimResult { block, sim_env }); } } diff --git a/src/tasks/env.rs b/src/tasks/env.rs index d0bbf957..abc7b18a 100644 --- a/src/tasks/env.rs +++ b/src/tasks/env.rs @@ -39,6 +39,30 @@ pub struct SimEnv { pub prev_header: Header, /// The header of the previous host block. pub prev_host: Header, + /// A tracing span associated with this block + pub span: tracing::Span, +} + +impl SimEnv { + /// Returns the block number of the signet block environment. + pub const fn block_number(&self) -> u64 { + self.prev_header.number.saturating_add(1) + } + + /// Returns the host block number for the signet block environment. + pub const fn host_block_number(&self) -> u64 { + self.prev_host.number.saturating_add(1) + } + + /// Returns a reference to the tracing span associated with this block env. + pub const fn span(&self) -> &tracing::Span { + &self.span + } + + /// Clones the span for use in other tasks. + pub fn clone_span(&self) -> tracing::Span { + self.span.clone() + } } impl EnvTask { @@ -95,7 +119,7 @@ impl EnvTask { let host_block_number = self.constants.rollup_block_to_host_block_num(rollup_header.number); - let span = info_span!("EnvTask::task_fut::loop", %host_block_number, %rollup_header.hash, %rollup_header.number); + let span = info_span!("SimEnv", %host_block_number, %rollup_header.hash, %rollup_header.number); let host_block_opt = res_unwrap_or_continue!( self.host_provider.get_block_by_number(host_block_number.into()).await, @@ -120,6 +144,7 @@ impl EnvTask { if sender .send(Some(SimEnv { + span, block_env: signet_env, prev_header: rollup_header.inner, prev_host, diff --git a/src/tasks/submit/builder_helper/submit.rs b/src/tasks/submit/builder_helper/submit.rs index 3917317a..09b1d362 100644 --- a/src/tasks/submit/builder_helper/submit.rs +++ b/src/tasks/submit/builder_helper/submit.rs @@ -244,13 +244,7 @@ impl BuilderHelperTask { let ru_block_number = sim_result.block.block_number(); let host_block_number = self.constants.rollup_block_to_host_block_num(ru_block_number); - let span = debug_span!( - parent: None, - "SubmitTask::task_future::transaction_prep", - ru_block_number, - host_block_number, - block_tx_count = sim_result.block.tx_count(), - ); + let span = sim_result.sim_env.span.clone(); let guard = span.enter(); @@ -283,7 +277,7 @@ impl BuilderHelperTask { self.constants.clone(), ); let bumpable = res_unwrap_or_continue!( - prep.prep_transaction(&sim_result.env.prev_host) + prep.prep_transaction(&sim_result.sim_env.prev_host) .instrument(submission_span.clone()) .await, submission_span,