Skip to content

Commit 0e82fa5

Browse files
committed
cleanup
1 parent b190043 commit 0e82fa5

File tree

1 file changed

+24
-36
lines changed

1 file changed

+24
-36
lines changed

src/tasks/submit.rs

Lines changed: 24 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl SubmitTask {
122122
) -> eyre::Result<ControlFlow> {
123123
let tx = self.prepare_tx(retry_count, resp, block).await?;
124124

125-
self.send_transaction(resp, tx).await
125+
self.send_transaction(retry_count, resp, tx).await
126126
}
127127

128128
/// Prepares the transaction by extracting the signature components, creating the transaction
@@ -155,13 +155,7 @@ impl SubmitTask {
155155
if let Err(TransportError::ErrorResp(e)) =
156156
self.provider().call(tx.clone()).block(BlockNumberOrTag::Pending.into()).await
157157
{
158-
error!(
159-
code = e.code,
160-
message = %e.message,
161-
data = ?e.data,
162-
"error in transaction submission"
163-
);
164-
158+
// NB: These errors are all handled the same way but are logged for debugging purposes
165159
if e.as_revert_data()
166160
.map(|data| data.starts_with(&IncorrectHostBlock::SELECTOR))
167161
.unwrap_or_default()
@@ -186,6 +180,12 @@ impl SubmitTask {
186180
return Some(Ok(ControlFlow::Skip));
187181
}
188182

183+
error!(
184+
code = e.code,
185+
message = %e.message,
186+
data = ?e.data,
187+
"unknown error in host transaction simulation call"
188+
);
189189
return Some(Ok(ControlFlow::Skip));
190190
}
191191

@@ -209,7 +209,7 @@ impl SubmitTask {
209209
let (max_fee_per_gas, max_priority_fee_per_gas, max_fee_per_blob_gas) =
210210
calculate_gas_limits(retry_count);
211211

212-
// manually retrieve nonce
212+
// manually retrieve nonce // TODO: Maybe this should be done in Env task and passed through elsewhere
213213
let nonce =
214214
self.provider().get_transaction_count(self.provider().default_signer_address()).await?;
215215
debug!(nonce, "assigned nonce");
@@ -233,59 +233,51 @@ impl SubmitTask {
233233
.with_max_fee_per_blob_gas(max_fee_per_blob_gas)
234234
.with_nonce(nonce);
235235

236-
debug!(?tx, "prepared transaction request");
237236
Ok(tx)
238237
}
239238

240239
/// Fills the transaction request with the provider and sends it to the network
241240
/// and any additionally configured broadcast providers.
242241
async fn send_transaction(
243242
&self,
243+
retry_count: usize,
244244
resp: &SignResponse,
245245
tx: TransactionRequest,
246246
) -> Result<ControlFlow, eyre::Error> {
247-
debug!(
248-
?tx,
249-
host_block_number = %resp.req.host_block_number,
250-
gas_limit = %resp.req.gas_limit,
251-
"sending transaction to network"
252-
);
253-
254247
// assign the nonce and fill the rest of the values
255-
debug!(?tx, "blob transaction request before fill");
256248
let SendableTx::Envelope(tx) = self.provider().fill(tx).await? else {
257249
bail!("failed to fill transaction")
258250
};
259-
debug!(?tx, "filled blob transaction");
251+
debug!(tx_hash = ?tx.hash(), host_block_number = %resp.req.host_block_number, "sending transaction to network");
260252

261253
// send the tx via the primary host_provider
262254
let fut = spawn_provider_send!(self.provider(), &tx);
263255

264-
// spawn send_tx futures for all additional broadcast host_providers
265-
for host_provider in self.config.connect_additional_broadcast() {
266-
spawn_provider_send!(&host_provider, &tx);
256+
// spawn send_tx futures on retry attempts for all additional broadcast host_providers
257+
if retry_count > 0 {
258+
for host_provider in self.config.connect_additional_broadcast() {
259+
spawn_provider_send!(&host_provider, &tx);
260+
}
267261
}
268262

269263
// send the in-progress transaction over the outbound_tx_channel
270264
if self.outbound_tx_channel.send(*tx.tx_hash()).is_err() {
271265
error!("receipts task gone");
272266
}
273267

274-
// question mark unwraps join error, which would be an internal panic
275-
// then if let checks for rpc error
276268
if let Err(e) = fut.await? {
277-
let err_str = e.to_string();
278-
if err_str.contains("replacement transaction underpriced") {
269+
// Detect and handle transaction underprice errors
270+
if matches!(e, TransportError::ErrorResp(ref err) if err.code == -32000 && err.message.contains("replacement transaction underpriced"))
271+
{
279272
debug!(?tx, "underpriced transaction error - retrying tx with gas bump");
280273
return Ok(ControlFlow::Retry);
281274
}
282-
error!(error = %e, "Primary tx broadcast failed. Skipping transaction.");
275+
276+
// Unknown error, log and skip
277+
error!(error = %e, "Primary tx broadcast failed");
283278
return Ok(ControlFlow::Skip);
284279
}
285280

286-
// Okay so the code gets all the way to this log
287-
// but we don't see the tx hash in the logs or in the explorer,
288-
// not even as a failed TX, just not at all.
289281
info!(
290282
tx_hash = %tx.tx_hash(),
291283
ru_chain_id = %resp.req.ru_chain_id,
@@ -339,10 +331,7 @@ impl SubmitTask {
339331

340332
let inbound_result =
341333
match self.handle_inbound(retries, block).instrument(span.clone()).await {
342-
Ok(control_flow) => {
343-
debug!(?control_flow, retries, "successfully handled inbound block");
344-
control_flow
345-
}
334+
Ok(control_flow) => control_flow,
346335
Err(err) => {
347336
// Delay until next slot if we get a 403 error
348337
if err.to_string().contains("403 Forbidden") {
@@ -353,7 +342,6 @@ impl SubmitTask {
353342
error!(error = %err, "error handling inbound block");
354343
}
355344

356-
retries += 1;
357345
ControlFlow::Retry
358346
}
359347
};
@@ -437,7 +425,7 @@ impl SubmitTask {
437425
last_block_attempted = block.block_number();
438426
debug!(last_block_attempted, "resetting last block attempted");
439427

440-
if self.retrying_handle_inbound(&block, 20).await.is_err() {
428+
if self.retrying_handle_inbound(&block, 3).await.is_err() {
441429
debug!("error handling inbound block");
442430
continue;
443431
};

0 commit comments

Comments
 (0)