Skip to content

Commit d83fa7d

Browse files
authored
chore: pass block-associated span with simenv and simresult (#151)
1 parent 551ae21 commit d83fa7d

File tree

3 files changed

+69
-23
lines changed

3 files changed

+69
-23
lines changed

src/tasks/block/sim.rs

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,30 @@ pub struct SimResult {
4848
/// The block built with the successfully simulated transactions
4949
pub block: BuiltBlock,
5050
/// The block environment the transactions were simulated against.
51-
pub env: SimEnv,
51+
pub sim_env: SimEnv,
52+
}
53+
54+
impl SimResult {
55+
/// Returns the block number of the built block.
56+
pub const fn block_number(&self) -> u64 {
57+
self.block.block_number()
58+
}
59+
60+
/// Returns the host block number for the built block.
61+
pub const fn host_block_number(&self) -> u64 {
62+
self.sim_env.host_block_number()
63+
}
64+
65+
/// Returns a reference to the tracing span associated with this simulation
66+
/// result.
67+
pub const fn span(&self) -> &tracing::Span {
68+
self.sim_env.span()
69+
}
70+
71+
/// Clones the span for use in other tasks.
72+
pub fn clone_span(&self) -> tracing::Span {
73+
self.sim_env.clone_span()
74+
}
5275
}
5376

5477
impl Simulator {
@@ -182,27 +205,31 @@ impl Simulator {
182205
return;
183206
}
184207
let Some(sim_env) = self.sim_env.borrow_and_update().clone() else { return };
185-
let block_number = sim_env.block_env.number.to::<u64>();
186-
info!(block_number, "new block environment received");
208+
209+
let span = sim_env.span();
210+
211+
span.in_scope(|| {
212+
info!("new block environment received");
213+
});
187214

188215
// Calculate the deadline for this block simulation.
189216
// NB: This must happen _after_ taking a reference to the sim cache,
190217
// waiting for a new block, and checking current slot authorization.
191218
let finish_by = self.calculate_deadline();
192219
let sim_cache = cache.clone();
193-
match self
220+
221+
let Ok(block) = self
194222
.handle_build(constants.clone(), sim_cache, finish_by, sim_env.block_env.clone())
223+
.instrument(span.clone())
195224
.await
196-
{
197-
Ok(block) => {
198-
debug!(block = ?block.block_number(), tx_count = block.transactions().len(), "built simulated block");
199-
let _ = submit_sender.send(SimResult { block, env: sim_env });
200-
}
201-
Err(e) => {
202-
error!(err = %e, "failed to build block");
203-
continue;
204-
}
205-
}
225+
.inspect_err(|err| span.in_scope(|| error!(%err, "error during block build")))
226+
else {
227+
continue;
228+
};
229+
230+
let _guard = span.clone().entered();
231+
debug!(block = ?block.block_number(), tx_count = block.transactions().len(), "built simulated block");
232+
let _ = submit_sender.send(SimResult { block, sim_env });
206233
}
207234
}
208235

src/tasks/env.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,30 @@ pub struct SimEnv {
3939
pub prev_header: Header,
4040
/// The header of the previous host block.
4141
pub prev_host: Header,
42+
/// A tracing span associated with this block
43+
pub span: tracing::Span,
44+
}
45+
46+
impl SimEnv {
47+
/// Returns the block number of the signet block environment.
48+
pub const fn block_number(&self) -> u64 {
49+
self.prev_header.number.saturating_add(1)
50+
}
51+
52+
/// Returns the host block number for the signet block environment.
53+
pub const fn host_block_number(&self) -> u64 {
54+
self.prev_host.number.saturating_add(1)
55+
}
56+
57+
/// Returns a reference to the tracing span associated with this block env.
58+
pub const fn span(&self) -> &tracing::Span {
59+
&self.span
60+
}
61+
62+
/// Clones the span for use in other tasks.
63+
pub fn clone_span(&self) -> tracing::Span {
64+
self.span.clone()
65+
}
4266
}
4367

4468
impl EnvTask {
@@ -95,7 +119,7 @@ impl EnvTask {
95119
let host_block_number =
96120
self.constants.rollup_block_to_host_block_num(rollup_header.number);
97121

98-
let span = info_span!("EnvTask::task_fut::loop", %host_block_number, %rollup_header.hash, %rollup_header.number);
122+
let span = info_span!("SimEnv", %host_block_number, %rollup_header.hash, %rollup_header.number);
99123

100124
let host_block_opt = res_unwrap_or_continue!(
101125
self.host_provider.get_block_by_number(host_block_number.into()).await,
@@ -120,6 +144,7 @@ impl EnvTask {
120144

121145
if sender
122146
.send(Some(SimEnv {
147+
span,
123148
block_env: signet_env,
124149
prev_header: rollup_header.inner,
125150
prev_host,

src/tasks/submit/builder_helper/submit.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,7 @@ impl BuilderHelperTask {
244244
let ru_block_number = sim_result.block.block_number();
245245
let host_block_number = self.constants.rollup_block_to_host_block_num(ru_block_number);
246246

247-
let span = debug_span!(
248-
parent: None,
249-
"SubmitTask::task_future::transaction_prep",
250-
ru_block_number,
251-
host_block_number,
252-
block_tx_count = sim_result.block.tx_count(),
253-
);
247+
let span = sim_result.sim_env.span.clone();
254248

255249
let guard = span.enter();
256250

@@ -283,7 +277,7 @@ impl BuilderHelperTask {
283277
self.constants.clone(),
284278
);
285279
let bumpable = res_unwrap_or_continue!(
286-
prep.prep_transaction(&sim_result.env.prev_host)
280+
prep.prep_transaction(&sim_result.sim_env.prev_host)
287281
.instrument(submission_span.clone())
288282
.await,
289283
submission_span,

0 commit comments

Comments
 (0)