Skip to content

Commit

Permalink
support v2.3 in benchmark test
Browse files Browse the repository at this point in the history
  • Loading branch information
anirudhwarrier committed Aug 6, 2024
1 parent 2d28d42 commit 08687df
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 75 deletions.
95 changes: 33 additions & 62 deletions integration-tests/benchmark/keeper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,26 @@ import (
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-testing-framework/blockchain"
ctf_config "github.com/smartcontractkit/chainlink-testing-framework/config"
env_client "github.com/smartcontractkit/chainlink-testing-framework/k8s/client"
ctfconfig "github.com/smartcontractkit/chainlink-testing-framework/config"
envclient "github.com/smartcontractkit/chainlink-testing-framework/k8s/client"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/environment"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/chainlink"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/ethereum"
"github.com/smartcontractkit/chainlink-testing-framework/k8s/pkg/helm/reorg"
"github.com/smartcontractkit/chainlink-testing-framework/logging"
"github.com/smartcontractkit/chainlink-testing-framework/networks"
seth_utils "github.com/smartcontractkit/chainlink-testing-framework/utils/seth"
sethutils "github.com/smartcontractkit/chainlink-testing-framework/utils/seth"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
eth_contracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
ethcontracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig"
"github.com/smartcontractkit/chainlink/integration-tests/testsetups"
"github.com/smartcontractkit/chainlink/integration-tests/types"
)

var (
performanceChainlinkResources = map[string]interface{}{
chainlinkResources = map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "1000m",
Expand All @@ -41,7 +41,7 @@ var (
},
},
}
performanceDbResources = map[string]interface{}{
dbResources = map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "1000m",
Expand All @@ -55,33 +55,6 @@ var (
"stateful": true,
"capacity": "10Gi",
}

soakChainlinkResources = map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "350m",
"memory": "1Gi",
},
"limits": map[string]interface{}{
"cpu": "350m",
"memory": "1Gi",
},
},
}
soakDbResources = map[string]interface{}{
"resources": map[string]interface{}{
"requests": map[string]interface{}{
"cpu": "250m",
"memory": "256Mi",
},
"limits": map[string]interface{}{
"cpu": "250m",
"memory": "256Mi",
},
},
"stateful": true,
"capacity": "10Gi",
}
)

type NetworkConfig struct {
Expand Down Expand Up @@ -115,9 +88,9 @@ func TestAutomationBenchmark(t *testing.T) {
benchmarkTestNetwork := getNetworkConfig(&config)

l.Info().Str("Namespace", testEnvironment.Cfg.Namespace).Msg("Connected to Keepers Benchmark Environment")
testNetwork := seth_utils.MustReplaceSimulatedNetworkUrlWithK8(l, benchmarkNetwork, *testEnvironment)
testNetwork := sethutils.MustReplaceSimulatedNetworkUrlWithK8(l, benchmarkNetwork, *testEnvironment)

chainClient, err := seth_utils.GetChainClientWithConfigFunction(&config, testNetwork, seth_utils.OneEphemeralKeysLiveTestnetAutoFixFn)
chainClient, err := sethutils.GetChainClientWithConfigFunction(&config, testNetwork, sethutils.OneEphemeralKeysLiveTestnetAutoFixFn)
require.NoError(t, err, "Error getting Seth client")

registryVersions := addRegistry(&config)
Expand Down Expand Up @@ -173,40 +146,42 @@ func TestAutomationBenchmark(t *testing.T) {
keeperBenchmarkTest.Run()
}

func addRegistry(config *tc.TestConfig) []eth_contracts.KeeperRegistryVersion {
func addRegistry(config *tc.TestConfig) []ethcontracts.KeeperRegistryVersion {
switch *config.Keeper.Common.RegistryToTest {
case "1_1":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_1_1}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_1_1}
case "1_2":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_1_2}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_1_2}
case "1_3":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_1_3}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_1_3}
case "2_0":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_0}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_0}
case "2_1":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_1}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_1}
case "2_2":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_2}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_2}
case "2_3":
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_3}
case "2_0-1_3":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_0, eth_contracts.RegistryVersion_1_3}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_0, ethcontracts.RegistryVersion_1_3}
case "2_1-2_0-1_3":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_1,
eth_contracts.RegistryVersion_2_0, eth_contracts.RegistryVersion_1_3}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_1,
ethcontracts.RegistryVersion_2_0, ethcontracts.RegistryVersion_1_3}
case "2_2-2_1":
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_2, eth_contracts.RegistryVersion_2_1}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_2, ethcontracts.RegistryVersion_2_1}
case "2_0-Multiple":
return repeatRegistries(eth_contracts.RegistryVersion_2_0, *config.Keeper.Common.NumberOfRegistries)
return repeatRegistries(ethcontracts.RegistryVersion_2_0, *config.Keeper.Common.NumberOfRegistries)
case "2_1-Multiple":
return repeatRegistries(eth_contracts.RegistryVersion_2_1, *config.Keeper.Common.NumberOfRegistries)
return repeatRegistries(ethcontracts.RegistryVersion_2_1, *config.Keeper.Common.NumberOfRegistries)
case "2_2-Multiple":
return repeatRegistries(eth_contracts.RegistryVersion_2_2, *config.Keeper.Common.NumberOfRegistries)
return repeatRegistries(ethcontracts.RegistryVersion_2_2, *config.Keeper.Common.NumberOfRegistries)
default:
return []eth_contracts.KeeperRegistryVersion{eth_contracts.RegistryVersion_2_0}
return []ethcontracts.KeeperRegistryVersion{ethcontracts.RegistryVersion_2_0}
}
}

