Skip to content

Commit

Permalink
check if replaced txns are confirmed
Browse files Browse the repository at this point in the history
  • Loading branch information
ian-shim committed Feb 1, 2024
1 parent 096ecf6 commit 65209bf
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions disperser/batcher/txn_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ type TxnRequest struct {
Metadata interface{}

requestedAt time.Time
// txAttempts are the transactions that have been attempted to be mined for this request.
// If a transaction hasn't been confirmed within the timeout and a replacement transaction is sent,
// the original transaction hash will be kept in this slice
txAttempts []*types.Transaction
}

// ReceiptOrErr is a wrapper for a transaction receipt or an error.
Expand Down Expand Up @@ -83,6 +87,7 @@ func NewTxnRequest(tx *types.Transaction, tag string, value *big.Int, metadata i
Metadata: metadata,

requestedAt: time.Now(),
txAttempts: make([]*types.Transaction, 0),
}
}

Expand Down Expand Up @@ -140,6 +145,7 @@ func (t *txnManager) ProcessTransaction(ctx context.Context, req *TxnRequest) er
t.logger.Debug("[TxnManager] successfully sent txn", "tag", req.Tag, "txn", txn.Hash().Hex())
}
req.Tx = txn
req.txAttempts = append(req.txAttempts, txn)

t.requestChan <- req
t.metrics.UpdateTxQueue(len(t.requestChan))
Expand Down Expand Up @@ -186,19 +192,24 @@ func (t *txnManager) monitorTransaction(ctx context.Context, req *TxnRequest) (*
err = t.ethClient.SendTransaction(ctx, newTx)
if err != nil {
if errors.Is(err, gcore.ErrNonceTooLow) {
// try to get the receipt again to see if the transaction has been mined
_, receiptErr := t.ethClient.TransactionReceipt(ctx, req.Tx.Hash())
if receiptErr == nil {
continue
// try to get the receipt again to see if any of the transaction attempts have been mined
for _, tx := range req.txAttempts {
_, receiptErr := t.ethClient.TransactionReceipt(ctx, tx.Hash())
if receiptErr == nil {
// tx has been mined, update the request with the mined tx and continue
req.Tx = tx
continue
}
}
}
t.logger.Error("[TxnManager] failed to send txn", "tag", req.Tag, "txn", req.Tx.Hash().Hex(), "err", err)
t.metrics.IncrementTxnCount("failure")
return nil, err
} else {
t.logger.Debug("[TxnManager] successfully sent txn", "tag", req.Tag, "txn", newTx.Hash().Hex())
}

t.logger.Debug("[TxnManager] successfully sent txn", "tag", req.Tag, "txn", newTx.Hash().Hex())
req.Tx = newTx
req.txAttempts = append(req.txAttempts, newTx)
numSpeedUps++
} else {
t.logger.Error("[TxnManager] transaction failed", "tag", req.Tag, "txHash", req.Tx.Hash().Hex(), "err", err)
Expand Down

0 comments on commit 65209bf

Please sign in to comment.