Skip to content

Commit

Permalink
wip: wire configs in test
Browse files Browse the repository at this point in the history
  • Loading branch information
makramkd committed Aug 6, 2024
1 parent 2d55ddf commit 6f4049f
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 81 deletions.
119 changes: 80 additions & 39 deletions core/capabilities/ccip/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"testing"
"time"

"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/ccip_integration_tests/integrationhelpers"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"

Expand Down Expand Up @@ -53,9 +55,27 @@ const (
CapabilityLabelledName = "ccip"
CapabilityVersion = "v1.0.0"
NodeOperatorID = 1
// TODO: this is 8 hours now to match what is hardcoded in the exec plugin.
// Eventually this should drive what is set in the exec plugin.
FirstBlockAge = 8 * time.Hour

// These constants drive what is set in the plugin offchain configs.
FirstBlockAge = 8 * time.Hour
RemoteGasPriceBatchWriteFrequency = 30 * time.Minute
BatchGasLimit = 6_500_000
RelativeBoostPerWaitHour = 1.5
InflightCacheExpiry = 10 * time.Minute
RootSnoozeTime = 30 * time.Minute
BatchingStrategyID = 0
DeltaProgress = 30 * time.Second
DeltaResend = 10 * time.Second
DeltaInitial = 20 * time.Second
DeltaRound = 2 * time.Second
DeltaGrace = 2 * time.Second
DeltaCertifiedCommitRequest = 10 * time.Second
DeltaStage = 10 * time.Second
Rmax = 3
MaxDurationQuery = 50 * time.Millisecond
MaxDurationObservation = 5 * time.Second
MaxDurationShouldAcceptAttestedReport = 10 * time.Second
MaxDurationShouldTransmitAcceptedReport = 10 * time.Second
)

