Skip to content

Commit

Permalink
chore: updated retry parameters to check transaction mined status (ra…
Browse files Browse the repository at this point in the history
…zor-network#1255)

* chore: updated parameters to check transaction mined status

* feat: added timeout over WaitForBlockCompletion
  • Loading branch information
Yashk767 authored Oct 22, 2024
1 parent 72b6be4 commit b0751a5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 12 deletions.
5 changes: 3 additions & 2 deletions core/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ const (
var NilHash = common.Hash{0x00}

const (
BlockCompletionAttempts = 3
BlockCompletionAttemptRetryDelay = 1
BlockCompletionAttempts = 4
BlockCompletionAttemptRetryDelay = 2
BlockCompletionTimeout = 15
)

//Following are the default config values for all the config parameters
Expand Down
32 changes: 22 additions & 10 deletions utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,19 +60,31 @@ func (*UtilsStruct) CheckTransactionReceipt(client *ethclient.Client, _txHash st
}

func (*UtilsStruct) WaitForBlockCompletion(client *ethclient.Client, hashToRead string) error {
ctx, cancel := context.WithTimeout(context.Background(), core.BlockCompletionTimeout*time.Second)
defer cancel()

for i := 0; i < core.BlockCompletionAttempts; i++ {
log.Debug("Checking if transaction is mined....")
transactionStatus := UtilsInterface.CheckTransactionReceipt(client, hashToRead)
if transactionStatus == 0 {
err := errors.New("transaction mining unsuccessful")
log.Error(err)
return err
} else if transactionStatus == 1 {
log.Info("Transaction mined successfully")
return nil
select {
case <-ctx.Done():
log.Error("Timeout: WaitForBlockCompletion took too long")
return errors.New("timeout exceeded for transaction mining")
default:
log.Debug("Checking if transaction is mined....")
transactionStatus := UtilsInterface.CheckTransactionReceipt(client, hashToRead)

if transactionStatus == 0 {
err := errors.New("transaction mining unsuccessful")
log.Error(err)
return err
} else if transactionStatus == 1 {
log.Info("Transaction mined successfully")
return nil
}

time.Sleep(core.BlockCompletionAttemptRetryDelay * time.Second)
}
Time.Sleep(core.BlockCompletionAttemptRetryDelay * time.Second)
}

log.Info("Max retries for WaitForBlockCompletion attempted!")
return errors.New("maximum attempts failed for transaction mining")
}
Expand Down

0 comments on commit b0751a5

Please sign in to comment.