Skip to content

Commit

Permalink
feat: adds retry to BatchReceipts call
Browse files Browse the repository at this point in the history
  • Loading branch information
ckartik committed Jul 3, 2024
1 parent a95e420 commit a7a4fc0
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions x/contracts/txmonitor/eth_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package txmonitor

import (
"context"
"time"

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -111,13 +112,29 @@ func (e *evmHelper) BatchReceipts(ctx context.Context, txHashes []common.Hash) (
}
}

// Execute the batch request
err := e.client.BatchCallContext(ctx, batch)
var receipts []Result
var err error
for retries := 0; retries < 3; retries++ {
// 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 {
time.Sleep(1 * time.Second)
continue
}

return nil, err
}

if err != nil {
return nil, err
}

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

0 comments on commit a7a4fc0

Please sign in to comment.