diff --git a/core/services/ccipcapability/oraclecreator/inprocess.go b/core/services/ccipcapability/oraclecreator/inprocess.go index f70212911f..995574ff0a 100644 --- a/core/services/ccipcapability/oraclecreator/inprocess.go +++ b/core/services/ccipcapability/oraclecreator/inprocess.go @@ -10,6 +10,7 @@ import ( "github.com/google/uuid" "github.com/prometheus/client_golang/prometheus" chainsel "github.com/smartcontractkit/chain-selectors" + "github.com/smartcontractkit/chainlink-ccip/pkg/consts" "github.com/smartcontractkit/libocr/commontypes" libocr3 "github.com/smartcontractkit/libocr/offchainreporting2plus" "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" @@ -179,6 +180,20 @@ func (i *inprocessOracleCreator) CreatePluginOracle(pluginType cctypes.PluginTyp return nil, fmt.Errorf("failed to create contract reader for chain %s: %w", chain.ID(), err) } + if chain.ID().Uint64() == destChainID { + // bind the chain reader to the dest chain's offramp. + offrampAddressHex := common.BytesToAddress(config.Config.OfframpAddress).Hex() + err3 := cr.Bind(context.Background(), []types.BoundContract{ + { + Address: offrampAddressHex, + Name: consts.ContractNameOffRamp, + }, + }) + if err3 != nil { + return nil, fmt.Errorf("failed to bind chain reader for dest chain %s's offramp at %s: %w", chain.ID(), offrampAddressHex, err3) + } + } + // Even though we only write to the dest chain, we need to create chain writers for all chains // we know about in order to post gas prices on the dest. var fromAddress common.Address diff --git a/core/services/ocr3/plugins/ccip_integration_tests/helpers.go b/core/services/ocr3/plugins/ccip_integration_tests/helpers.go index b9b257d885..cc718b7fe6 100644 --- a/core/services/ocr3/plugins/ccip_integration_tests/helpers.go +++ b/core/services/ocr3/plugins/ccip_integration_tests/helpers.go @@ -127,7 +127,7 @@ func createUniverses( backend, evm_2_evm_multi_onramp.EVM2EVMMultiOnRampStaticConfig{ LinkToken: linkToken.Address(), - ChainSelector: chainID, + ChainSelector: getSelector(chainID), RmnProxy: rmnProxy.Address(), MaxFeeJuelsPerMsg: big.NewInt(1e18), NonceManager: nonceManager.Address(), @@ -168,7 +168,7 @@ func createUniverses( owner, backend, evm_2_evm_multi_offramp.EVM2EVMMultiOffRampStaticConfig{ - ChainSelector: chainID, + ChainSelector: getSelector(chainID), RmnProxy: rmnProxy.Address(), TokenAdminRegistry: tokenAdminRegistry.Address(), NonceManager: nonceManager.Address(), @@ -493,11 +493,11 @@ func wireRouter(t *testing.T, uni onchainUniverse, universes map[uint64]onchainU continue } routerOnrampUpdates = append(routerOnrampUpdates, router.RouterOnRamp{ - DestChainSelector: remoteChainID, + DestChainSelector: getSelector(remoteChainID), OnRamp: uni.onramp.Address(), }) routerOfframpUpdates = append(routerOfframpUpdates, router.RouterOffRamp{ - SourceChainSelector: remoteChainID, + SourceChainSelector: getSelector(remoteChainID), OffRamp: uni.offramp.Address(), }) } @@ -515,7 +515,7 @@ func wireOnRamp(t *testing.T, uni onchainUniverse, universes map[uint64]onchainU continue } onrampDestChainConfigArgs = append(onrampDestChainConfigArgs, evm_2_evm_multi_onramp.EVM2EVMMultiOnRampDestChainConfigArgs{ - DestChainSelector: remoteChainID, + DestChainSelector: getSelector(remoteChainID), DynamicConfig: defaultOnRampDynamicConfig(t), }) } @@ -533,7 +533,7 @@ func wireOffRamp(t *testing.T, uni onchainUniverse, universes map[uint64]onchain continue } offrampSourceChainConfigArgs = append(offrampSourceChainConfigArgs, evm_2_evm_multi_offramp.EVM2EVMMultiOffRampSourceChainConfigArgs{ - SourceChainSelector: remoteChainID, // for each destination chain, add a source chain config + SourceChainSelector: getSelector(remoteChainID), // for each destination chain, add a source chain config IsEnabled: true, OnRamp: remoteUniverse.onramp.Address().Bytes(), }) @@ -543,6 +543,14 @@ func wireOffRamp(t *testing.T, uni onchainUniverse, universes map[uint64]onchain uni.backend.Commit() } +func getSelector(chainID uint64) uint64 { + selector, err := chainsel.SelectorFromChainId(chainID) + if err != nil { + panic(err) + } + return selector +} + // initRemoteChainsGasPrices sets the gas prices for all chains except the local chain in the local price registry func initRemoteChainsGasPrices(t *testing.T, uni onchainUniverse, universes map[uint64]onchainUniverse) { var gasPriceUpdates []price_registry.InternalGasPriceUpdate @@ -552,7 +560,7 @@ func initRemoteChainsGasPrices(t *testing.T, uni onchainUniverse, universes map[ } gasPriceUpdates = append(gasPriceUpdates, price_registry.InternalGasPriceUpdate{ - DestChainSelector: remoteChainID, + DestChainSelector: getSelector(remoteChainID), UsdPerUnitGas: big.NewInt(2e12), }, ) diff --git a/core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go b/core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go index b9e28f3af5..4162b0d0af 100644 --- a/core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go +++ b/core/services/ocr3/plugins/ccip_integration_tests/ocr3_node_test.go @@ -13,8 +13,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/chainlink" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" - chainselectors "github.com/smartcontractkit/chain-selectors" - "github.com/smartcontractkit/libocr/commontypes" confighelper2 "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" @@ -108,8 +106,7 @@ func TestIntegration_OCR3Nodes(t *testing.T) { for _, uni := range universes { // Add nodes and give them the capability t.Log("AddingDON for universe: ", uni.chainID) - chainSelector, err := chainselectors.SelectorFromChainId(uni.chainID) - require.NoError(t, err) + chainSelector := getSelector(uni.chainID) homeChainUni.AddDON(t, ccipCapabilityID, chainSelector, @@ -125,17 +122,17 @@ func TestIntegration_OCR3Nodes(t *testing.T) { for chainID, universe := range universes { for otherChain, pingPong := range pingPongs[chainID] { t.Log("PingPong From: ", chainID, " To: ", otherChain) - _, err := pingPong.StartPingPong(universe.owner) - require.NoError(t, err) + _, err2 := pingPong.StartPingPong(universe.owner) + require.NoError(t, err2) universe.backend.Commit() - logIter, err := universe.onramp.FilterCCIPSendRequested(&bind.FilterOpts{Start: 0}, nil) - require.NoError(t, err) + logIter, err3 := universe.onramp.FilterCCIPSendRequested(&bind.FilterOpts{Start: 0}, nil) + require.NoError(t, err3) // Iterate until latest event for logIter.Next() { } log := logIter.Event - require.Equal(t, otherChain, log.DestChainSelector) + require.Equal(t, getSelector(otherChain), log.DestChainSelector) require.Equal(t, pingPong.Address(), log.Message.Sender) chainPingPongAddr := pingPongs[otherChain][chainID].Address().Bytes() // With chain agnostic addresses we need to pad the address to the correct length if the receiver is zero prefixed diff --git a/core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go b/core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go index 1b1e96693a..4393863353 100644 --- a/core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go +++ b/core/services/ocr3/plugins/ccip_integration_tests/ping_pong_test.go @@ -83,7 +83,7 @@ func initializePingPongContracts( for chainToConnect, pingPong := range pingPongs[chainID] { _, err := pingPong.SetCounterpart( universe.owner, - chainUniverses[chainToConnect].chainID, + getSelector(chainUniverses[chainToConnect].chainID), // This is the address of the ping pong contract on the other chain pingPongs[chainToConnect][chainID].Address(), )