Skip to content

Commit 6499785

Browse files
authored
fix: use in_scope to narrow down guard usage (#113)
1 parent 6ecca6e commit 6499785

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/tasks/submit/prep.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use signet_sim::BuiltBlock;
1717
use signet_types::{SignRequest, SignResponse};
1818
use signet_zenith::BundleHelper;
1919
use std::sync::OnceLock;
20+
use tracing::Instrument;
2021

2122
/// Preparation logic for transactions issued to the host chain by the
2223
/// [`SubmitTask`].
@@ -134,7 +135,7 @@ impl<'a> SubmitPrep<'a> {
134135

135136
/// Prepares a transaction for submission to the host chain.
136137
pub async fn prep_transaction(self, prev_host: &Header) -> eyre::Result<Bumpable> {
137-
let req = self.new_tx_request().await?;
138+
let req = self.new_tx_request().in_current_span().await?;
138139
Ok(Bumpable::new(req, prev_host))
139140
}
140141
}

src/tasks/submit/task.rs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ impl SubmitTask {
139139
// Retry loop
140140
let result = loop {
141141
let span = debug_span!(
142+
parent: None,
142143
"SubmitTask::retrying_send",
143144
retries = bumpable.bump_count(),
144145
nonce = bumpable.req().nonce,
@@ -231,11 +232,13 @@ impl SubmitTask {
231232
let host_block_number = self.constants.rollup_block_to_host_block_num(ru_block_number);
232233

233234
let span = debug_span!(
234-
"SubmitTask::loop",
235+
parent: None,
236+
"SubmitTask::task_future::transaction_prep",
235237
ru_block_number,
236238
host_block_number,
237239
block_tx_count = sim_result.block.tx_count(),
238240
);
241+
239242
let guard = span.enter();
240243

241244
debug!(ru_block_number, "submit channel received block");
@@ -249,22 +252,26 @@ impl SubmitTask {
249252
// drop guard before await
250253
drop(guard);
251254

255+
// Fetch the previous host block, not the current host block which is currently being built
256+
let prev_host_block = host_block_number - 1;
257+
252258
let Ok(Some(prev_host)) = self
253259
.provider()
254-
.get_block_by_number(host_block_number.into())
260+
.get_block_by_number(prev_host_block.into())
255261
.into_future()
256262
.instrument(span.clone())
257263
.await
258264
else {
259-
let _guard = span.enter();
260-
warn!(ru_block_number, host_block_number, "failed to get previous host block");
265+
span.in_scope(|| {
266+
warn!(ru_block_number, host_block_number, "failed to get previous host block")
267+
});
261268
continue;
262269
};
263270

264271
// Prep the span we'll use for the transaction submission
265272
let submission_span = debug_span!(
266-
parent: span,
267-
"SubmitTask::tx_submission",
273+
parent: &span,
274+
"SubmitTask::task_future::transaction_submission",
268275
tx_count = sim_result.block.tx_count(),
269276
host_block_number,
270277
ru_block_number,
@@ -285,7 +292,9 @@ impl SubmitTask {
285292
{
286293
Ok(bumpable) => bumpable,
287294
Err(error) => {
288-
error!(%error, "failed to prepare transaction for submission");
295+
submission_span.in_scope(|| {
296+
error!(%error, "failed to prepare transaction for submission");
297+
});
289298
continue;
290299
}
291300
};
@@ -294,15 +303,19 @@ impl SubmitTask {
294303
if let Err(error) =
295304
self.sim_with_call(bumpable.req()).instrument(submission_span.clone()).await
296305
{
297-
error!(%error, "simulation failed for transaction");
306+
submission_span.in_scope(|| {
307+
error!(%error, "simulation failed for transaction");
308+
});
298309
continue;
299310
};
300311

301312
// Now send the transaction
302313
if let Err(error) =
303314
self.retrying_send(bumpable, 3).instrument(submission_span.clone()).await
304315
{
305-
error!(%error, "error dispatching block to host chain");
316+
submission_span.in_scope(|| {
317+
error!(%error, "error dispatching block to host chain");
318+
});
306319
continue;
307320
}
308321
}

0 commit comments

Comments
 (0)