Skip to content

Commit

Permalink
Merge branch 'develop' into hedera_with_gas_estimation
Browse files Browse the repository at this point in the history
  • Loading branch information
simsonraj authored Oct 7, 2024
2 parents 3861edd + 67d4939 commit 8f63ab1
Showing 1 changed file with 27 additions and 19 deletions.
46 changes: 27 additions & 19 deletions integration-tests/actions/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ import (
)

const (
InsufficientFundsErr = "insufficient funds"
GasTooLowErr = "gas too low"
OvershotErr = "overshot"
InsufficientFundsErr = "insufficient funds"
TransactionUnderPriced = "transaction underpriced"
FailedToWaitForTransaction = "failed to wait for transaction"
GasTooLowErr = "gas too low"
OvershotErr = "overshot"
)

var (
Expand All @@ -52,21 +54,21 @@ func (r *InsufficientFundTransferRetrier) Retry(ctx context.Context, logger zero
if currentAttempt >= r.maxRetries {
if r.nextRetrier != nil {
logger.Debug().
Str("retier", "InsufficientFundTransferRetrier").
Str("retrier", "InsufficientFundTransferRetrier").
Msg("Max retries reached. Passing to next retrier")
return r.nextRetrier.Retry(ctx, logger, client, txErr, payload, 0)
}
return txErr
}

for txErr != nil && (strings.Contains(txErr.Error(), InsufficientFundsErr)) {
for txErr != nil && (strings.Contains(txErr.Error(), InsufficientFundsErr) || strings.Contains(txErr.Error(), TransactionUnderPriced) || strings.Contains(txErr.Error(), FailedToWaitForTransaction)) {
logger.Info().
Msg("Insufficient funds error detected, retrying with less funds")

newAmount := big.NewInt(0).Sub(payload.Amount, big.NewInt(blockchain.GWei))

logger.Debug().
Str("retier", "InsufficientFundTransferRetrier").
Str("retrier", "InsufficientFundTransferRetrier").
Str("old amount", payload.Amount.String()).
Str("new amount", newAmount.String()).
Str("diff", big.NewInt(0).Sub(payload.Amount, newAmount).String()).
Expand All @@ -77,25 +79,27 @@ func (r *InsufficientFundTransferRetrier) Retry(ctx context.Context, logger zero
_, retryErr := SendFunds(logger, client, payload)
if retryErr == nil {
logger.Info().
Str("retier", "InsufficientFundTransferRetrier").
Str("retrier", "InsufficientFundTransferRetrier").
Msg(RetrySuccessfulMsg)
return nil
}

if strings.Contains(retryErr.Error(), InsufficientFundsErr) {
if strings.Contains(retryErr.Error(), InsufficientFundsErr) || strings.Contains(retryErr.Error(), TransactionUnderPriced) || strings.Contains(retryErr.Error(), FailedToWaitForTransaction) {
return r.Retry(ctx, logger, client, retryErr, payload, currentAttempt+1)
}

txErr = retryErr
}

if r.nextRetrier != nil {
logger.Debug().
Str("retier", "InsufficientFundTransferRetrier").
Str("retrier", "InsufficientFundTransferRetrier").
Msg(NotSupportedMsg)
return r.nextRetrier.Retry(ctx, logger, client, txErr, payload, 0)
}

logger.Warn().
Str("retier", "InsufficientFundTransferRetrier").
Str("retrier", "InsufficientFundTransferRetrier").
Msg("No more retriers available. Unable to retry transaction. Returning error.")

return txErr
Expand All @@ -112,7 +116,7 @@ func (r *GasTooLowTransferRetrier) Retry(ctx context.Context, logger zerolog.Log
if payload.GasLimit != nil && *payload.GasLimit >= r.maxGasLimit {
if r.nextRetrier != nil {
logger.Debug().
Str("retier", "GasTooLowTransferRetrier").
Str("retrier", "GasTooLowTransferRetrier").
Msg("Max gas limit reached. Passing to next retrier")
return r.nextRetrier.Retry(ctx, logger, client, txErr, payload, 0)
}
Expand All @@ -130,7 +134,7 @@ func (r *GasTooLowTransferRetrier) Retry(ctx context.Context, logger zerolog.Log
}

logger.Debug().
Str("retier", "GasTooLowTransferRetrier").
Str("retrier", "GasTooLowTransferRetrier").
Int64("old gas limit", newGasLimit/2).
Int64("new gas limit", newGasLimit).
Int64("diff", newGasLimit).
Expand All @@ -141,25 +145,27 @@ func (r *GasTooLowTransferRetrier) Retry(ctx context.Context, logger zerolog.Log
_, retryErr := SendFunds(logger, client, payload)
if retryErr == nil {
logger.Info().
Str("retier", "GasTooLowTransferRetrier").
Str("retrier", "GasTooLowTransferRetrier").
Msg(RetrySuccessfulMsg)
return nil
}

if strings.Contains(retryErr.Error(), GasTooLowErr) {
return r.Retry(ctx, logger, client, retryErr, payload, currentAttempt+1)
}

txErr = retryErr
}

if r.nextRetrier != nil {
logger.Debug().
Str("retier", "OvershotTransferRetrier").
Str("retrier", "GasTooLowTransferRetrier").
Msg(NotSupportedMsg)
return r.nextRetrier.Retry(ctx, logger, client, txErr, payload, 0)
}

logger.Warn().
Str("retier", "OvershotTransferRetrier").
Str("retrier", "GasTooLowTransferRetrier").
Msg("No more retriers available. Unable to retry transaction. Returning error.")

return txErr
Expand All @@ -175,7 +181,7 @@ type OvershotTransferRetrier struct {
func (r *OvershotTransferRetrier) Retry(ctx context.Context, logger zerolog.Logger, client *seth.Client, txErr error, payload FundsToSendPayload, currentAttempt int) error {
if currentAttempt >= r.maxRetries {
logger.Debug().
Str("retier", "OvershotTransferRetrier").
Str("retrier", "OvershotTransferRetrier").
Msg("Max retries reached. Passing to next retrier")
if r.nextRetrier != nil {
return r.nextRetrier.Retry(ctx, logger, client, txErr, payload, 0)
Expand All @@ -199,7 +205,7 @@ func (r *OvershotTransferRetrier) Retry(ctx context.Context, logger zerolog.Logg

newAmount := big.NewInt(0).Sub(payload.Amount, big.NewInt(int64(overshotAmount)))
logger.Debug().
Str("retier", "OvershotTransferRetrier").
Str("retrier", "OvershotTransferRetrier").
Str("old amount", payload.Amount.String()).
Str("new amount", newAmount.String()).
Str("diff", big.NewInt(0).Sub(payload.Amount, newAmount).String()).
Expand All @@ -210,19 +216,21 @@ func (r *OvershotTransferRetrier) Retry(ctx context.Context, logger zerolog.Logg
_, retryErr := SendFunds(logger, client, payload)
if retryErr == nil {
logger.Info().
Str("retier", "OvershotTransferRetrier").
Str("retrier", "OvershotTransferRetrier").
Msg(RetrySuccessfulMsg)
return nil
}

if strings.Contains(retryErr.Error(), OvershotErr) {
return r.Retry(ctx, logger, client, retryErr, payload, currentAttempt+1)
}

txErr = retryErr
}

if r.nextRetrier != nil {
logger.Debug().
Str("retier", "OvershotTransferRetrier").
Str("retrier", "OvershotTransferRetrier").
Msg(NotSupportedMsg)
return r.nextRetrier.Retry(ctx, logger, client, txErr, payload, 0)
}
Expand Down

0 comments on commit 8f63ab1

Please sign in to comment.