Skip to content

Commit 3f06b3a

Browse files
authored
feat: span the provider send spawns (#152)
1 parent d83fa7d commit 3f06b3a

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/tasks/submit/builder_helper/submit.rs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ use tokio::{sync::mpsc, task::JoinHandle};
2525

2626
/// Helper macro to spawn a tokio task that broadcasts a tx.
2727
macro_rules! spawn_provider_send {
28-
($provider:expr, $tx:expr) => {
28+
($provider:expr, $tx:expr, $span:expr) => {
2929
{
3030
let p = $provider.clone();
3131
let t = $tx.clone();
3232
tokio::spawn(async move {
3333
p.send_tx_envelope(t).await.inspect_err(|e| {
3434
warn!(%e, "error in transaction broadcast")
3535
})
36-
})
36+
}.instrument($span.clone()))
3737
}
3838
};
3939
}
@@ -106,30 +106,36 @@ impl BuilderHelperTask {
106106
let SendableTx::Envelope(tx) = self.provider().fill(tx).await? else {
107107
bail!("failed to fill transaction")
108108
};
109-
debug!(tx_hash = ?tx.hash(), "sending transaction to network");
109+
110+
// Set up a span for the send operation. We'll add this to the spawned
111+
// tasks
112+
let span = debug_span!("BuilderHelperTask::send_transaction", tx_hash = %tx.hash());
113+
span.in_scope(|| debug!("sending transaction to network"));
110114

111115
// send the tx via the primary host_provider
112-
let fut = spawn_provider_send!(self.provider(), &tx);
116+
let fut = spawn_provider_send!(self.provider(), &tx, &span);
113117

114118
// spawn send_tx futures on retry attempts for all additional broadcast host_providers
115119
for host_provider in self.config.connect_additional_broadcast() {
116-
spawn_provider_send!(&host_provider, &tx);
120+
spawn_provider_send!(&host_provider, &tx, &span);
117121
}
118122

123+
// enter span for remainder of function.
124+
let _guard = span.enter();
119125
// send the in-progress transaction over the outbound_tx_channel
120126
if self.outbound_tx_channel.send(*tx.tx_hash()).is_err() {
121127
error!("receipts task gone");
122128
}
123129

124-
if let Err(error) = fut.await? {
130+
if let Err(err) = fut.await? {
125131
// Detect and handle transaction underprice errors
126-
if matches!(error, TransportError::ErrorResp(ref err) if err.code == -32603) {
127-
debug!(tx_hash = ?tx.hash(), "underpriced transaction error - retrying tx with gas bump");
132+
if matches!(err, TransportError::ErrorResp(ref err) if err.code == -32603) {
133+
debug!("underpriced transaction error - retrying tx with gas bump");
128134
return Ok(ControlFlow::Retry);
129135
}
130136

131137
// Unknown error, log and skip
132-
error!(%error, "Primary tx broadcast failed");
138+
error!(%err, "Primary tx broadcast failed");
133139
return Ok(ControlFlow::Skip);
134140
}
135141

@@ -188,20 +194,17 @@ impl BuilderHelperTask {
188194
return Ok(ControlFlow::Skip);
189195
}
190196
drop(guard);
191-
debug!(
192-
retries = bumpable.bump_count(),
193-
window.start, window.end, "retrying block"
194-
);
197+
debug!("retrying block");
195198
continue;
196199
}
197200
ControlFlow::Skip => {
198201
counter!("builder.skipped_blocks").increment(1);
199-
debug!(retries = bumpable.bump_count(), "skipping block");
202+
debug!("skipping block");
200203
break inbound_result;
201204
}
202205
ControlFlow::Done => {
203206
counter!("builder.submitted_successful_blocks").increment(1);
204-
debug!(retries = bumpable.bump_count(), "successfully submitted block");
207+
debug!("successfully submitted block");
205208
break inbound_result;
206209
}
207210
}

0 commit comments

Comments
 (0)