Skip to content

Commit

Permalink
Merge pull request #12 from airchains-network/alpha
Browse files Browse the repository at this point in the history
Add retry limit to transaction retrieval
  • Loading branch information
Noooblien authored Jul 23, 2024
2 parents 71b457e + 0de6d37 commit 941e34e
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion blocksync/txns.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,34 @@ func StoreEVMTransactions(client *ethclient.Client, ctx context.Context, ldt *le
)

txHash := common.HexToHash(transactionHash)
retryCount := 0
maxRetries := 7

for {
tx, isPending, err = client.TransactionByHash(ctx, txHash)
if err != nil {
logs.Log.Debug(fmt.Sprintf("Failed to get transaction hash: %s", txHash))
logs.Log.Debug(fmt.Sprintf("Error %s", err))

retryCount++
if retryCount > maxRetries {
logs.Log.Warn(fmt.Sprintf(" transaction hash not exist: %s after %d failed attempts", txHash, retryCount))
break
}

fmt.Println("Retrying the transaction after 10 seconds...")
time.Sleep(time.Second * 10) // Wait for 10 seconds before retrying
time.Sleep(time.Second * 5) // Wait for 5 seconds before retrying
continue
}

if isPending {
logs.Log.Debug("Transaction is pending, waiting for 5 seconds for tx Approval in blockchain")
logs.Log.Info(fmt.Sprintf("Transaction type: %d\n", tx.Type()))
// Retry after 5 seconds if transaction is pending
time.Sleep(time.Second * 5)
continue
}

break
}

Expand Down

0 comments on commit 941e34e

Please sign in to comment.