Skip to content

Commit 31a1a04

Browse files
authored
fix(eth-sender): confirm eth-txs in order of their creation (#2310)
Signed-off-by: tomg10 <lemures64@gmail.com>
1 parent a61f273 commit 31a1a04

File tree

1 file changed

+28
-21
lines changed

1 file changed

+28
-21
lines changed

core/node/eth_sender/src/eth_tx_manager.rs

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl EthTxManager {
6868
&self,
6969
storage: &mut Connection<'_, Core>,
7070
op: &EthTx,
71-
) -> Option<ExecutedTxStatus> {
71+
) -> Result<Option<ExecutedTxStatus>, EthSenderError> {
7272
// Checking history items, starting from most recently sent.
7373
for history_item in storage
7474
.eth_sender_dal()
@@ -80,16 +80,19 @@ impl EthTxManager {
8080
// because if we do and get an `Err`, we won't finish the for loop,
8181
// which means we might miss the transaction that actually succeeded.
8282
match self.l1_interface.get_tx_status(history_item.tx_hash).await {
83-
Ok(Some(s)) => return Some(s),
83+
Ok(Some(s)) => return Ok(Some(s)),
8484
Ok(_) => continue,
85-
Err(err) => tracing::warn!(
86-
"Can't check transaction {:?}: {:?}",
87-
history_item.tx_hash,
88-
err
89-
),
85+
Err(err) => {
86+
tracing::warn!(
87+
"Can't check transaction {:?}: {:?}",
88+
history_item.tx_hash,
89+
err
90+
);
91+
return Err(err);
92+
}
9093
}
9194
}
92-
None
95+
Ok(None)
9396
}
9497

9598
pub(crate) async fn send_eth_tx(
@@ -253,29 +256,26 @@ impl EthTxManager {
253256
.await?;
254257
let blobs_operator_address = self.l1_interface.get_blobs_operator_account();
255258

256-
if let Some(res) = self
257-
.monitor_inflight_transactions_inner(storage, l1_block_numbers, operator_nonce, None)
258-
.await?
259-
{
260-
return Ok(Some(res));
261-
};
262-
263259
if let Some(blobs_operator_nonce) = blobs_operator_nonce {
264260
// need to check if both nonce and address are `Some`
265261
if blobs_operator_address.is_none() {
266262
panic!("blobs_operator_address has to be set its nonce is known; qed");
267263
}
268-
Ok(self
264+
if let Some(res) = self
269265
.monitor_inflight_transactions_inner(
270266
storage,
271267
l1_block_numbers,
272268
blobs_operator_nonce,
273269
blobs_operator_address,
274270
)
275-
.await?)
276-
} else {
277-
Ok(None)
271+
.await?
272+
{
273+
return Ok(Some(res));
274+
}
278275
}
276+
277+
self.monitor_inflight_transactions_inner(storage, l1_block_numbers, operator_nonce, None)
278+
.await
279279
}
280280

281281
async fn monitor_inflight_transactions_inner(
@@ -347,11 +347,11 @@ impl EthTxManager {
347347
);
348348

349349
match self.check_all_sending_attempts(storage, &tx).await {
350-
Some(tx_status) => {
350+
Ok(Some(tx_status)) => {
351351
self.apply_tx_status(storage, &tx, tx_status, l1_block_numbers.finalized)
352352
.await;
353353
}
354-
None => {
354+
Ok(None) => {
355355
// The nonce has increased but we did not find the receipt.
356356
// This is an error because such a big re-org may cause transactions that were
357357
// previously recorded as confirmed to become pending again and we have to
@@ -361,6 +361,13 @@ impl EthTxManager {
361361
&tx
362362
);
363363
}
364+
Err(err) => {
365+
// An error here means that we weren't able to check status of one of the txs
366+
// we can't continue to avoid situations with out-of-order confirmed txs
367+
// (for instance Execute tx confirmed before PublishProof tx) as this would make
368+
// our API return inconsistent block info
369+
return Err(err);
370+
}
364371
}
365372
}
366373
Ok(None)

0 commit comments

Comments
 (0)