Skip to content

Commit

Permalink
centralised ephemeral keys on testnet check, fixed keeper smoke tests…
Browse files Browse the repository at this point in the history
…, added root key buffer check
  • Loading branch information
Tofel committed Apr 22, 2024
1 parent 7e77724 commit b04528a
Show file tree
Hide file tree
Showing 18 changed files with 261 additions and 154 deletions.
15 changes: 9 additions & 6 deletions integration-tests/actions/automationv2/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
ocr2keepers20config "github.com/smartcontractkit/chainlink-automation/pkg/v2/config"
ocr2keepers30config "github.com/smartcontractkit/chainlink-automation/pkg/v3/config"

actions_seth "github.com/smartcontractkit/chainlink/integration-tests/actions/seth"
"github.com/smartcontractkit/chainlink/integration-tests/docker/test_env"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/automation_registrar_wrapper2_1"

Expand Down Expand Up @@ -583,7 +584,10 @@ func calculateOCR3ConfigArgs(a *AutomationTest, S []int, oracleIdentities []conf

func (a *AutomationTest) RegisterUpkeeps(upkeepConfigs []UpkeepConfig) ([]common.Hash, error) {
registrationTxHashes := make([]common.Hash, 0)
concurrency := a.GetConcurrency()
concurrency, err := actions_seth.GetAndAssertCorrectConcurrency(a.ChainClient, 1)
if err != nil {
return nil, err
}

type result struct {
txHash common.Hash
Expand Down Expand Up @@ -721,7 +725,10 @@ func (a *AutomationTest) RegisterUpkeeps(upkeepConfigs []UpkeepConfig) ([]common
func (a *AutomationTest) ConfirmUpkeepsRegistered(registrationTxHashes []common.Hash) ([]*big.Int, error) {
upkeepIds := make([]*big.Int, 0)

concurrency := a.GetConcurrency()
concurrency, err := actions_seth.GetAndAssertCorrectConcurrency(a.ChainClient, 1)
if err != nil {
return nil, err
}

type result struct {
upkeepID *big.Int
Expand Down Expand Up @@ -904,7 +911,3 @@ func (a *AutomationTest) LoadAutomationDeployment(t *testing.T, linkTokenAddress

a.AddJobsAndSetConfig(t)
}

func (a *AutomationTest) GetConcurrency() int {
return int(*a.ChainClient.Cfg.EphemeralAddrs)
}
38 changes: 34 additions & 4 deletions integration-tests/actions/seth/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -887,10 +887,6 @@ func SendLinkFundsToDeploymentAddresses(
return data, nil
}

if *chainClient.Cfg.EphemeralAddrs == 0 {
return nil
}

toTransferToMultiCallContract := big.NewInt(0).Mul(linkAmountPerUpkeep, big.NewInt(int64(totalUpkeeps+concurrency)))
toTransferPerClient := big.NewInt(0).Mul(linkAmountPerUpkeep, big.NewInt(int64(operationsPerAddress+1)))
err := linkToken.Transfer(multicallAddress.Hex(), toTransferToMultiCallContract)
Expand Down Expand Up @@ -951,6 +947,40 @@ var noOpSethConfigFn = func(cfg *seth.Config) error { return nil }

type SethConfigFunction = func(*seth.Config) error

// OneEphemeralKeysLiveTestnetCheckFn checks whether there's at least one ephemeral key on a simulated network or at least one static key on a live network,
// and that there are no epehemeral keys on a live network. Root key is excluded from the check.
var OneEphemeralKeysLiveTestnetCheckFn = func(sethCfg *seth.Config) error {
concurrency := sethCfg.GetMaxConcurrency()

if sethCfg.IsSimulatedNetwork() {
if concurrency < 1 {
return fmt.Errorf(INSUFFICIENT_EPHEMERAL_KEYS, 0)
}

return nil
}

if sethCfg.EphemeralAddrs != nil && int(*sethCfg.EphemeralAddrs) > 0 {
ephMsg := `
Error: Ephemeral Addresses Detected on Live Network
Ephemeral addresses are currently set for use on a live network, which is not permitted. The number of ephemeral addresses set is %d. Please make the following update to your TOML configuration file to correct this:
'[Seth] ephemeral_addresses_number = 0'
Additionally, ensure the following requirements are met to run this test on a live network:
1. Use more than one private key in your network configuration.
`

return errors.New(ephMsg)
}

if concurrency < 1 {
return fmt.Errorf(INSUFFICIENT_STATIC_KEYS, len(sethCfg.Network.PrivateKeys))
}

return nil
}

// GetChainClient returns a seth client for the given network after validating the config
func GetChainClient(config tc.SethConfig, network blockchain.EVMNetwork) (*seth.Client, error) {
return GetChainClientWithConfigFunction(config, network, noOpSethConfigFn)
Expand Down
6 changes: 5 additions & 1 deletion integration-tests/actions/seth/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,11 @@ func DeployMultiCallAndFundDeploymentAddresses(
numberOfUpkeeps int,
linkFundsForEachUpkeep *big.Int,
) error {
concurrency := int(*chainClient.Cfg.EphemeralAddrs)
concurrency, err := GetAndAssertCorrectConcurrency(chainClient, 1)
if err != nil {
return err
}

operationsPerAddress := numberOfUpkeeps / concurrency

multicallAddress, err := contracts.DeployMultiCallContract(chainClient)
Expand Down
56 changes: 51 additions & 5 deletions integration-tests/actions/seth/keeper_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,8 @@ func RegisterUpkeepContractsWithCheckData(t *testing.T, client *seth.Client, lin
registrationTxHashes := make([]common.Hash, 0)
upkeepIds := make([]*big.Int, 0)

concurrency := int(*client.Cfg.EphemeralAddrs)
require.GreaterOrEqual(t, concurrency, 1, "You need at least 1 ephemeral address to deploy consumers. Please set them in TOML config. Example: `[Seth] ephemeral_addresses_number = 10`")
concurrency, err := GetAndAssertCorrectConcurrency(client, 1)
require.NoError(t, err, "Insufficient concurrency to execute action")

type config struct {
address string
Expand Down Expand Up @@ -374,8 +374,8 @@ func DeployKeeperConsumers(t *testing.T, client *seth.Client, numberOfContracts
l := logging.GetTestLogger(t)
keeperConsumerContracts := make([]contracts.KeeperConsumer, 0)

concurrency := int(*client.Cfg.EphemeralAddrs)
require.GreaterOrEqual(t, concurrency, 1, "You need at least 1 ephemeral address to deploy consumers. Please set them in TOML config. Example: `[Seth] ephemeral_addresses_number = 10`")
concurrency, err := GetAndAssertCorrectConcurrency(client, 1)
require.NoError(t, err, "Insufficient concurrency to execute action")

type result struct {
contract contracts.KeeperConsumer
Expand Down Expand Up @@ -601,7 +601,9 @@ func RegisterNewUpkeeps(
addressesOfNewUpkeeps = append(addressesOfNewUpkeeps, upkeep.Address())
}

concurrency := int(*chainClient.Cfg.EphemeralAddrs)
concurrency, err := GetAndAssertCorrectConcurrency(chainClient, 1)
require.NoError(t, err, "Insufficient concurrency to execute action")

operationsPerAddress := numberOfNewUpkeeps / concurrency

multicallAddress, err := contracts.DeployMultiCallContract(chainClient)
Expand All @@ -616,3 +618,47 @@ func RegisterNewUpkeeps(

return newlyDeployedUpkeeps, newUpkeepIDs
}

var INSUFFICIENT_EPHEMERAL_KEYS = `
Error: Insufficient Ephemeral Addresses for Simulated Network
To operate on a simulated network, you must configure at least one ephemeral address. Currently, %d ephemeral address(es) are set. Please update your TOML configuration file as follows to meet this requirement:
[Seth] ephemeral_addresses_number = 1
This adjustment ensures that your setup is minimaly viable. Although it is highly recommended to use at least 20 ephemeral addresses.
`

var INSUFFICIENT_STATIC_KEYS = `
Error: Insufficient Private Keys for Live Network
To run this test on a live network, you must either:
1. Set at least two private keys in the '[Network.WalletKeys]' section of your TOML configuration file. Example format:
[Network.WalletKeys]
NETWORK_NAME=["PRIVATE_KEY_1", "PRIVATE_KEY_2"]
2. Set at least two private keys in the '[Network.EVMNetworks.NETWORK_NAME] section of your TOML configuration file. Example format:
evm_keys=["PRIVATE_KEY_1", "PRIVATE_KEY_2"]
Currently, only %d private key/s is/are set.
Recommended Action:
Distribute your funds across multiple private keys and update your configuration accordingly. Even though 1 private key is sufficient for testing, it is highly recommended to use at least 10 private keys.
`

// GetAndAssertCorrectConcurrency checks Seth configuration for the number of ephemeral keys or static keys (depending on Seth configuration) and makes sure that
// the number is at least minConcurrency. If the number is less than minConcurrency, it returns an error. Root key is always excuded from the count.
func GetAndAssertCorrectConcurrency(client *seth.Client, minConcurrency int) (int, error) {
concurrency := client.Cfg.GetMaxConcurrency()

var msg string
if client.Cfg.IsSimulatedNetwork() {
msg = fmt.Sprintf(INSUFFICIENT_EPHEMERAL_KEYS, concurrency)
} else {
msg = fmt.Sprintf(INSUFFICIENT_STATIC_KEYS, concurrency)
}

if concurrency < minConcurrency {
return 0, fmt.Errorf(msg)
}

return concurrency, nil
}
7 changes: 5 additions & 2 deletions integration-tests/benchmark/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,9 @@ func TestAutomationBenchmark(t *testing.T) {
benchmarkTestNetwork := getNetworkConfig(&config)

l.Info().Str("Namespace", testEnvironment.Cfg.Namespace).Msg("Connected to Keepers Benchmark Environment")

testNetwork := utils.MustReplaceSimulatedNetworkUrlWithK8(l, benchmarkNetwork, *testEnvironment)

chainClient, err := actions_seth.GetChainClient(&config, testNetwork)
chainClient, err := actions_seth.GetChainClientWithConfigFunction(&config, testNetwork, actions_seth.OneEphemeralKeysLiveTestnetCheckFn)
require.NoError(t, err, "Error getting Seth client")

registryVersions := addRegistry(&config)
Expand Down Expand Up @@ -331,6 +330,10 @@ func SetupAutomationBenchmarkEnv(t *testing.T, keeperTestConfig types.KeeperBenc
numberOfNodes++
}

networkName := strings.ReplaceAll(testNetwork.Name, " ", "-")
networkName = strings.ReplaceAll(networkName, "_", "-")
testNetwork.Name = networkName

testEnvironment := environment.New(&environment.Config{
TTL: time.Hour * 720, // 30 days,
NamespacePrefix: fmt.Sprintf(
Expand Down
13 changes: 1 addition & 12 deletions integration-tests/chaos/automation_chaos_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"time"

"github.com/onsi/gomega"
"github.com/smartcontractkit/seth"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -247,17 +246,7 @@ func TestAutomationChaos(t *testing.T) {

network = utils.MustReplaceSimulatedNetworkUrlWithK8(l, network, *testEnvironment)

sethConfigFn := func(sethCfg *seth.Config) error {
if sethCfg.IsSimulatedNetwork() {
require.Equal(t, int(*sethCfg.EphemeralAddrs), 0, "You must not use ephemeral addresses on a simulated network. Please update '[Seth] ephemeral_addresses_number = 0' field in the TOML config file", *sethCfg.EphemeralAddrs)
// take only the first key, all others are not funded in genesis and will crash the test ¯\_(ツ)_/¯
sethCfg.Network.PrivateKeys = sethCfg.Network.PrivateKeys[0:1]
}

return nil
}

chainClient, err := actions_seth.GetChainClientWithConfigFunction(&config, network, sethConfigFn)
chainClient, err := actions_seth.GetChainClientWithConfigFunction(&config, network, actions_seth.OneEphemeralKeysLiveTestnetCheckFn)
require.NoError(t, err, "Error creating seth client")

// Register cleanup for any test
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/docker/test_env/test_env_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {
}

if b.hasSeth {
seth, err := actions_seth.GetChainClient(b.testConfig, networkConfig)
seth, err := actions_seth.GetChainClientWithConfigFunction(b.testConfig, networkConfig, actions_seth.OneEphemeralKeysLiveTestnetCheckFn)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -416,7 +416,7 @@ func (b *CLTestEnvBuilder) Build() (*CLClusterTestEnv, error) {

if b.hasSeth {
b.te.sethClients = make(map[int64]*seth.Client)
seth, err := actions_seth.GetChainClient(b.testConfig, networkConfig)
seth, err := actions_seth.GetChainClientWithConfigFunction(b.testConfig, networkConfig, actions_seth.OneEphemeralKeysLiveTestnetCheckFn)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ require (
github.com/smartcontractkit/chainlink-vrf v0.0.0-20240222010609-cd67d123c772
github.com/smartcontractkit/chainlink/v2 v2.0.0-00010101000000-000000000000
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052
github.com/smartcontractkit/seth v0.1.6-0.20240416163802-874941ddafe0
github.com/smartcontractkit/seth v0.1.6-0.20240422133624-326a80f0e828
github.com/smartcontractkit/wasp v0.4.7
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1539,8 +1539,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052 h1:1WFjrrVrWoQ9UpVMh7Mx4jDpzhmo1h8hFUKd9awIhIU=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052/go.mod h1:SJEZCHgMCAzzBvo9vMV2DQ9onfEcIJCYSViyP4JI6c4=
github.com/smartcontractkit/seth v0.1.6-0.20240416163802-874941ddafe0 h1:pmszbHy+Bi3WE9QguhsiSVwFHwHWCBZMldUxEBYjPH0=
github.com/smartcontractkit/seth v0.1.6-0.20240416163802-874941ddafe0/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero=
github.com/smartcontractkit/seth v0.1.6-0.20240422133624-326a80f0e828 h1:fJv2+66PvfpASpt1Fq/R9BhYMHgD5I/SRp95IozqNj0=
github.com/smartcontractkit/seth v0.1.6-0.20240422133624-326a80f0e828/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero=
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE=
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg=
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ=
Expand Down
10 changes: 2 additions & 8 deletions integration-tests/load/automationv2_1/automationv2_1_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import (

"github.com/pkg/errors"

"github.com/smartcontractkit/seth"

geth "github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
Expand Down Expand Up @@ -322,11 +320,7 @@ Load Config:

testNetwork = utils.MustReplaceSimulatedNetworkUrlWithK8(l, testNetwork, *testEnvironment)

sethConfigFn := func(sethCfg *seth.Config) error {
return utils.ValidateAddressesTypeAndNumber(sethCfg, 50)
}

chainClient, err := actions_seth.GetChainClientWithConfigFunction(loadedTestConfig, testNetwork, sethConfigFn)
chainClient, err := actions_seth.GetChainClientWithConfigFunction(loadedTestConfig, testNetwork, actions_seth.OneEphemeralKeysLiveTestnetCheckFn)
require.NoError(t, err, "Error creating seth client")

chainlinkNodes, err := client.ConnectChainlinkNodes(testEnvironment)
Expand Down Expand Up @@ -430,7 +424,7 @@ Load Config:
}

for _, u := range loadedTestConfig.Automation.Load {
deploymentData, err := deployConsumerAndTriggerContracts(l, u, a.ChainClient, a.GetConcurrency(), multicallAddress, automationDefaultLinkFunds, a.LinkToken)
deploymentData, err := deployConsumerAndTriggerContracts(l, u, a.ChainClient, multicallAddress, automationDefaultLinkFunds, a.LinkToken)
require.NoError(t, err, "Error deploying consumer and trigger contracts")

consumerContracts = append(consumerContracts, deploymentData.ConsumerContracts...)
Expand Down
7 changes: 6 additions & 1 deletion integration-tests/load/automationv2_1/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,14 @@ type DeploymentData struct {
LoadConfigs []aconfig.Load
}

func deployConsumerAndTriggerContracts(l zerolog.Logger, loadConfig aconfig.Load, chainClient *seth.Client, concurrency int, multicallAddress common.Address, automationDefaultLinkFunds *big.Int, linkToken contracts.LinkToken) (DeploymentData, error) {
func deployConsumerAndTriggerContracts(l zerolog.Logger, loadConfig aconfig.Load, chainClient *seth.Client, multicallAddress common.Address, automationDefaultLinkFunds *big.Int, linkToken contracts.LinkToken) (DeploymentData, error) {
data := DeploymentData{}

concurrency, err := actions_seth.GetAndAssertCorrectConcurrency(chainClient, 1)
if err != nil {
return DeploymentData{}, err
}

type deployedContractData struct {
consumerContract contracts.KeeperConsumer
triggerContract contracts.LogEmitter
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/load/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ require (
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240214231432-4ad5eb95178c
github.com/smartcontractkit/chainlink/v2 v2.9.0-beta0.0.20240216210048-da02459ddad8
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052
github.com/smartcontractkit/seth v0.1.6-0.20240416163802-874941ddafe0
github.com/smartcontractkit/seth v0.1.6-0.20240422133624-326a80f0e828
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1
github.com/smartcontractkit/wasp v0.4.7
github.com/stretchr/testify v1.9.0
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/load/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1530,8 +1530,8 @@ github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJ
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052 h1:1WFjrrVrWoQ9UpVMh7Mx4jDpzhmo1h8hFUKd9awIhIU=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052/go.mod h1:SJEZCHgMCAzzBvo9vMV2DQ9onfEcIJCYSViyP4JI6c4=
github.com/smartcontractkit/seth v0.1.6-0.20240416163802-874941ddafe0 h1:pmszbHy+Bi3WE9QguhsiSVwFHwHWCBZMldUxEBYjPH0=
github.com/smartcontractkit/seth v0.1.6-0.20240416163802-874941ddafe0/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero=
github.com/smartcontractkit/seth v0.1.6-0.20240422133624-326a80f0e828 h1:fJv2+66PvfpASpt1Fq/R9BhYMHgD5I/SRp95IozqNj0=
github.com/smartcontractkit/seth v0.1.6-0.20240422133624-326a80f0e828/go.mod h1:2TMOZQ8WTAw7rR1YBbXpnad6VmT/+xDd/nXLmB7Eero=
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1 h1:yiKnypAqP8l0OX0P3klzZ7SCcBUxy5KqTAKZmQOvSQE=
github.com/smartcontractkit/tdh2/go/ocr2/decryptionplugin v0.0.0-20230906073235-9e478e5e19f1/go.mod h1:q6f4fe39oZPdsh1i57WznEZgxd8siidMaSFq3wdPmVg=
github.com/smartcontractkit/tdh2/go/tdh2 v0.0.0-20230906073235-9e478e5e19f1 h1:Dai1bn+Q5cpeGMQwRdjOdVjG8mmFFROVkSKuUgBErRQ=
Expand Down
Loading

0 comments on commit b04528a

Please sign in to comment.