func repeatRegistries(registryVersion eth_contracts.KeeperRegistryVersion, numberOfRegistries int) []eth_contracts.KeeperRegistryVersion {
repeatedRegistries := make([]eth_contracts.KeeperRegistryVersion, 0)
func repeatRegistries(registryVersion ethcontracts.KeeperRegistryVersion, numberOfRegistries int) []ethcontracts.KeeperRegistryVersion {
repeatedRegistries := make([]ethcontracts.KeeperRegistryVersion, 0)
for i := 0; i < numberOfRegistries; i++ {
repeatedRegistries = append(repeatedRegistries, registryVersion)
}
Expand Down Expand Up @@ -316,12 +291,8 @@ func SetupAutomationBenchmarkEnv(t *testing.T, keeperTestConfig types.KeeperBenc
PreventPodEviction: true,
})

dbResources := performanceDbResources
chainlinkResources := performanceChainlinkResources
if strings.Contains(strings.ToLower(strings.Join(keeperTestConfig.GetConfigurationNames(), ",")), "soak") {
chainlinkResources = soakChainlinkResources
dbResources = soakDbResources
}
dbResources := dbResources
chainlinkResources := chainlinkResources

// Test can run on simulated, simulated-non-dev, testnets
if testNetwork.Name == networks.SimulatedEVMNonDev.Name {
Expand Down Expand Up @@ -389,10 +360,10 @@ func SetupAutomationBenchmarkEnv(t *testing.T, keeperTestConfig types.KeeperBenc
// for simulated-nod-dev each CL node gets its own RPC node
if testNetwork.Name == networks.SimulatedEVMNonDev.Name {
podName := fmt.Sprintf("%s-ethereum-geth:%d", testNetwork.Name, i)
txNodeInternalWs, err := testEnvironment.Fwd.FindPort(podName, "geth", "ws-rpc").As(env_client.RemoteConnection, env_client.WS)
txNodeInternalWs, err := testEnvironment.Fwd.FindPort(podName, "geth", "ws-rpc").As(envclient.RemoteConnection, envclient.WS)
require.NoError(t, err, "Error finding WS ports")
internalWsURLs = append(internalWsURLs, txNodeInternalWs)
txNodeInternalHttp, err := testEnvironment.Fwd.FindPort(podName, "geth", "http-rpc").As(env_client.RemoteConnection, env_client.HTTP)
txNodeInternalHttp, err := testEnvironment.Fwd.FindPort(podName, "geth", "http-rpc").As(envclient.RemoteConnection, envclient.HTTP)
require.NoError(t, err, "Error finding HTTP ports")
internalHttpURLs = append(internalHttpURLs, txNodeInternalHttp)
// for testnets with more than 1 RPC nodes
Expand All @@ -412,8 +383,8 @@ func SetupAutomationBenchmarkEnv(t *testing.T, keeperTestConfig types.KeeperBenc
testNetwork.URLs = []string{internalWsURLs[i]}

var overrideFn = func(_ interface{}, target interface{}) {
ctf_config.MustConfigOverrideChainlinkVersion(keeperTestConfig.GetChainlinkImageConfig(), target)
ctf_config.MightConfigOverridePyroscopeKey(keeperTestConfig.GetPyroscopeConfig(), target)
ctfconfig.MustConfigOverrideChainlinkVersion(keeperTestConfig.GetChainlinkImageConfig(), target)
ctfconfig.MightConfigOverridePyroscopeKey(keeperTestConfig.GetPyroscopeConfig(), target)
}

tomlConfig, err := actions.BuildTOMLNodeConfigForK8s(keeperTestConfig, testNetwork)
Expand Down
67 changes: 66 additions & 1 deletion integration-tests/testconfig/keeper/keeper.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,21 @@ contract_call_interval = "4s"

[Seth]
# keeper benchmark running on simulated network requires 100k per node
root_key_funds_buffer = 700_000
root_key_funds_buffer = 1_000_000

[Benchmark.Keeper.Common]
registry_to_test = "2_1"
number_of_registries = 1
number_of_nodes = 6
number_of_upkeeps = 1000
upkeep_gas_limit = 1500000
check_gas_to_burn = 10000
perform_gas_to_burn = 1000
max_perform_gas = 5000000
block_range = 3600
block_interval = 60
forces_single_tx_key = false
delete_jobs_on_end = true

[Benchmark.NodeConfig]
BaseConfigTOML = """
Expand Down Expand Up @@ -95,3 +109,54 @@ HistoryDepth = 100
Mode = 'FixedPrice'
LimitDefault = 5_000_000
"""

[Soak.Keeper.Common]
registry_to_test = "2_1"
number_of_registries = 1
number_of_nodes = 6
number_of_upkeeps = 50
upkeep_gas_limit = 1500000
check_gas_to_burn = 10000
perform_gas_to_burn = 1000
max_perform_gas = 5000000
block_range = 28800
block_interval = 300
forces_single_tx_key = false
delete_jobs_on_end = true

[Soak.NodeConfig]
BaseConfigTOML = """
[Feature]
LogPoller = true
[OCR2]
Enabled = true
[P2P]
[P2P.V2]
Enabled = true
AnnounceAddresses = ["0.0.0.0:6690"]
ListenAddresses = ["0.0.0.0:6690"]
[Keeper]
TurnLookBack = 0
[WebServer]
HTTPWriteTimeout = '1h'
"""

CommonChainConfigTOML = """
"""

[Soak.NodeConfig.ChainConfigTOMLByChainID]
# applicable for simulated chain
1337 = """
FinalityDepth = 50
LogPollInterval = '1s'
MinIncomingConfirmations = 1
[HeadTracker]
HistoryDepth = 100
[GasEstimator]
Mode = 'FixedPrice'
LimitDefault = 5_000_000
"""
28 changes: 16 additions & 12 deletions integration-tests/testsetups/keeper_benchmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ type KeeperBenchmarkTest struct {
chainClient *seth.Client
testConfig tt.KeeperBenchmarkTestConfig

linkToken contracts.LinkToken
ethFeed contracts.MockLINKETHFeed
gasFeed contracts.MockGasFeed
//nativeFeed contracts.MockETHUSDFeed
//wrappedNative contracts.WETHToken
linkToken contracts.LinkToken
linkethFeed contracts.MockLINKETHFeed
gasFeed contracts.MockGasFeed
ethusdFeed contracts.MockETHUSDFeed
wrappedNative contracts.WETHToken
}

// UpkeepConfig dictates details of how the test's upkeep contracts should be called and configured
Expand Down Expand Up @@ -168,7 +168,7 @@ func (k *KeeperBenchmarkTest) Setup(env *environment.Environment, config tt.Keep
_, err = contracts.LoadMockLINKETHFeed(k.chainClient, common.HexToAddress(c.EthFeedAddress))
require.NoError(k.t, err, "Loading ETH-Link feed Contract shouldn't fail")
} else {
k.ethFeed, err = contracts.DeployMockLINKETHFeed(k.chainClient, big.NewInt(2e18))
k.linkethFeed, err = contracts.DeployMockLINKETHFeed(k.chainClient, big.NewInt(2e18))
require.NoError(k.t, err, "Deploying mock ETH-Link feed shouldn't fail")
}

Expand All @@ -180,6 +180,11 @@ func (k *KeeperBenchmarkTest) Setup(env *environment.Environment, config tt.Keep
require.NoError(k.t, err, "Deploying mock gas feed shouldn't fail")
}

k.ethusdFeed, err = contracts.DeployMockETHUSDFeed(k.chainClient, big.NewInt(200000000000))
require.NoError(k.t, err, "Deploying mock ETH-USD feed shouldn't fail")
k.wrappedNative, err = contracts.DeployWETHTokenContract(k.log, k.chainClient)
require.NoError(k.t, err, "Deploying WETH Token Contract shouldn't fail")

for index := range inputs.RegistryVersions {
k.log.Info().Int("Index", index).Msg("Starting Test Setup")
k.DeployBenchmarkKeeperContracts(index)
Expand Down Expand Up @@ -242,15 +247,14 @@ func (k *KeeperBenchmarkTest) Run() {
txKeyId = 0
}
kr := k.keeperRegistries[rIndex]
// TODO: need to add the LINK, WETH and WETH/USD feed to support v23
ocrConfig, err := actions.BuildAutoOCR2ConfigVarsWithKeyIndex(
k.t, nodesWithoutBootstrap, *inputs.KeeperRegistrySettings, kr.Address(), k.Inputs.DeltaStage, txKeyId, common.Address{}, kr.ChainModuleAddress(), kr.ReorgProtectionEnabled(), nil, nil, nil,
k.t, nodesWithoutBootstrap, *inputs.KeeperRegistrySettings, kr.Address(), k.Inputs.DeltaStage, txKeyId, common.Address{}, kr.ChainModuleAddress(), kr.ReorgProtectionEnabled(), k.linkToken, k.wrappedNative, k.ethusdFeed,
)
require.NoError(k.t, err, "Building OCR config shouldn't fail")

rv := inputs.RegistryVersions[rIndex]
// Send keeper jobs to registry and chainlink nodes
if rv == ethereum.RegistryVersion_2_0 || rv == ethereum.RegistryVersion_2_1 || rv == ethereum.RegistryVersion_2_2 {
if rv >= ethereum.RegistryVersion_2_0 {
actions.CreateOCRKeeperJobs(k.t, k.chainlinkNodes, kr.Address(), k.chainClient.ChainID, txKeyId, rv)
if rv == ethereum.RegistryVersion_2_0 {
err = kr.SetConfig(*inputs.KeeperRegistrySettings, ocrConfig)
Expand Down Expand Up @@ -710,7 +714,7 @@ func (k *KeeperBenchmarkTest) DeployBenchmarkKeeperContracts(index int) {
registry, err = contracts.DeployKeeperRegistry(k.chainClient, &contracts.KeeperRegistryOpts{
RegistryVersion: registryVersion,
LinkAddr: k.linkToken.Address(),
ETHFeedAddr: k.ethFeed.Address(),
ETHFeedAddr: k.linkethFeed.Address(),
GasFeedAddr: k.gasFeed.Address(),
TranscoderAddr: actions.ZeroAddress.Hex(),
RegistrarAddr: actions.ZeroAddress.Hex(),
Expand All @@ -733,13 +737,13 @@ func (k *KeeperBenchmarkTest) DeployBenchmarkKeeperContracts(index int) {
require.NoError(k.t, err, "Funding keeper registrar contract shouldn't fail")
} else { // OCR automation - v2.X
registry, registrar = actions.DeployAutoOCRRegistryAndRegistrar(
k.t, k.chainClient, registryVersion, *k.Inputs.KeeperRegistrySettings, k.linkToken, nil, nil,
k.t, k.chainClient, registryVersion, *k.Inputs.KeeperRegistrySettings, k.linkToken, k.wrappedNative, k.ethusdFeed,
)

// Fund the registry with LINK
err := k.linkToken.Transfer(registry.Address(), big.NewInt(0).Mul(big.NewInt(1e18), big.NewInt(int64(k.Inputs.Upkeeps.NumberOfUpkeeps))))
require.NoError(k.t, err, "Funding keeper registry contract shouldn't fail")
ocrConfig, err := actions.BuildAutoOCR2ConfigVars(k.t, k.chainlinkNodes[1:], *k.Inputs.KeeperRegistrySettings, registrar.Address(), k.Inputs.DeltaStage, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled(), nil, nil, nil)
ocrConfig, err := actions.BuildAutoOCR2ConfigVars(k.t, k.chainlinkNodes[1:], *k.Inputs.KeeperRegistrySettings, registrar.Address(), k.Inputs.DeltaStage, registry.ChainModuleAddress(), registry.ReorgProtectionEnabled(), k.linkToken, k.wrappedNative, k.ethusdFeed)
require.NoError(k.t, err, "Building OCR config shouldn't fail")
k.log.Debug().Interface("KeeperRegistrySettings", *k.Inputs.KeeperRegistrySettings).Interface("OCRConfig", ocrConfig).Msg("Config")
require.NoError(k.t, err, "Error building OCR config vars")
Expand Down

0 comments on commit 08687df

Please sign in to comment.