Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DEVSVCS-545] cleanup #14478

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 0 additions & 277 deletions integration-tests/actions/automation_ocr_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,297 +2,20 @@ package actions

//revive:disable:dot-imports
import (
"encoding/json"
"fmt"
"math"
"math/big"
"testing"
"time"

"github.com/pkg/errors"

"github.com/smartcontractkit/chainlink-testing-framework/seth"

"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/generated/i_automation_registry_master_wrapper_2_3"

"github.com/ethereum/go-ethereum/common"
"github.com/lib/pq"
"github.com/stretchr/testify/require"
"gopkg.in/guregu/null.v4"

ocr2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
ocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"

ocr2keepers20config "github.com/smartcontractkit/chainlink-automation/pkg/v2/config"
ocr2keepers30config "github.com/smartcontractkit/chainlink-automation/pkg/v3/config"
"github.com/smartcontractkit/chainlink-testing-framework/lib/logging"

"github.com/smartcontractkit/chainlink/integration-tests/client"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
"github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/chaintype"
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func BuildAutoOCR2ConfigVars(
t *testing.T,
chainlinkNodes []*client.ChainlinkK8sClient,
registryConfig contracts.KeeperRegistrySettings,
registrar string,
deltaStage time.Duration,
chainModuleAddress common.Address,
reorgProtectionEnabled bool,
linkToken contracts.LinkToken,
wethToken contracts.WETHToken,
ethUSDFeed contracts.MockETHUSDFeed,

) (contracts.OCRv2Config, error) {
return BuildAutoOCR2ConfigVarsWithKeyIndex(t, chainlinkNodes, registryConfig, registrar, deltaStage, 0, common.Address{}, chainModuleAddress, reorgProtectionEnabled, linkToken, wethToken, ethUSDFeed)
}

func BuildAutoOCR2ConfigVarsWithKeyIndex(
t *testing.T,
chainlinkNodes []*client.ChainlinkK8sClient,
registryConfig contracts.KeeperRegistrySettings,
registrar string,
deltaStage time.Duration,
keyIndex int,
registryOwnerAddress common.Address,
chainModuleAddress common.Address,
reorgProtectionEnabled bool,
linkToken contracts.LinkToken,
wethToken contracts.WETHToken,
ethUSDFeed contracts.MockETHUSDFeed,
) (contracts.OCRv2Config, error) {
l := logging.GetTestLogger(t)
S, oracleIdentities, err := GetOracleIdentitiesWithKeyIndex(chainlinkNodes, keyIndex)
if err != nil {
return contracts.OCRv2Config{}, err
}

var offC []byte
var signerOnchainPublicKeys []types.OnchainPublicKey
var transmitterAccounts []types.Account
var f uint8
var offchainConfigVersion uint64
var offchainConfig []byte

if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_1 || registryConfig.RegistryVersion == ethereum.RegistryVersion_2_2 || registryConfig.RegistryVersion == ethereum.RegistryVersion_2_3 {
offC, err = json.Marshal(ocr2keepers30config.OffchainConfig{
TargetProbability: "0.999",
TargetInRounds: 1,
PerformLockoutWindow: 3600000, // Intentionally set to be higher than in prod for testing purpose
GasLimitPerReport: 5_300_000,
GasOverheadPerUpkeep: 300_000,
MinConfirmations: 0,
MaxUpkeepBatchSize: 10,
})
if err != nil {
return contracts.OCRv2Config{}, err
}

signerOnchainPublicKeys, transmitterAccounts, f, _, offchainConfigVersion, offchainConfig, err = ocr3.ContractSetConfigArgsForTests(
10*time.Second, // deltaProgress time.Duration,
15*time.Second, // deltaResend time.Duration,
500*time.Millisecond, // deltaInitial time.Duration,
1000*time.Millisecond, // deltaRound time.Duration,
200*time.Millisecond, // deltaGrace time.Duration,
300*time.Millisecond, // deltaCertifiedCommitRequest time.Duration
deltaStage, // deltaStage time.Duration,
24, // rMax uint64,
S, // s []int,
oracleIdentities, // oracles []OracleIdentityExtra,
offC, // reportingPluginConfig []byte,
20*time.Millisecond, // maxDurationQuery time.Duration,
20*time.Millisecond, // maxDurationObservation time.Duration, // good to here
1200*time.Millisecond, // maxDurationShouldAcceptAttestedReport time.Duration,
20*time.Millisecond, // maxDurationShouldTransmitAcceptedReport time.Duration,
1, // f int,
nil, // onchainConfig []byte,
)
if err != nil {
return contracts.OCRv2Config{}, err
}
} else {
offC, err = json.Marshal(ocr2keepers20config.OffchainConfig{
TargetProbability: "0.999",
TargetInRounds: 1,
PerformLockoutWindow: 3600000, // Intentionally set to be higher than in prod for testing purpose
GasLimitPerReport: 5_300_000,
GasOverheadPerUpkeep: 300_000,
SamplingJobDuration: 3000,
MinConfirmations: 0,
MaxUpkeepBatchSize: 1,
})
if err != nil {
return contracts.OCRv2Config{}, err
}

signerOnchainPublicKeys, transmitterAccounts, f, _, offchainConfigVersion, offchainConfig, err = ocr2.ContractSetConfigArgsForTests(
10*time.Second, // deltaProgress time.Duration,
15*time.Second, // deltaResend time.Duration,
3000*time.Millisecond, // deltaRound time.Duration,
200*time.Millisecond, // deltaGrace time.Duration,
deltaStage, // deltaStage time.Duration,
24, // rMax uint8,
S, // s []int,
oracleIdentities, // oracles []OracleIdentityExtra,
offC, // reportingPluginConfig []byte,
20*time.Millisecond, // maxDurationQuery time.Duration,
20*time.Millisecond, // maxDurationObservation time.Duration,
1200*time.Millisecond, // maxDurationReport time.Duration,
20*time.Millisecond, // maxDurationShouldAcceptFinalizedReport time.Duration,
20*time.Millisecond, // maxDurationShouldTransmitAcceptedReport time.Duration,
1, // f int,
nil, // onchainConfig []byte,
)
if err != nil {
return contracts.OCRv2Config{}, err
}
}

var signers []common.Address
for _, signer := range signerOnchainPublicKeys {
require.Equal(t, 20, len(signer), "OnChainPublicKey '%v' has wrong length for address", signer)
signers = append(signers, common.BytesToAddress(signer))
}

var transmitters []common.Address
for _, transmitter := range transmitterAccounts {
require.True(t, common.IsHexAddress(string(transmitter)), "TransmitAccount '%s' is not a valid Ethereum address", string(transmitter))
transmitters = append(transmitters, common.HexToAddress(string(transmitter)))
}

ocrConfig := contracts.OCRv2Config{
Signers: signers,
Transmitters: transmitters,
F: f,
OffchainConfigVersion: offchainConfigVersion,
OffchainConfig: offchainConfig,
}

if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_0 {
ocrConfig.OnchainConfig = registryConfig.Encode20OnchainConfig(registrar)
} else if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_1 {
ocrConfig.TypedOnchainConfig21 = registryConfig.Create21OnchainConfig(registrar, registryOwnerAddress)
} else if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_2 {
ocrConfig.TypedOnchainConfig22 = registryConfig.Create22OnchainConfig(registrar, registryOwnerAddress, chainModuleAddress, reorgProtectionEnabled)
} else if registryConfig.RegistryVersion == ethereum.RegistryVersion_2_3 {
ocrConfig.TypedOnchainConfig23 = registryConfig.Create23OnchainConfig(registrar, registryOwnerAddress, chainModuleAddress, reorgProtectionEnabled)
ocrConfig.BillingTokens = []common.Address{
common.HexToAddress(linkToken.Address()),
common.HexToAddress(wethToken.Address()),
}

ocrConfig.BillingConfigs = []i_automation_registry_master_wrapper_2_3.AutomationRegistryBase23BillingConfig{
{
GasFeePPB: 100,
FlatFeeMilliCents: big.NewInt(500),
PriceFeed: common.HexToAddress(ethUSDFeed.Address()), // ETH/USD feed and LINK/USD feed are the same
Decimals: 18,
FallbackPrice: big.NewInt(1000),
MinSpend: big.NewInt(200),
},
{
GasFeePPB: 100,
FlatFeeMilliCents: big.NewInt(500),
PriceFeed: common.HexToAddress(ethUSDFeed.Address()), // ETH/USD feed and LINK/USD feed are the same
Decimals: 18,
FallbackPrice: big.NewInt(1000),
MinSpend: big.NewInt(200),
},
}
}

l.Info().Msg("Done building OCR config")
return ocrConfig, nil
}

// CreateOCRKeeperJobs bootstraps the first node and to the other nodes sends ocr jobs
func CreateOCRKeeperJobs(
t *testing.T,
chainlinkNodes []*client.ChainlinkK8sClient,
registryAddr string,
chainID int64,
keyIndex int,
registryVersion ethereum.KeeperRegistryVersion,
) {
l := logging.GetTestLogger(t)
bootstrapNode := chainlinkNodes[0]
bootstrapP2PIds, err := bootstrapNode.MustReadP2PKeys()
require.NoError(t, err, "Shouldn't fail reading P2P keys from bootstrap node")
bootstrapP2PId := bootstrapP2PIds.Data[0].Attributes.PeerID

var contractVersion string
if registryVersion == ethereum.RegistryVersion_2_2 || registryVersion == ethereum.RegistryVersion_2_3 {
contractVersion = "v2.1+"
} else if registryVersion == ethereum.RegistryVersion_2_1 {
contractVersion = "v2.1"
} else if registryVersion == ethereum.RegistryVersion_2_0 {
contractVersion = "v2.0"
} else {
require.FailNow(t, fmt.Sprintf("v2.0, v2.1, v2.2 and v2.3 are the only supported versions, but got something else: %v (iota)", registryVersion))
}

bootstrapSpec := &client.OCR2TaskJobSpec{
Name: "ocr2 bootstrap node " + registryAddr,
JobType: "bootstrap",
OCR2OracleSpec: job.OCR2OracleSpec{
ContractID: registryAddr,
Relay: "evm",
RelayConfig: map[string]interface{}{
"chainID": int(chainID),
},
ContractConfigTrackerPollInterval: *models.NewInterval(time.Second * 15),
},
}
_, err = bootstrapNode.MustCreateJob(bootstrapSpec)
require.NoError(t, err, "Shouldn't fail creating bootstrap job on bootstrap node")
// TODO: Use service name returned by chainlink-env once that is available
P2Pv2Bootstrapper := fmt.Sprintf("%s@%s-node-1:%d", bootstrapP2PId, bootstrapNode.Name(), 6690)

for nodeIndex := 1; nodeIndex < len(chainlinkNodes); nodeIndex++ {
nodeTransmitterAddress, err := chainlinkNodes[nodeIndex].EthAddresses()
require.NoError(t, err, "Shouldn't fail getting primary ETH address from OCR node %d", nodeIndex+1)
nodeOCRKeys, err := chainlinkNodes[nodeIndex].MustReadOCR2Keys()
require.NoError(t, err, "Shouldn't fail getting OCR keys from OCR node %d", nodeIndex+1)
var nodeOCRKeyId []string
for _, key := range nodeOCRKeys.Data {
if key.Attributes.ChainType == string(chaintype.EVM) {
nodeOCRKeyId = append(nodeOCRKeyId, key.ID)
break
}
}

autoOCR2JobSpec := client.OCR2TaskJobSpec{
Name: "ocr2 " + registryAddr,
JobType: "offchainreporting2",
OCR2OracleSpec: job.OCR2OracleSpec{
PluginType: "ocr2automation",
Relay: "evm",
RelayConfig: map[string]interface{}{
"chainID": int(chainID),
},
PluginConfig: map[string]interface{}{
"mercuryCredentialName": "\"cred1\"",
"contractVersion": "\"" + contractVersion + "\"",
},
ContractConfigTrackerPollInterval: *models.NewInterval(time.Second * 15),
ContractID: registryAddr, // registryAddr
OCRKeyBundleID: null.StringFrom(nodeOCRKeyId[0]), // get node ocr2config.ID
TransmitterID: null.StringFrom(nodeTransmitterAddress[keyIndex]), // node addr
P2PV2Bootstrappers: pq.StringArray{P2Pv2Bootstrapper}, // bootstrap node key and address <p2p-key>@bootstrap:8000
},
}

_, err = chainlinkNodes[nodeIndex].MustCreateJob(&autoOCR2JobSpec)
require.NoError(t, err, "Shouldn't fail creating OCR Task job on OCR node %d err: %+v", nodeIndex+1, err)
}
l.Info().Msg("Done creating OCR automation jobs")
}

// DeployAutoOCRRegistryAndRegistrar registry and registrar
func DeployAutoOCRRegistryAndRegistrar(
t *testing.T,
Expand Down
39 changes: 38 additions & 1 deletion integration-tests/actions/automation_ocr_helpers_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/store/models"
)

func AutomationDefaultRegistryConfig(c tc.AutomationTestConfig) contracts.KeeperRegistrySettings {
func ReadRegistryConfig(c tc.AutomationTestConfig) contracts.KeeperRegistrySettings {
registrySettings := c.GetAutomationConfig().AutomationConfig.RegistrySettings
return contracts.KeeperRegistrySettings{
PaymentPremiumPPB: *registrySettings.PaymentPremiumPPB,
Expand All @@ -40,12 +40,49 @@ func AutomationDefaultRegistryConfig(c tc.AutomationTestConfig) contracts.Keeper
MaxPerformGas: *registrySettings.MaxPerformGas,
FallbackGasPrice: registrySettings.FallbackGasPrice,
FallbackLinkPrice: registrySettings.FallbackLinkPrice,
FallbackNativePrice: registrySettings.FallbackNativePrice,
MaxCheckDataSize: *registrySettings.MaxCheckDataSize,
MaxPerformDataSize: *registrySettings.MaxPerformDataSize,
MaxRevertDataSize: *registrySettings.MaxRevertDataSize,
}
}

func ReadPluginConfig(c tc.AutomationTestConfig) ocr2keepers30config.OffchainConfig {
plCfg := c.GetAutomationConfig().AutomationConfig.PluginConfig
return ocr2keepers30config.OffchainConfig{
TargetProbability: *plCfg.TargetProbability,
TargetInRounds: *plCfg.TargetInRounds,
PerformLockoutWindow: *plCfg.PerformLockoutWindow,
GasLimitPerReport: *plCfg.GasLimitPerReport,
GasOverheadPerUpkeep: *plCfg.GasOverheadPerUpkeep,
MinConfirmations: *plCfg.MinConfirmations,
MaxUpkeepBatchSize: *plCfg.MaxUpkeepBatchSize,
LogProviderConfig: ocr2keepers30config.LogProviderConfig{
BlockRate: *plCfg.LogProviderConfig.BlockRate,
LogLimit: *plCfg.LogProviderConfig.LogLimit,
},
}
}

func ReadPublicConfig(c tc.AutomationTestConfig) ocr3.PublicConfig {
pubCfg := c.GetAutomationConfig().AutomationConfig.PublicConfig
return ocr3.PublicConfig{
DeltaProgress: *pubCfg.DeltaProgress,
DeltaResend: *pubCfg.DeltaResend,
DeltaInitial: *pubCfg.DeltaInitial,
DeltaRound: *pubCfg.DeltaRound,
DeltaGrace: *pubCfg.DeltaGrace,
DeltaCertifiedCommitRequest: *pubCfg.DeltaCertifiedCommitRequest,
DeltaStage: *pubCfg.DeltaStage,
RMax: *pubCfg.RMax,
MaxDurationQuery: *pubCfg.MaxDurationQuery,
MaxDurationObservation: *pubCfg.MaxDurationObservation,
MaxDurationShouldAcceptAttestedReport: *pubCfg.MaxDurationShouldAcceptAttestedReport,
MaxDurationShouldTransmitAcceptedReport: *pubCfg.MaxDurationShouldTransmitAcceptedReport,
F: *pubCfg.F,
}
}

func BuildAutoOCR2ConfigVarsLocal(
l zerolog.Logger,
chainlinkNodes []*client.ChainlinkClient,
Expand Down
22 changes: 4 additions & 18 deletions integration-tests/benchmark/automation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
sethutils "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/seth"

"github.com/smartcontractkit/chainlink/integration-tests/actions"
"github.com/smartcontractkit/chainlink/integration-tests/contracts"
ethcontracts "github.com/smartcontractkit/chainlink/integration-tests/contracts/ethereum"
tc "github.com/smartcontractkit/chainlink/integration-tests/testconfig"
"github.com/smartcontractkit/chainlink/integration-tests/testsetups"
Expand Down Expand Up @@ -94,25 +93,12 @@ func TestAutomationBenchmark(t *testing.T) {
require.NoError(t, err, "Error getting Seth client")

registryVersions := addRegistry(&config)
registrySettings := actions.ReadRegistryConfig(config)
keeperBenchmarkTest := testsetups.NewKeeperBenchmarkTest(t,
testsetups.KeeperBenchmarkTestInputs{
BlockchainClient: chainClient,
RegistryVersions: registryVersions,
KeeperRegistrySettings: &contracts.KeeperRegistrySettings{
PaymentPremiumPPB: uint32(0),
FlatFeeMicroLINK: uint32(40000),
BlockCountPerTurn: big.NewInt(100),
CheckGasLimit: uint32(45_000_000), //45M
StalenessSeconds: big.NewInt(90_000),
GasCeilingMultiplier: uint16(2),
MaxPerformGas: uint32(*config.Automation.Benchmark.MaxPerformGas),
MinUpkeepSpend: big.NewInt(0),
FallbackGasPrice: big.NewInt(2e11),
FallbackLinkPrice: big.NewInt(2e18),
MaxCheckDataSize: uint32(5_000),
MaxPerformDataSize: uint32(5_000),
MaxRevertDataSize: uint32(5_000),
},
BlockchainClient: chainClient,
RegistryVersions: registryVersions,
KeeperRegistrySettings: &registrySettings,
Upkeeps: &testsetups.UpkeepConfig{
NumberOfUpkeeps: *config.Automation.Benchmark.NumberOfUpkeeps,
CheckGasToBurn: *config.Automation.Benchmark.CheckGasToBurn,
Expand Down
Loading
Loading