Skip to content

Commit

Permalink
Funds refund fixes and optimisation (#12485)
Browse files Browse the repository at this point in the history
* use transfer gas fee instead of gas limit when sending/returning funds, do not return on first error

* add go work to dockerignore so it doesn't mess up building local image
  • Loading branch information
Tofel authored Mar 19, 2024
1 parent 07c9f6c commit b790f6c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,6 @@ codeship-*.yml
dockercfg
credentials.env
gcr_creds.env

go.work
go.work.sum
2 changes: 1 addition & 1 deletion integration-tests/actions/seth/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
return nil, err
}

gasLimit := uint64(client.Cfg.Network.GasLimit)
gasLimit := uint64(client.Cfg.Network.TransferGasFee)
if payload.GasLimit != nil {
gasLimit = *payload.GasLimit
}
Expand Down
29 changes: 24 additions & 5 deletions integration-tests/actions/seth/refund.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/ethereum/go-ethereum/accounts/keystore"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/pkg/errors"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -50,7 +51,7 @@ func (r *InsufficientFundTransferRetrier) Retry(ctx context.Context, logger zero
if r.nextRetrier != nil {
logger.Debug().
Str("retier", "InsufficientFundTransferRetrier").
Msg("Max gas limit reached. Passing to next retrier")
Msg("Max retries reached. Passing to next retrier")
return r.nextRetrier.Retry(ctx, logger, client, txErr, payload, 0)
}
return txErr
Expand Down Expand Up @@ -241,6 +242,8 @@ func ReturnFunds(log zerolog.Logger, seth *seth.Client, chainlinkNodes []contrac
return nil
}

failedReturns := []common.Address{}

for _, chainlinkNode := range chainlinkNodes {
fundedKeys, err := chainlinkNode.ExportEVMKeysForChain(fmt.Sprint(seth.ChainID))
if err != nil {
Expand Down Expand Up @@ -272,9 +275,9 @@ func ReturnFunds(log zerolog.Logger, seth *seth.Client, chainlinkNodes []contrac

var totalGasCost *big.Int
if seth.Cfg.Network.EIP1559DynamicFees {
totalGasCost = new(big.Int).Mul(big.NewInt(0).SetUint64(seth.Cfg.Network.GasLimit), big.NewInt(0).SetInt64(seth.Cfg.Network.GasFeeCap))
totalGasCost = new(big.Int).Mul(big.NewInt(0).SetInt64(seth.Cfg.Network.TransferGasFee), big.NewInt(0).SetInt64(seth.Cfg.Network.GasFeeCap))
} else {
totalGasCost = new(big.Int).Mul(big.NewInt(0).SetUint64(seth.Cfg.Network.GasLimit), big.NewInt(0).SetInt64(seth.Cfg.Network.GasPrice))
totalGasCost = new(big.Int).Mul(big.NewInt(0).SetInt64(seth.Cfg.Network.TransferGasFee), big.NewInt(0).SetInt64(seth.Cfg.Network.GasPrice))
}

toSend := new(big.Int).Sub(balance, totalGasCost)
Expand All @@ -286,17 +289,33 @@ func ReturnFunds(log zerolog.Logger, seth *seth.Client, chainlinkNodes []contrac
Str("Balance", balance.String()).
Str("To send", toSend.String()).
Msg("Not enough balance to cover gas cost. Skipping return.")

failedReturns = append(failedReturns, fromAddress)
continue
}

payload := FundsToSendPayload{ToAddress: seth.Addresses[0], Amount: toSend, PrivateKey: decryptedKey.PrivateKey}

_, err = SendFunds(log, seth, payload)
if err != nil {
handler := OvershotTransferRetrier{maxRetries: 3, nextRetrier: &InsufficientFundTransferRetrier{maxRetries: 3, nextRetrier: &GasTooLowTransferRetrier{maxGasLimit: seth.Cfg.Network.GasLimit * 3}}}
return handler.Retry(context.Background(), log, seth, err, payload, 0)
handler := OvershotTransferRetrier{maxRetries: 10, nextRetrier: &InsufficientFundTransferRetrier{maxRetries: 10, nextRetrier: &GasTooLowTransferRetrier{maxGasLimit: uint64(seth.Cfg.Network.TransferGasFee * 10)}}}
err = handler.Retry(context.Background(), log, seth, err, payload, 0)
if err != nil {
log.Error().
Err(err).
Str("Address", fromAddress.String()).
Msg("Failed to return funds from Chainlink node to default network wallet")
failedReturns = append(failedReturns, fromAddress)
}
}
}
}

if len(failedReturns) > 0 {
return fmt.Errorf("failed to return funds from Chainlink nodes to default network wallet for addresses: %v", failedReturns)
}

log.Info().Msg("Successfully returned funds from all Chainlink nodes to default network wallets")

return nil
}

0 comments on commit b790f6c

Please sign in to comment.