Skip to content

Commit 8951b43

Browse files
committed
improve spans use in flashbots submit
1 parent f2ca599 commit 8951b43

File tree

2 files changed

+48
-31
lines changed

2 files changed

+48
-31
lines changed

src/tasks/submit/builder_helper.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,7 @@ impl BuilderHelperTask {
262262
let host_block_number = sim_result.host_block_number();
263263

264264
let span = sim_result.sim_env.span.clone();
265-
266-
span_debug!(span, "submit channel received block");
265+
span_debug!(span, "builder helper task received block");
267266

268267
// Don't submit empty blocks
269268
if sim_result.block.is_empty() {

src/tasks/submit/flashbots.rs

Lines changed: 47 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use alloy::{
1414
use eyre::OptionExt;
1515
use init4_bin_base::{deps::metrics::counter, utils::signer::LocalOrAws};
1616
use tokio::{sync::mpsc, task::JoinHandle};
17-
use tracing::{Instrument, debug};
17+
use tracing::{Instrument, debug, debug_span};
1818

1919
/// Handles construction, simulation, and submission of rollup blocks to the
2020
/// Flashbots network.
@@ -117,40 +117,58 @@ impl FlashbotsTask {
117117
debug!("upstream task gone - exiting flashbots task");
118118
break;
119119
};
120-
let span = sim_result.span();
121-
span_debug!(span, "received sim result");
120+
121+
let span = sim_result.sim_env.clone_span();
122+
123+
// Don't submit empty blocks
124+
if sim_result.block.is_empty() {
125+
counter!("signet.builder.flashbots.empty_block").increment(1);
126+
span_debug!(span, "received empty block - skipping");
127+
continue;
128+
}
129+
span_debug!(span, "flashbots task received block");
122130

123131
// Prepare a MEV bundle with the configured call type from the sim result
124-
let Ok(bundle) =
125-
self.prepare(&sim_result).instrument(span.clone()).await.inspect_err(|error| {
126-
counter!("signet.builder.flashbots.bundle_prep_failures").increment(1);
127-
span_debug!(span, %error, "bundle preparation failed");
128-
})
129-
else {
132+
let res = self.prepare(&sim_result).instrument(span.clone()).await;
133+
let Ok(bundle) = res else {
134+
counter!("signet.builder.flashbots.bundle_prep_failures").increment(1);
135+
let error = res.unwrap_err();
136+
span_debug!(span, %error, "bundle preparation failed");
130137
continue;
131138
};
132139

133-
// Send the bundle to Flashbots
134-
let response = self
135-
.flashbots()
136-
.send_mev_bundle(bundle.clone())
137-
.with_auth(self.signer.clone())
138-
.await;
139-
140-
match response {
141-
Ok(resp) => {
142-
counter!("signet.builder.flashbots.bundles_submitted").increment(1);
143-
span_debug!(
144-
span,
145-
hash = resp.map(|r| r.bundle_hash.to_string()),
146-
"received bundle hash after submitted to flashbots"
147-
);
148-
}
149-
Err(err) => {
150-
counter!("signet.builder.flashbots.submission_failures").increment(1);
151-
span_error!(span, %err, "MEV bundle submission failed - error returned");
152-
}
140+
// Make a child span to cover submission
141+
let submit_span = debug_span!(
142+
parent: &span,
143+
"flashbots.submit",
144+
);
145+
146+
// Send the bundle to Flashbots, instrumenting the send future so all
147+
// events inside the async send are attributed to the submit span.
148+
let response = async {
149+
self.flashbots()
150+
.send_mev_bundle(bundle.clone())
151+
.with_auth(self.signer.clone())
152+
.into_future()
153+
.instrument(submit_span.clone())
154+
.await
153155
}
156+
.await;
157+
158+
let Ok(resp) = &response else {
159+
counter!("signet.builder.flashbots.submission_failures").increment(1);
160+
if let Err(err) = &response {
161+
span_error!(submit_span, %err, "MEV bundle submission failed - error returned");
162+
}
163+
continue;
164+
};
165+
166+
counter!("signet.builder.flashbots.bundles_submitted").increment(1);
167+
span_debug!(
168+
submit_span,
169+
hash = resp.as_ref().map(|r| r.bundle_hash.to_string()),
170+
"received bundle hash after submitted to flashbots"
171+
);
154172
}
155173
}
156174

0 commit comments

Comments
 (0)