Skip to content

Commit 1878e52

Browse files
committed
feat: adds retry to BatchReceipts call
1 parent faa49ce commit 1878e52

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

x/contracts/txmonitor/eth_helper.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package txmonitor
22

33
import (
44
"context"
5+
"time"
56

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

114-
// Execute the batch request
115-
err := e.client.BatchCallContext(ctx, batch)
115+
var receipts []Result
116+
var err error
117+
for retries := 0; retries < 3; retries++ {
118+
// Execute the batch request
119+
err = e.client.BatchCallContext(ctx, batch)
120+
if err == nil {
121+
break
122+
}
123+
124+
// Check if the error is a 429 (Too Many Requests)
125+
if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == 429 {
126+
time.Sleep(1 * time.Second)
127+
continue
128+
}
129+
130+
return nil, err
131+
}
132+
116133
if err != nil {
117134
return nil, err
118135
}
119136

120-
receipts := make([]Result, len(batch))
137+
receipts = make([]Result, len(batch))
121138
for i, elem := range batch {
122139
receipts[i].Receipt = elem.Result.(*types.Receipt)
123140
if elem.Error != nil {

0 commit comments

Comments
 (0)