Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: updated retry parameters to check transaction mined status #1255

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading