From 45919d12bdd0390fbe0f2abee640fb26548d4b94 Mon Sep 17 00:00:00 2001 From: Kartik Chopra Date: Thu, 4 Jul 2024 14:47:50 -0400 Subject: [PATCH] feat: attempt the request multiple times --- x/contracts/txmonitor/eth_helper.go | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/x/contracts/txmonitor/eth_helper.go b/x/contracts/txmonitor/eth_helper.go index 51b050250..5b1388ee8 100644 --- a/x/contracts/txmonitor/eth_helper.go +++ b/x/contracts/txmonitor/eth_helper.go @@ -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)