Skip to content

Commit

Permalink
Pass the home chain selector (#14500)
Browse files Browse the repository at this point in the history
* pass the home chain selector

* Refactor contract reader configuration and add RMNHome contract support

* Update chainlink-ccip dependency version

* changeset

* new chainlink-ccip version

* bump chainlink-ccip

* bump to main branch commit

* using latest chainlink-ccip commit
  • Loading branch information
0xnogo authored Sep 30, 2024
1 parent 8fa9a67 commit d435981
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 13 deletions.
5 changes: 5 additions & 0 deletions .changeset/tidy-apricots-care.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"chainlink": minor
---

#added Pass the home chain selector to the commit plugin factory
12 changes: 12 additions & 0 deletions core/capabilities/ccip/configs/evm/contract_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,12 @@ var (
nonceManagerABI = evmtypes.MustGetABI(nonce_manager.NonceManagerABI)
priceFeedABI = evmtypes.MustGetABI(aggregator_v3_interface.AggregatorV3InterfaceABI)
rmnRemoteABI = evmtypes.MustGetABI(rmn_remote.RMNRemoteABI)
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 {
Expand Down Expand Up @@ -249,6 +253,14 @@ var HomeChainReaderConfigRaw = evmrelaytypes.ChainReaderConfig{
},
},
},
consts.ContractNameRMNHome: {
ContractABI: rmnHomeString,
Configs: map[string]*evmrelaytypes.ChainReaderDefinition{
consts.MethodNameGetAllConfigs: {
ChainSpecificName: mustGetMethodName("getAllConfigs", rmnHomeABI),
},
},
},
},
}

Expand Down
16 changes: 16 additions & 0 deletions core/capabilities/ccip/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package ccip
import (
"context"
"fmt"
"strconv"
"time"

"github.com/smartcontractkit/chainlink-common/pkg/loop"
Expand All @@ -23,7 +24,11 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/query/primitives"

chainsel "github.com/smartcontractkit/chain-selectors"

cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"

"github.com/smartcontractkit/chainlink/v2/core/chains/legacyevm"
"github.com/smartcontractkit/chainlink/v2/core/config"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry"
Expand Down Expand Up @@ -162,6 +167,16 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services
ccipConfigBinding,
)

// get the chain selector for the home chain
homeChainChainID, err := strconv.ParseUint(d.capabilityConfig.ExternalRegistry().RelayID().ChainID, 10, 64)
if err != nil {
return nil, fmt.Errorf("failed to parse chain ID %s: %w", d.capabilityConfig.ExternalRegistry().RelayID().ChainID, err)
}
homeChainChainSelector, err := chainsel.SelectorFromChainId(homeChainChainID)
if err != nil {
return nil, fmt.Errorf("failed to get chain selector from chain ID %d", homeChainChainID)
}

