Skip to content

Commit 4d6aee1

Browse files
authored
obs: improve spans use in flashbots submit (#165)
This PR improves span usage in the Flashbots submit task for better tracking in groundcover and analytics.
1 parent f2ca599 commit 4d6aee1

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
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: 28 additions & 10 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,38 +117,56 @@ 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) =
132+
let result =
125133
self.prepare(&sim_result).instrument(span.clone()).await.inspect_err(|error| {
126134
counter!("signet.builder.flashbots.bundle_prep_failures").increment(1);
127135
span_debug!(span, %error, "bundle preparation failed");
128-
})
129-
else {
130-
continue;
136+
});
137+
let bundle = match result {
138+
Ok(bundle) => bundle,
139+
Err(_) => continue,
131140
};
132141

133-
// Send the bundle to Flashbots
142+
// Make a child span to cover submission
143+
let submit_span = debug_span!(
144+
parent: &span,
145+
"flashbots.submit",
146+
);
147+
148+
// Send the bundle to Flashbots, instrumenting the send future so all
149+
// events inside the async send are attributed to the submit span.
134150
let response = self
135151
.flashbots()
136152
.send_mev_bundle(bundle.clone())
137153
.with_auth(self.signer.clone())
154+
.into_future()
155+
.instrument(submit_span.clone())
138156
.await;
139157

140158
match response {
141159
Ok(resp) => {
142160
counter!("signet.builder.flashbots.bundles_submitted").increment(1);
143161
span_debug!(
144-
span,
162+
submit_span,
145163
hash = resp.map(|r| r.bundle_hash.to_string()),
146164
"received bundle hash after submitted to flashbots"
147165
);
148166
}
149167
Err(err) => {
150168
counter!("signet.builder.flashbots.submission_failures").increment(1);
151-
span_error!(span, %err, "MEV bundle submission failed - error returned");
169+
span_error!(submit_span, %err, "MEV bundle submission failed - error returned");
152170
}
153171
}
154172
}

0 commit comments

Comments
 (0)