Skip to content

Commit

Permalink
feat: reattempt individual txns
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Jul 9, 2024
1 parent d4193dc commit acc413f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion x/contracts/txmonitor/eth_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (e *evmHelper) BatchReceipts(ctx context.Context, txHashes []common.Hash) (
var receipts []Result
var err error
for attempts := 0; attempts < 50; attempts++ {
e.logger.Debug("Attempting batch call", "attempt", attempts+1)
e.logger.Info("Attempting batch call", "attempt", attempts+1)
// Execute the batch request
err = e.client.BatchCallContext(context.Background(), batch)
if err != nil {
Expand All @@ -134,6 +134,7 @@ func (e *evmHelper) BatchReceipts(ctx context.Context, txHashes []common.Hash) (
e.logger.Error("All batch call attempts failed", "error", err)
return nil, err
}

receipts = make([]Result, len(batch))
for i, elem := range batch {
e.logger.Debug("Processing batch element", "index", i, "result", elem.Result, "error", elem.Error)
Expand All @@ -143,6 +144,24 @@ func (e *evmHelper) BatchReceipts(ctx context.Context, txHashes []common.Hash) (
}
}

// Retry individual failed transactions
for i, receipt := range receipts {
if receipt.Err != nil {
e.logger.Info("Retrying failed transaction", "index", i, "hash", txHashes[i].Hex())
for attempts := 0; attempts < 50; attempts++ {
e.logger.Info("Attempting individual call", "attempt", attempts+1, "hash", txHashes[i].Hex())
err = e.client.CallContext(context.Background(), receipt.Receipt, "eth_getTransactionReceipt", txHashes[i])
if err == nil {
e.logger.Info("Individual call succeeded", "attempt", attempts+1, "hash", txHashes[i].Hex())
receipts[i].Err = nil
break
}
e.logger.Error("Individual call attempt failed", "attempt", attempts+1, "hash", txHashes[i].Hex(), "error", err)
time.Sleep(1 * time.Second)
}
}
}

e.logger.Info("BatchReceipts completed successfully", "receipts", receipts)
return receipts, nil
}

0 comments on commit acc413f

Please sign in to comment.