Skip to content

Commit a843f55

Browse files
author
colinlyguo
committed
address AI's comment
1 parent 86b18d5 commit a843f55

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

rollup/internal/controller/sender/sender.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -648,10 +648,19 @@ func (s *Sender) checkPendingTransaction() {
648648
if err := s.client.SendTransaction(s.ctx, newSignedTx); err != nil {
649649
if strings.Contains(err.Error(), "nonce too low") {
650650
// When we receive a 'nonce too low' error but cannot find the transaction receipt, it indicates another transaction with this nonce has already been processed, so this transaction will never be mined and should be marked as failed.
651-
log.Warn("nonce too low detected, marking all non-confirmed transactions with same nonce as failed", "nonce", originalTx.Nonce(), "address", s.transactionSigner.GetAddr().Hex(), "txHash", originalTx.Hash().Hex(), "err", err)
652-
653-
if updateErr := s.pendingTransactionOrm.UpdateTransactionStatusByTxHash(s.ctx, originalTx.Hash(), types.TxStatusConfirmedFailed); updateErr != nil {
654-
log.Error("failed to update status of original transaction to confirmed failed", "txHash", originalTx.Hash().Hex(), "nonce", originalTx.Nonce(), "from", s.transactionSigner.GetAddr().Hex(), "err", updateErr)
651+
log.Warn("nonce too low detected, marking all non-confirmed transactions with same nonce as failed", "nonce", originalTx.Nonce(), "address", s.transactionSigner.GetAddr().Hex(), "txHash", originalTx.Hash().Hex(), "newTxHash", newSignedTx.Hash().Hex(), "err", err)
652+
653+
// Handle both original and replacement transactions in a database transaction
654+
if dbErr := s.db.Transaction(func(dbTX *gorm.DB) error {
655+
if updateErr := s.pendingTransactionOrm.UpdateTransactionStatusByTxHash(s.ctx, originalTx.Hash(), types.TxStatusConfirmedFailed, dbTX); updateErr != nil {
656+
return fmt.Errorf("failed to update original transaction status, hash: %s, err: %w", originalTx.Hash().Hex(), updateErr)
657+
}
658+
if updateErr := s.pendingTransactionOrm.DeleteTransactionByTxHash(s.ctx, newSignedTx.Hash(), dbTX); updateErr != nil {
659+
return fmt.Errorf("failed to delete replacement transaction, hash: %s, err: %w", newSignedTx.Hash().Hex(), updateErr)
660+
}
661+
return nil
662+
}); dbErr != nil {
663+
log.Error("failed to handle nonce too low scenario in database", "err", dbErr)
655664
return
656665
}
657666
return

0 commit comments

Comments
 (0)