Skip to content

Commit

Permalink
Use chain selectors instead of chain IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Jul 16, 2024
1 parent ad5328b commit ec53a30
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 17 deletions.
15 changes: 15 additions & 0 deletions core/services/ccipcapability/oraclecreator/inprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down
22 changes: 15 additions & 7 deletions core/services/ocr3/plugins/ccip_integration_tests/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
})
}
Expand All @@ -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),
})
}
Expand All @@ -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(),
})
Expand All @@ -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
Expand All @@ -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),
},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
)
Expand Down

0 comments on commit ec53a30

Please sign in to comment.