Skip to content

Commit

Permalink
Mumbai soak fix light (#12384)
Browse files Browse the repository at this point in the history
* use EIP-1559 for sending funds (if enabled), validate Seth config, return early on error during funds sending

* hacky fix for Duration copying for now
  • Loading branch information
Tofel authored Mar 11, 2024
1 parent 18c7237 commit bb0a33f
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 21 deletions.
45 changes: 27 additions & 18 deletions integration-tests/actions/seth/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ func FundChainlinkNodes(
privateKey *ecdsa.PrivateKey,
amount *big.Float,
) error {
fundingErrors := []error{}
for _, cl := range nodes {
toAddress, err := cl.PrimaryEthAddress()
if err != nil {
Expand All @@ -70,12 +69,12 @@ func FundChainlinkNodes(
PrivateKey: privateKey,
})
if err != nil {
fundingErrors = append(fundingErrors, err)

logger.Err(err).
Str("From", fromAddress.Hex()).
Str("To", toAddress).
Msg("Failed to fund Chainlink node")

return err
}

txHash := "(none)"
Expand All @@ -91,14 +90,6 @@ func FundChainlinkNodes(
Msg("Funded Chainlink node")
}

if len(fundingErrors) > 0 {
var wrapped error
for _, e := range fundingErrors {
wrapped = errors.Wrapf(e, ",")
}
return fmt.Errorf("failed to fund chainlink nodes due to following errors: %w", wrapped)
}

return nil
}

Expand Down Expand Up @@ -130,14 +121,29 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
gasLimit = *payload.GasLimit
}

rawTx := &types.LegacyTx{
Nonce: nonce,
To: &payload.ToAddress,
Value: payload.Amount,
Gas: gasLimit,
GasPrice: big.NewInt(client.Cfg.Network.GasPrice),
var signedTx *types.Transaction

if client.Cfg.Network.EIP1559DynamicFees {
rawTx := &types.DynamicFeeTx{
Nonce: nonce,
To: &payload.ToAddress,
Value: payload.Amount,
Gas: gasLimit,
GasFeeCap: big.NewInt(client.Cfg.Network.GasFeeCap),
GasTipCap: big.NewInt(client.Cfg.Network.GasTipCap),
}
signedTx, err = types.SignNewTx(payload.PrivateKey, types.NewLondonSigner(big.NewInt(client.ChainID)), rawTx)
} else {
rawTx := &types.LegacyTx{
Nonce: nonce,
To: &payload.ToAddress,
Value: payload.Amount,
Gas: gasLimit,
GasPrice: big.NewInt(client.Cfg.Network.GasPrice),
}
signedTx, err = types.SignNewTx(payload.PrivateKey, types.NewEIP155Signer(big.NewInt(client.ChainID)), rawTx)
}
signedTx, err := types.SignNewTx(payload.PrivateKey, types.NewEIP155Signer(big.NewInt(client.ChainID)), rawTx)

if err != nil {
return nil, errors.Wrap(err, "failed to sign tx")
}
Expand All @@ -157,6 +163,9 @@ func SendFunds(logger zerolog.Logger, client *seth.Client, payload FundsToSendPa
Uint64("Nonce", nonce).
Uint64("Gas Limit", gasLimit).
Int64("Gas Price", client.Cfg.Network.GasPrice).
Int64("Gas Fee Cap", client.Cfg.Network.GasFeeCap).
Int64("Gas Tip Cap", client.Cfg.Network.GasTipCap).
Bool("Dynamic fees", client.Cfg.Network.EIP1559DynamicFees).
Msg("Sent funds")

return client.WaitMined(ctx, logger, client.Client, signedTx)
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/chaos/ocr_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ func TestOCRChaos(t *testing.T) {
network = utils.MustReplaceSimulatedNetworkUrlWithK8(l, network, *testEnvironment)

sethCfg := utils.MergeSethAndEvmNetworkConfigs(l, network, *readSethCfg)
err = utils.ValidateSethNetworkConfig(sethCfg.Network)
require.NoError(t, err, "Error validating seth network config")
seth, err := seth.NewClientWithConfig(&sethCfg)
require.NoError(t, err, "Error creating seth client")

Expand Down
4 changes: 4 additions & 0 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
if b.hasSeth {
readSethCfg := b.testConfig.GetSethConfig()
sethCfg := utils.MergeSethAndEvmNetworkConfigs(b.l, networkConfig, *readSethCfg)
err = utils.ValidateSethNetworkConfig(sethCfg.Network)
if err != nil {
return nil, err
}
seth, err := seth.NewClientWithConfig(&sethCfg)
if err != nil {
return nil, err
Expand Down
7 changes: 4 additions & 3 deletions integration-tests/testconfig/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,13 @@ gas_tip_cap = 10_000_000_000
name = "Mumbai"
chain_id = "80001"
transaction_timeout = "3m"
transfer_gas_fee = 21_000
transfer_gas_fee = 40_000
gas_limit = 6_000_000
# legacy transactions
#gas_price = 1_800_000_000
# EIP-1559 transactions
eip_1559_dynamic_fees = true
gas_fee_cap = 1_800_000_000
gas_fee_cap = 3_800_000_000
gas_tip_cap = 1_800_000_000

[[Seth.networks]]
Expand All @@ -104,5 +105,5 @@ gas_limit = 3_000_000
gas_price = 50_000_000
# EIP-1559 transactions
#eip_1559_dynamic_fees = true
gas_fee_cap = 1_800_000_000
gas_fee_cap = 3_800_000_000
gas_tip_cap = 1_800_000_000
11 changes: 11 additions & 0 deletions integration-tests/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,17 @@ func handleDefaultConfigOverride(logger zerolog.Logger, filename, configurationN
return errors.Wrapf(err, "error reading file %s", filename)
}

// temporary fix for Duration not being correctly copied
if oldConfig != nil && oldConfig.Seth != nil && oldConfig.Seth.Networks != nil {
for i, old_network := range oldConfig.Seth.Networks {
for _, target_network := range target.Seth.Networks {
if old_network.ChainID == target_network.ChainID {
oldConfig.Seth.Networks[i].TxnTimeout = old_network.TxnTimeout
}
}
}
}

// override instead of merging
if (newConfig.Seth != nil && len(newConfig.Seth.Networks) > 0) && (oldConfig != nil && oldConfig.Seth != nil && len(oldConfig.Seth.Networks) > 0) {
for i, old_network := range oldConfig.Seth.Networks {
Expand Down
2 changes: 2 additions & 0 deletions integration-tests/testsetups/ocr.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@ func (o *OCRSoakTest) Setup(ocrTestConfig tt.OcrTestConfig) {
require.NotNil(o.t, readSethCfg, "Seth config shouldn't be nil")

sethCfg := utils.MergeSethAndEvmNetworkConfigs(o.log, network, *readSethCfg)
err = utils.ValidateSethNetworkConfig(sethCfg.Network)
require.NoError(o.t, err, "Error validating seth network config")

seth, err := seth.NewClientWithConfig(&sethCfg)
require.NoError(o.t, err, "Error creating seth client")
Expand Down
47 changes: 47 additions & 0 deletions integration-tests/utils/seth.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package utils

import (
"fmt"
"strconv"

"github.com/rs/zerolog"
"github.com/smartcontractkit/seth"
Expand Down Expand Up @@ -82,3 +83,49 @@ func MustReplaceSimulatedNetworkUrlWithK8(l zerolog.Logger, network blockchain.E

return network
}

// ValidateSethNetworkConfig validates the Seth network config
func ValidateSethNetworkConfig(cfg *seth.Network) error {
if cfg == nil {
return fmt.Errorf("Network cannot be nil")
}
if cfg.ChainID == "" {
return fmt.Errorf("ChainID is required")
}
_, err := strconv.Atoi(cfg.ChainID)
if err != nil {
return fmt.Errorf("ChainID needs to be a number")
}
if cfg.URLs == nil || len(cfg.URLs) == 0 {
return fmt.Errorf("URLs are required")
}
if cfg.PrivateKeys == nil || len(cfg.PrivateKeys) == 0 {
return fmt.Errorf("PrivateKeys are required")
}
if cfg.TransferGasFee == 0 {
return fmt.Errorf("TransferGasFee needs to be above 0. It's the gas fee for a simple transfer transaction")
}
if cfg.TxnTimeout.Duration() == 0 {
return fmt.Errorf("TxnTimeout needs to be above 0. It's the timeout for a transaction")
}
if cfg.GasLimit == 0 {
return fmt.Errorf("GasLimit needs to be above 0. It's the gas limit for a transaction")
}
if cfg.EIP1559DynamicFees {
if cfg.GasFeeCap == 0 {
return fmt.Errorf("GasFeeCap needs to be above 0. It's the maximum fee per gas for a transaction (including tip)")
}
if cfg.GasTipCap == 0 {
return fmt.Errorf("GasTipCap needs to be above 0. It's the maximum tip per gas for a transaction")
}
if cfg.GasFeeCap <= cfg.GasTipCap {
return fmt.Errorf("GasFeeCap needs to be above GasTipCap (as it is base fee + tip cap)")
}
} else {
if cfg.GasPrice == 0 {
return fmt.Errorf("GasPrice needs to be above 0. It's the price of gas for a transaction")
}
}

return nil
}

0 comments on commit bb0a33f

Please sign in to comment.