// if bootstrappers are provided we assume that the node is a plugin oracle.
// the reason for this is that bootstrap oracles do not need to be aware
// of other bootstrap oracles. however, plugin oracles, at least initially,
Expand All @@ -182,6 +197,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services
d.monitoringEndpointGen,
bootstrapperLocators,
hcr,
cciptypes.ChainSelector(homeChainChainSelector),
)
} else {
oracleCreator = oraclecreator.NewBootstrapOracleCreator(
Expand Down
24 changes: 23 additions & 1 deletion core/capabilities/ccip/oraclecreator/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ type pluginOracleCreator struct {
monitoringEndpointGen telemetry.MonitoringEndpointGenerator
bootstrapperLocators []commontypes.BootstrapperLocator
homeChainReader ccipreaderpkg.HomeChain
homeChainSelector cciptypes.ChainSelector
}

func NewPluginOracleCreator(
Expand All @@ -83,6 +84,7 @@ func NewPluginOracleCreator(
monitoringEndpointGen telemetry.MonitoringEndpointGenerator,
bootstrapperLocators []commontypes.BootstrapperLocator,
homeChainReader ccipreaderpkg.HomeChain,
homeChainSelector cciptypes.ChainSelector,
) cctypes.OracleCreator {
return &pluginOracleCreator{
ocrKeyBundles: ocrKeyBundles,
Expand All @@ -98,6 +100,7 @@ func NewPluginOracleCreator(
monitoringEndpointGen: monitoringEndpointGen,
bootstrapperLocators: bootstrapperLocators,
homeChainReader: homeChainReader,
homeChainSelector: homeChainSelector,
}
}

Expand Down Expand Up @@ -220,6 +223,7 @@ func (i *pluginOracleCreator) createFactoryAndTransmitter(
ccipevm.NewCommitPluginCodecV1(),
ccipevm.NewMessageHasherV1(),
i.homeChainReader,
i.homeChainSelector,
contractReaders,
chainWriters,
)
Expand Down Expand Up @@ -273,6 +277,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() {
Expand All @@ -281,7 +290,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
Expand Down Expand Up @@ -348,9 +357,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 {
Expand All @@ -364,6 +382,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
}

Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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-20240927145425-578a50b4d7c5 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca // 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
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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-20240927145425-578a50b4d7c5 h1:958op4dZQK46g4zk9gQTj0GLa2G+jbuj4oHAnneJ4PI=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240927145425-578a50b4d7c5/go.mod h1:Q51RNKBrkqSJ0U2bwGQx4RL2X7c1qUL3NXVZF2kmCUA=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca h1:cvifSiZr9VifpKjgVtGaEqknz2MwpY4shQhoOLpgQUE=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca/go.mod h1:hxKOwuo3HBC9a5hoNOvstl2wVF6Z9kZDssHU5VCdqk8=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57 h1:pRiTiFOkPEyvgG0hchcCSZzwUbwYydnZBu0QbVaRnVk=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57/go.mod h1:F6WUS6N4mP5ScwpwyTyAJc9/vjR+GXbMCRUOVekQi1g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
Expand Down
2 changes: 1 addition & 1 deletion 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.23
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240927145425-578a50b4d7c5
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240916152957-433914114bd2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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-20240927145425-578a50b4d7c5 h1:958op4dZQK46g4zk9gQTj0GLa2G+jbuj4oHAnneJ4PI=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240927145425-578a50b4d7c5/go.mod h1:Q51RNKBrkqSJ0U2bwGQx4RL2X7c1qUL3NXVZF2kmCUA=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca h1:cvifSiZr9VifpKjgVtGaEqknz2MwpY4shQhoOLpgQUE=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca/go.mod h1:hxKOwuo3HBC9a5hoNOvstl2wVF6Z9kZDssHU5VCdqk8=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57 h1:pRiTiFOkPEyvgG0hchcCSZzwUbwYydnZBu0QbVaRnVk=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57/go.mod h1:F6WUS6N4mP5ScwpwyTyAJc9/vjR+GXbMCRUOVekQi1g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ require (
github.com/smartcontractkit/ccip-owner-contracts v0.0.0-20240926212305-a6deabdfce86
github.com/smartcontractkit/chain-selectors v1.0.23
github.com/smartcontractkit/chainlink-automation v1.0.4
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240927145425-578a50b4d7c5
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57
github.com/smartcontractkit/chainlink-testing-framework/havoc v1.50.0
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.9
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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-20240927145425-578a50b4d7c5 h1:958op4dZQK46g4zk9gQTj0GLa2G+jbuj4oHAnneJ4PI=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240927145425-578a50b4d7c5/go.mod h1:Q51RNKBrkqSJ0U2bwGQx4RL2X7c1qUL3NXVZF2kmCUA=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca h1:cvifSiZr9VifpKjgVtGaEqknz2MwpY4shQhoOLpgQUE=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca/go.mod h1:hxKOwuo3HBC9a5hoNOvstl2wVF6Z9kZDssHU5VCdqk8=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57 h1:pRiTiFOkPEyvgG0hchcCSZzwUbwYydnZBu0QbVaRnVk=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57/go.mod h1:F6WUS6N4mP5ScwpwyTyAJc9/vjR+GXbMCRUOVekQi1g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
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 @@ -30,7 +30,7 @@ require (
require (
github.com/AlekSi/pointer v1.1.0 // indirect
github.com/smartcontractkit/chainlink-automation v1.0.4 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240927145425-578a50b4d7c5 // indirect
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca // indirect
github.com/smartcontractkit/libocr v0.0.0-20240717100443-f6226e09bee7 // indirect
)

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 @@ -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-20240927145425-578a50b4d7c5 h1:958op4dZQK46g4zk9gQTj0GLa2G+jbuj4oHAnneJ4PI=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240927145425-578a50b4d7c5/go.mod h1:Q51RNKBrkqSJ0U2bwGQx4RL2X7c1qUL3NXVZF2kmCUA=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca h1:cvifSiZr9VifpKjgVtGaEqknz2MwpY4shQhoOLpgQUE=
github.com/smartcontractkit/chainlink-ccip v0.0.0-20240930060710-158d2a9ac9ca/go.mod h1:hxKOwuo3HBC9a5hoNOvstl2wVF6Z9kZDssHU5VCdqk8=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57 h1:pRiTiFOkPEyvgG0hchcCSZzwUbwYydnZBu0QbVaRnVk=
github.com/smartcontractkit/chainlink-common v0.2.3-0.20240927162447-20630b333f57/go.mod h1:F6WUS6N4mP5ScwpwyTyAJc9/vjR+GXbMCRUOVekQi1g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240911175228-daf2600bb7b7 h1:lTGIOQYLk1Ufn++X/AvZnt6VOcuhste5yp+C157No/Q=
Expand Down

0 comments on commit d435981

Please sign in to comment.