From a1182a8dc806e39bb503bba654a90a869771549c Mon Sep 17 00:00:00 2001 From: nogo <0xnogo@gmail.com> Date: Wed, 25 Sep 2024 21:26:51 +0400 Subject: [PATCH] Refactor contract reader configuration and add RMNHome contract support --- .../ccip/configs/evm/contract_reader.go | 12 +++++++++++ .../capabilities/ccip/oraclecreator/plugin.go | 20 ++++++++++++++++++- core/scripts/go.mod | 2 +- core/scripts/go.sum | 4 ++-- go.mod | 2 +- go.sum | 4 ++-- integration-tests/go.mod | 2 +- integration-tests/go.sum | 4 ++-- integration-tests/load/go.mod | 2 +- integration-tests/load/go.sum | 4 ++-- 10 files changed, 43 insertions(+), 13 deletions(-) diff --git a/core/capabilities/ccip/configs/evm/contract_reader.go b/core/capabilities/ccip/configs/evm/contract_reader.go index 18aa07cc022..4518d84ae54 100644 --- a/core/capabilities/ccip/configs/evm/contract_reader.go +++ b/core/capabilities/ccip/configs/evm/contract_reader.go @@ -26,8 +26,12 @@ var ( feeQuoterABI = evmtypes.MustGetABI(fee_quoter.FeeQuoterABI) nonceManagerABI = evmtypes.MustGetABI(nonce_manager.NonceManagerABI) priceFeedABI = evmtypes.MustGetABI(aggregator_v3_interface.AggregatorV3InterfaceABI) + rmnHomeABI = evmtypes.MustGetABI(rmnHomeString) ) +// TODO: replace with generated ABI when the contract will be defined +var rmnHomeString = "[{\"inputs\":[],\"name\":\"getAllConfigs\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"num\",\"type\":\"uint256\"}],\"name\":\"store\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]" + // MustSourceReaderConfig returns a ChainReaderConfig that can be used to read from the onramp. // The configuration is marshaled into JSON so that it can be passed to the relayer NewContractReader() method. func MustSourceReaderConfig() []byte { @@ -238,6 +242,14 @@ var HomeChainReaderConfigRaw = evmrelaytypes.ChainReaderConfig{ }, }, }, + consts.ContractNameRMNHome: { + ContractABI: rmnHomeString, + Configs: map[string]*evmrelaytypes.ChainReaderDefinition{ + consts.MethodNameGetAllConfigs: { + ChainSpecificName: mustGetMethodName("getAllConfigs", rmnHomeABI), + }, + }, + }, }, } diff --git a/core/capabilities/ccip/oraclecreator/plugin.go b/core/capabilities/ccip/oraclecreator/plugin.go index 3e61364919e..4321a9bedaf 100644 --- a/core/capabilities/ccip/oraclecreator/plugin.go +++ b/core/capabilities/ccip/oraclecreator/plugin.go @@ -274,6 +274,11 @@ func (i *pluginOracleCreator) createReadersAndWriters( execBatchGasLimit = ofc.exec().BatchGasLimit } + homeChainID, err := i.getChainID(i.homeChainSelector) + if err != nil { + return nil, nil, err + } + contractReaders := make(map[cciptypes.ChainSelector]types.ContractReader) chainWriters := make(map[cciptypes.ChainSelector]types.ChainWriter) for _, chain := range i.chains.Slice() { @@ -282,7 +287,7 @@ func (i *pluginOracleCreator) createReadersAndWriters( return nil, nil, err1 } - chainReaderConfig := getChainReaderConfig(chain.ID().Uint64(), destChainID, ofc, chainSelector) + chainReaderConfig := getChainReaderConfig(chain.ID().Uint64(), destChainID, homeChainID, ofc, chainSelector) cr, err1 := createChainReader(i.lggr, chain, chainReaderConfig, pluginType) if err1 != nil { return nil, nil, err1 @@ -349,9 +354,18 @@ func (i *pluginOracleCreator) getChainSelector(chainID uint64) (cciptypes.ChainS return cciptypes.ChainSelector(chainSelector), nil } +func (i *pluginOracleCreator) getChainID(chainSelector cciptypes.ChainSelector) (uint64, error) { + chainID, err := chainsel.ChainIdFromSelector(uint64(chainSelector)) + if err != nil { + return 0, fmt.Errorf("failed to get chain ID from chain selector %d: %w", chainSelector, err) + } + return chainID, nil +} + func getChainReaderConfig( chainID uint64, destChainID uint64, + homeChainID uint64, ofc offChainConfig, chainSelector cciptypes.ChainSelector, ) evmrelaytypes.ChainReaderConfig { @@ -365,6 +379,10 @@ func getChainReaderConfig( if !ofc.commitEmpty() && ofc.commit().PriceFeedChainSelector == chainSelector { chainReaderConfig = evmconfig.MergeReaderConfigs(chainReaderConfig, evmconfig.FeedReaderConfig) } + + if chainID == homeChainID { + chainReaderConfig = evmconfig.MergeReaderConfigs(chainReaderConfig, evmconfig.HomeChainReaderConfigRaw) + } return chainReaderConfig } diff --git a/core/scripts/go.mod b/core/scripts/go.mod index fe7f01d90a8..ea93716384b 100644 --- a/core/scripts/go.mod +++ b/core/scripts/go.mod @@ -271,7 +271,7 @@ require ( github.com/shirou/gopsutil v3.21.11+incompatible // indirect github.com/shirou/gopsutil/v3 v3.24.3 // indirect github.com/smartcontractkit/chain-selectors v1.0.23 // indirect - github.com/smartcontractkit/chainlink-ccip v0.0.0-20240919185124-2bbe88720888 // indirect + github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1 // indirect github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 // indirect github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240916152957-433914114bd2 // indirect github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f // indirect diff --git a/core/scripts/go.sum b/core/scripts/go.sum index aca4d0072d7..40f53cbd4ed 100644 --- a/core/scripts/go.sum +++ b/core/scripts/go.sum @@ -1081,8 +1081,8 @@ github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnj github.com/smartcontractkit/chain-selectors v1.0.23/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-20240919185124-2bbe88720888 h1:s7545Nj0JNV50bQM9+sPh1/wwjCyGzAxT8NvEKAwte8= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20240919185124-2bbe88720888/go.mod h1:KP82vFCqm+M1G1t6Vos5CewGUGYJkxxCEdxnta4uLlE= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1 h1:69TS78mDeZr9f9OJPJgQ/2loESSPIzqYhWbk4mefvPs= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1/go.mod h1:KP82vFCqm+M1G1t6Vos5CewGUGYJkxxCEdxnta4uLlE= github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420 h1:+xNnYYgkxzKUIkLCOfzfAKUxeLLtuxlalDI70kNJ8No= github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420/go.mod h1:zm+l8gN4LQS1+YvwQDhRz/njirVeWGNiDJKIhCGwaoQ= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q= diff --git a/go.mod b/go.mod index e7c9477b457..d86705abb6a 100644 --- a/go.mod +++ b/go.mod @@ -74,7 +74,7 @@ require ( github.com/shopspring/decimal v1.4.0 github.com/smartcontractkit/chain-selectors v1.0.23 github.com/smartcontractkit/chainlink-automation v1.0.4 - github.com/smartcontractkit/chainlink-ccip v0.0.0-20240919185124-2bbe88720888 + github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1 github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420 github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240916152957-433914114bd2 diff --git a/go.sum b/go.sum index c5d9c312c5f..ba15c0cdf10 100644 --- a/go.sum +++ b/go.sum @@ -1042,8 +1042,8 @@ github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnj github.com/smartcontractkit/chain-selectors v1.0.23/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-20240919185124-2bbe88720888 h1:s7545Nj0JNV50bQM9+sPh1/wwjCyGzAxT8NvEKAwte8= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20240919185124-2bbe88720888/go.mod h1:KP82vFCqm+M1G1t6Vos5CewGUGYJkxxCEdxnta4uLlE= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1 h1:69TS78mDeZr9f9OJPJgQ/2loESSPIzqYhWbk4mefvPs= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1/go.mod h1:KP82vFCqm+M1G1t6Vos5CewGUGYJkxxCEdxnta4uLlE= github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420 h1:+xNnYYgkxzKUIkLCOfzfAKUxeLLtuxlalDI70kNJ8No= github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420/go.mod h1:zm+l8gN4LQS1+YvwQDhRz/njirVeWGNiDJKIhCGwaoQ= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q= diff --git a/integration-tests/go.mod b/integration-tests/go.mod index d21019b11f8..cf7b147fae7 100644 --- a/integration-tests/go.mod +++ b/integration-tests/go.mod @@ -38,7 +38,7 @@ require ( github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240910151738-3f318badcfb5 github.com/smartcontractkit/chain-selectors v1.0.23 github.com/smartcontractkit/chainlink-automation v1.0.4 - github.com/smartcontractkit/chainlink-ccip v0.0.0-20240919185124-2bbe88720888 + github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1 github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420 github.com/smartcontractkit/chainlink-testing-framework/havoc v1.50.0 github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.6 diff --git a/integration-tests/go.sum b/integration-tests/go.sum index 9aac0a41470..315c3fe1fe9 100644 --- a/integration-tests/go.sum +++ b/integration-tests/go.sum @@ -1423,8 +1423,8 @@ github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnj github.com/smartcontractkit/chain-selectors v1.0.23/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-20240919185124-2bbe88720888 h1:s7545Nj0JNV50bQM9+sPh1/wwjCyGzAxT8NvEKAwte8= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20240919185124-2bbe88720888/go.mod h1:KP82vFCqm+M1G1t6Vos5CewGUGYJkxxCEdxnta4uLlE= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1 h1:69TS78mDeZr9f9OJPJgQ/2loESSPIzqYhWbk4mefvPs= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1/go.mod h1:KP82vFCqm+M1G1t6Vos5CewGUGYJkxxCEdxnta4uLlE= github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420 h1:+xNnYYgkxzKUIkLCOfzfAKUxeLLtuxlalDI70kNJ8No= github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420/go.mod h1:zm+l8gN4LQS1+YvwQDhRz/njirVeWGNiDJKIhCGwaoQ= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q= diff --git a/integration-tests/load/go.mod b/integration-tests/load/go.mod index 4011722a723..373ebcdadb1 100644 --- a/integration-tests/load/go.mod +++ b/integration-tests/load/go.mod @@ -386,7 +386,7 @@ require ( github.com/shopspring/decimal v1.4.0 // indirect github.com/sirupsen/logrus v1.9.3 // indirect github.com/smartcontractkit/chain-selectors v1.0.23 // indirect - github.com/smartcontractkit/chainlink-ccip v0.0.0-20240919185124-2bbe88720888 // indirect + github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1 // indirect github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 // indirect github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240916152957-433914114bd2 // indirect github.com/smartcontractkit/chainlink-feeds v0.0.0-20240910155501-42f20443189f // indirect diff --git a/integration-tests/load/go.sum b/integration-tests/load/go.sum index 9bab4980401..4613b61a6ba 100644 --- a/integration-tests/load/go.sum +++ b/integration-tests/load/go.sum @@ -1397,8 +1397,8 @@ github.com/smartcontractkit/chain-selectors v1.0.23 h1:D2Eaex4Cw/O7Lg3tX6WklOqnj github.com/smartcontractkit/chain-selectors v1.0.23/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-20240919185124-2bbe88720888 h1:s7545Nj0JNV50bQM9+sPh1/wwjCyGzAxT8NvEKAwte8= -github.com/smartcontractkit/chainlink-ccip v0.0.0-20240919185124-2bbe88720888/go.mod h1:KP82vFCqm+M1G1t6Vos5CewGUGYJkxxCEdxnta4uLlE= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1 h1:69TS78mDeZr9f9OJPJgQ/2loESSPIzqYhWbk4mefvPs= +github.com/smartcontractkit/chainlink-ccip v0.0.0-20240925132715-27eedb719ed1/go.mod h1:KP82vFCqm+M1G1t6Vos5CewGUGYJkxxCEdxnta4uLlE= github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420 h1:+xNnYYgkxzKUIkLCOfzfAKUxeLLtuxlalDI70kNJ8No= github.com/smartcontractkit/chainlink-common v0.2.3-0.20240919092417-53e784c2e420/go.mod h1:zm+l8gN4LQS1+YvwQDhRz/njirVeWGNiDJKIhCGwaoQ= github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=