func e18Mult(amount uint64) *big.Int {
Expand Down Expand Up @@ -437,45 +457,66 @@ func (h *homeChain) AddDON(
for range oracles {
schedule = append(schedule, 1)
}
signers, transmitters, f, _, offchainConfigVersion, offchainConfig, err := ocr3confighelper.ContractSetConfigArgsForTests(
30*time.Second, // deltaProgress
10*time.Second, // deltaResend
20*time.Second, // deltaInitial
2*time.Second, // deltaRound
2*time.Second, // deltaGrace
10*time.Second, // deltaCertifiedCommitRequest TODO: whats a good value for this?
10*time.Second, // deltaStage
3, // rmax
schedule,
oracles,
[]byte{}, // empty offchain config
50*time.Millisecond, // maxDurationQuery
5*time.Second, // maxDurationObservation
10*time.Second, // maxDurationShouldAcceptAttestedReport
10*time.Second, // maxDurationShouldTransmitAcceptedReport
int(f),
[]byte{}) // empty OnChainConfig
require.NoError(t, err, "failed to create contract config")

tabi, err := ocr3_config_encoder.IOCR3ConfigEncoderMetaData.GetAbi()
require.NoError(t, err)

signersBytes := make([][]byte, len(signers))
for i, signer := range signers {
signersBytes[i] = signer
}

transmittersBytes := make([][]byte, len(transmitters))
for i, transmitter := range transmitters {
// anotherErr because linting doesn't want to shadow err
parsed, anotherErr := common.ParseHexOrString(string(transmitter))
require.NoError(t, anotherErr)
transmittersBytes[i] = parsed
}

// Add DON on capability registry contract
var ocr3Configs []ocr3_config_encoder.CCIPConfigTypesOCR3Config
for _, pluginType := range []cctypes.PluginType{cctypes.PluginTypeCCIPCommit, cctypes.PluginTypeCCIPExec} {
var encodedOffchainConfig []byte
var err2 error
if pluginType == cctypes.PluginTypeCCIPCommit {
encodedOffchainConfig, err2 = pluginconfig.EncodeCommitOffchainConfig(pluginconfig.CommitOffchainConfig{
RemoteGasPriceBatchWriteFrequency: *commonconfig.MustNewDuration(RemoteGasPriceBatchWriteFrequency),
// TODO: implement token price writes
// TokenPriceBatchWriteFrequency: *commonconfig.MustNewDuration(tokenPriceBatchWriteFrequency),
})
require.NoError(t, err2)
} else {
encodedOffchainConfig, err2 = pluginconfig.EncodeExecuteOffchainConfig(pluginconfig.ExecuteOffchainConfig{
BatchGasLimit: BatchGasLimit,
RelativeBoostPerWaitHour: RelativeBoostPerWaitHour,
MessageVisibilityInterval: *commonconfig.MustNewDuration(FirstBlockAge),
InflightCacheExpiry: *commonconfig.MustNewDuration(InflightCacheExpiry),
RootSnoozeTime: *commonconfig.MustNewDuration(RootSnoozeTime),
BatchingStrategyID: BatchingStrategyID,
})
}
signers, transmitters, f, _, offchainConfigVersion, offchainConfig, err := ocr3confighelper.ContractSetConfigArgsForTests(
DeltaProgress,
DeltaResend,
DeltaInitial,
DeltaRound,
DeltaGrace,
DeltaCertifiedCommitRequest,
DeltaStage,
Rmax,
schedule,
oracles,
encodedOffchainConfig,
MaxDurationQuery,
MaxDurationObservation,
MaxDurationShouldAcceptAttestedReport,
MaxDurationShouldTransmitAcceptedReport,
int(f),
[]byte{}, // empty OnChainConfig
)
require.NoError(t, err, "failed to create contract config")

signersBytes := make([][]byte, len(signers))
for i, signer := range signers {
signersBytes[i] = signer
}

transmittersBytes := make([][]byte, len(transmitters))
for i, transmitter := range transmitters {
// anotherErr because linting doesn't want to shadow err
parsed, anotherErr := common.ParseHexOrString(string(transmitter))
require.NoError(t, anotherErr)
transmittersBytes[i] = parsed
}

ocr3Configs = append(ocr3Configs, ocr3_config_encoder.CCIPConfigTypesOCR3Config{
PluginType: uint8(pluginType),
ChainSelector: chainSelector,
Expand Down Expand Up @@ -522,13 +563,13 @@ func (h *homeChain) AddDON(
require.NotZero(t, donID, "failed to get donID from config set event")

var signerAddresses []common.Address
for _, signer := range signers {
signerAddresses = append(signerAddresses, common.BytesToAddress(signer))
for _, oracle := range oracles {
signerAddresses = append(signerAddresses, common.BytesToAddress(oracle.OnchainPublicKey))
}

var transmitterAddresses []common.Address
for _, transmitter := range transmitters {
transmitterAddresses = append(transmitterAddresses, common.HexToAddress(string(transmitter)))
for _, oracle := range oracles {
transmitterAddresses = append(transmitterAddresses, common.HexToAddress(string(oracle.TransmitAccount)))
}

// get the config digest from the ccip config contract and set config on the offramp.
Expand Down
22 changes: 15 additions & 7 deletions core/capabilities/ccip/configs/evm/chain_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ var (
offrampABI = evmtypes.MustGetABI(evm_2_evm_multi_offramp.EVM2EVMMultiOffRampABI)
)

func MustChainWriterConfig(fromAddress common.Address, maxGasPrice *assets.Wei) []byte {
rawConfig := ChainWriterConfigRaw(fromAddress, maxGasPrice)
func MustChainWriterConfig(
fromAddress common.Address,
maxGasPrice *assets.Wei,
commitGasLimit,
execBatchGasLimit uint64,
) []byte {
rawConfig := ChainWriterConfigRaw(fromAddress, maxGasPrice, commitGasLimit, execBatchGasLimit)
encoded, err := json.Marshal(rawConfig)
if err != nil {
panic(fmt.Errorf("failed to marshal ChainWriterConfig: %w", err))
Expand All @@ -31,7 +36,12 @@ func MustChainWriterConfig(fromAddress common.Address, maxGasPrice *assets.Wei)
}

// ChainWriterConfigRaw returns a ChainWriterConfig that can be used to transmit commit and execute reports.
func ChainWriterConfigRaw(fromAddress common.Address, maxGasPrice *assets.Wei) evmrelaytypes.ChainWriterConfig {
func ChainWriterConfigRaw(
fromAddress common.Address,
maxGasPrice *assets.Wei,
commitGasLimit,
execBatchGasLimit uint64,
) evmrelaytypes.ChainWriterConfig {
return evmrelaytypes.ChainWriterConfig{
Contracts: map[string]*evmrelaytypes.ContractConfig{
consts.ContractNameOffRamp: {
Expand All @@ -40,14 +50,12 @@ func ChainWriterConfigRaw(fromAddress common.Address, maxGasPrice *assets.Wei) e
consts.MethodCommit: {
ChainSpecificName: mustGetMethodName("commit", offrampABI),
FromAddress: fromAddress,
// TODO: inject this into the method, should be fetched from the OCR config.
GasLimit: 500_000,
GasLimit: commitGasLimit,
},
consts.MethodExecute: {
ChainSpecificName: mustGetMethodName("execute", offrampABI),
FromAddress: fromAddress,
// TODO: inject this into the method, should be fetched from the OCR config.
GasLimit: 6_500_000,
GasLimit: execBatchGasLimit,
},
},
},
Expand Down
29 changes: 20 additions & 9 deletions core/capabilities/ccip/ocrimpls/config_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"

gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)

Expand All @@ -24,6 +25,20 @@ func (c *configTracker) LatestBlockHeight(ctx context.Context) (blockHeight uint

// LatestConfig implements types.ContractConfigTracker.
func (c *configTracker) LatestConfig(ctx context.Context, changedInBlock uint64) (types.ContractConfig, error) {
return c.contractConfig(), nil
}

// LatestConfigDetails implements types.ContractConfigTracker.
func (c *configTracker) LatestConfigDetails(ctx context.Context) (changedInBlock uint64, configDigest types.ConfigDigest, err error) {
return 0, c.cfg.ConfigDigest, nil
}

// Notify implements types.ContractConfigTracker.
func (c *configTracker) Notify() <-chan struct{} {
return nil
}

func (c *configTracker) contractConfig() types.ContractConfig {
return types.ContractConfig{
ConfigDigest: c.cfg.ConfigDigest,
ConfigCount: c.cfg.ConfigCount,
Expand All @@ -33,17 +48,13 @@ func (c *configTracker) LatestConfig(ctx context.Context, changedInBlock uint64)
OnchainConfig: []byte{},
OffchainConfigVersion: c.cfg.Config.OffchainConfigVersion,
OffchainConfig: c.cfg.Config.OffchainConfig,
}, nil
}

// LatestConfigDetails implements types.ContractConfigTracker.
func (c *configTracker) LatestConfigDetails(ctx context.Context) (changedInBlock uint64, configDigest types.ConfigDigest, err error) {
return 0, c.cfg.ConfigDigest, nil
}
}

// Notify implements types.ContractConfigTracker.
func (c *configTracker) Notify() <-chan struct{} {
return nil
// PublicConfig returns the OCR configuration as a PublicConfig so that we can
// access ReportingPluginConfig and other fields prior to launching the plugins.
func (c *configTracker) PublicConfig() (ocr3confighelper.PublicConfig, error) {
return ocr3confighelper.PublicConfigFromContractConfig(false, c.contractConfig())
}

func toOnchainPublicKeys(signers [][]byte) []types.OnchainPublicKey {
Expand Down
32 changes: 30 additions & 2 deletions core/capabilities/ccip/oraclecreator/inprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
chainsel "github.com/smartcontractkit/chain-selectors"

"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"

"github.com/smartcontractkit/libocr/commontypes"
libocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus"
Expand Down Expand Up @@ -46,6 +47,10 @@ import (

var _ cctypes.OracleCreator = &inprocessOracleCreator{}

const (
defaultCommitGasLimit = 500_000
)

// inprocessOracleCreator creates oracles that reference plugins running
// in the same process as the chainlink node, i.e not LOOPPs.
type inprocessOracleCreator struct {
Expand Down Expand Up @@ -148,6 +153,24 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp
destChainFamily := relay.NetworkEVM
destRelayID := types.NewRelayID(destChainFamily, fmt.Sprintf("%d", destChainID))

configTracker := ocrimpls.NewConfigTracker(config)
publicConfig, err := configTracker.PublicConfig()
if err != nil {
return nil, fmt.Errorf("failed to get public config from OCR config: %w", err)
}
var execBatchGasLimit uint64
if pluginType == cctypes.PluginTypeCCIPExec {
execOffchainConfig, err := pluginconfig.DecodeExecuteOffchainConfig(publicConfig.ReportingPluginConfig)
if err != nil {
return nil, fmt.Errorf("failed to decode execute offchain config: %w, raw: %s",
err, string(publicConfig.ReportingPluginConfig))
}
if execOffchainConfig.BatchGasLimit == 0 && destChainFamily == relay.NetworkEVM {
return nil, fmt.Errorf("BatchGasLimit not set in execute offchain config, must be > 0")
}
execBatchGasLimit = execOffchainConfig.BatchGasLimit
}

// this is so that we can use the msg hasher and report encoder from that dest chain relayer's provider.
contractReaders := make(map[cciptypes.ChainSelector]types.ContractReader)
chainWriters := make(map[cciptypes.ChainSelector]types.ChainWriter)
Expand Down Expand Up @@ -208,7 +231,12 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp
chain.Client(),
chain.TxManager(),
chain.GasEstimator(),
evmconfig.ChainWriterConfigRaw(fromAddress, chain.Config().EVM().GasEstimator().PriceMaxKey(fromAddress)),
evmconfig.ChainWriterConfigRaw(
fromAddress,
chain.Config().EVM().GasEstimator().PriceMaxKey(fromAddress),
defaultCommitGasLimit,
execBatchGasLimit,
),
)
if err2 != nil {
return nil, fmt.Errorf("failed to create chain writer for chain %s: %w", chain.ID(), err2)
Expand Down Expand Up @@ -297,7 +325,7 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp
BinaryNetworkEndpointFactory: i.peerWrapper.Peer2,
Database: i.db,
V2Bootstrappers: i.bootstrapperLocators,
ContractConfigTracker: ocrimpls.NewConfigTracker(config),
ContractConfigTracker: configTracker,
ContractTransmitter: transmitter,
LocalConfig: defaultLocalConfig(),
Logger: ocrcommon.NewOCRWrapper(
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ require (
github.com/sethvargo/go-retry v0.2.4 // indirect
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
github.com/shirou/gopsutil/v3 v3.24.3 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240801174805-480934b67956 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240806092752-d01cc4681531 // indirect
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45 // indirect
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240718160222-2dc0c8136bfa // indirect
github.com/smartcontractkit/chainlink-feeds v0.0.0-20240710170203-5b41615da827 // indirect
Expand Down Expand Up @@ -333,7 +333,7 @@ require (
go.uber.org/zap v1.27.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 // indirect
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect
golang.org/x/mod v0.19.0 // indirect
golang.org/x/net v0.27.0 // indirect
golang.org/x/oauth2 v0.20.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1070,8 +1070,8 @@ github.com/smartcontractkit/chain-selectors v1.0.19 h1:y82TyWaOA6gSvi26bbyDYgfZv
github.com/smartcontractkit/chain-selectors v1.0.19/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.4 h1:iyW181JjKHLNMnDleI8umfIfVVlwC7+n5izbLSFgjw8=
github.com/smartcontractkit/chainlink-automation v1.0.4/go.mod h1:u4NbPZKJ5XiayfKHD/v3z3iflQWqvtdhj13jVZXj/cM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240801174805-480934b67956 h1:2PmmxcZY1/7Zp65BG0X5uXoxo1l+F5u8OdtulPHJjyA=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240801174805-480934b67956/go.mod h1:K67FldZZmg+//7yyI0yBMXEw6uvYevTj/ErBEvXaBXM=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240806092752-d01cc4681531 h1:EUqZZP8NUJMErH4//R1sPgjOfNgYcNQhF03kD9Z2qYU=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240806092752-d01cc4681531/go.mod h1:wl0SRmyJ2ARxz+4Eho6nEXsmWFXxTSYpvcb30AxwKyE=
github.com/smartcontractkit/chainlink-common v0.2.1-0.20240717132349-ee5af9b79834 h1:pTf4xdcmiWBqWZ6rTy2RMTDBzhHk89VC1pM7jXKQztI=
github.com/smartcontractkit/chainlink-common v0.2.1-0.20240717132349-ee5af9b79834/go.mod h1:fh9eBbrReCmv31bfz52ENCAMa7nTKQbdhb2B3+S2VGo=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45 h1:NBQLtqk8zsyY4qTJs+NElI3aDFTcAo83JHvqD04EvB0=
Expand Down Expand Up @@ -1351,8 +1351,8 @@ golang.org/x/exp v0.0.0-20191227195350-da58074b4299/go.mod h1:2RIsYlXP63K8oxa1u0
golang.org/x/exp v0.0.0-20200119233911-0405dc783f0a/go.mod h1:2RIsYlXP63K8oxa1u096TMicItID8zy7Y6sNkU49FU4=
golang.org/x/exp v0.0.0-20200207192155-f17229e696bd/go.mod h1:J/WKrq2StrnmMY6+EHIKF9dgMWnmCNThgcyBT1FY9mM=
golang.org/x/exp v0.0.0-20200224162631-6cc2880d07d6/go.mod h1:3jZMyOhIsHpP37uCMkUooju7aAi5cS1Q23tOzKc+0MU=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7 h1:wDLEX9a7YQoKdKNQt88rtydkqDxeGaBUTnIYc3iG/mA=
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8=
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY=
golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js=
golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ require (
github.com/shopspring/decimal v1.4.0
github.com/smartcontractkit/chain-selectors v1.0.19
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240801174805-480934b67956
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240806092752-d01cc4681531
github.com/smartcontractkit/chainlink-common v0.2.1-0.20240717132349-ee5af9b79834
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240710121324-3ed288aa9b45
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240718160222-2dc0c8136bfa
Expand Down Expand Up @@ -103,7 +103,7 @@ require (
go.uber.org/multierr v1.11.0
go.uber.org/zap v1.27.0
golang.org/x/crypto v0.25.0
golang.org/x/exp v0.0.0-20240716175740-e3f259677ff7
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/mod v0.19.0
golang.org/x/net v0.27.0
golang.org/x/sync v0.7.0
Expand Down
Loading

0 comments on commit 6f4049f

Please sign in to comment.