Skip to content

Commit

Permalink
feat: attempt the request multiple times
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Jul 4, 2024
1 parent 0ddb7ad commit 45919d1
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions x/contracts/txmonitor/eth_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,23 +115,18 @@ func (e *evmHelper) BatchReceipts(ctx context.Context, txHashes []common.Hash) (

var receipts []Result
var err error
for {
for attempts := 0; attempts < 10; attempts++ {
// Execute the batch request
err = e.client.BatchCallContext(ctx, batch)
if err == nil {
break
}

// Check if the error is a 429 (Too Many Requests)
if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == 429 {
log.Println("received 429 Too Many Requests, retrying...", "error", err)
if err != nil {
log.Printf("Batch call attempt %d failed: %v", attempts+1, err)
time.Sleep(1 * time.Second)
continue
}
}

if err != nil {
return nil, err
}

receipts = make([]Result, len(batch))
for i, elem := range batch {
receipts[i].Receipt = elem.Result.(*types.Receipt)
Expand Down

0 comments on commit 45919d1

Please sign in to comment.