Skip to content

Commit

Permalink
adding home chain changes
Browse files Browse the repository at this point in the history
  • Loading branch information
yashnevatia committed Jan 10, 2025
1 parent fa9d9f9 commit 57965b9
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 40 deletions.
6 changes: 3 additions & 3 deletions deployment/ccip/changeset/cs_active_candidate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func Test_ActiveCandidate(t *testing.T) {

// Now we can add a candidate config, send another request, and observe behavior.
// The candidate config should not be able to execute messages.
tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds)
tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].LinkToken.Address().String(), state.Chains[tenv.FeedChainSel].Weth9.Address().String(), tenv.FeedChainSel)
_, err = commonchangeset.ApplyChangesets(t, tenv.Env, tenv.TimelockContracts(t), []commonchangeset.ChangesetApplication{
{
Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset),
Expand All @@ -199,7 +199,7 @@ func Test_ActiveCandidate(t *testing.T) {
OCRConfigPerRemoteChainSelector: map[uint64]CCIPOCRParams{
dest: DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9),
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken.Address().String(), state.Chains[dest].Weth9.Address().String()),
nil,
),
},
Expand All @@ -220,7 +220,7 @@ func Test_ActiveCandidate(t *testing.T) {
OCRConfigPerRemoteChainSelector: map[uint64]CCIPOCRParams{
dest: DefaultOCRParams(
tenv.FeedChainSel,
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9),
tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken.Address().String(), state.Chains[dest].Weth9.Address().String()),
nil,
),
},
Expand Down
34 changes: 20 additions & 14 deletions deployment/ccip/changeset/cs_ccip_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,8 @@ func (p PromoteCandidatesChangesetConfig) Validate(e deployment.Environment) ([]
if err := deployment.IsValidChainSelector(chainSelector); err != nil {
return nil, fmt.Errorf("don chain selector invalid: %w", err)
}
chainState, exists := state.Chains[chainSelector]
if !exists {
return nil, fmt.Errorf("chain %d does not exist", chainSelector)
}
if chainState.OffRamp == nil {
// should not be possible, but a defensive check.
return nil, errors.New("OffRamp contract does not exist")
if err := state.ValidateState(chainSelector); err != nil {
return nil, err
}

donID, err := internal.DonIDForChain(
Expand Down Expand Up @@ -311,9 +306,8 @@ func (s SetCandidateConfigBase) Validate(e deployment.Environment, state CCIPOnC
if err := deployment.IsValidChainSelector(chainSelector); err != nil {
return fmt.Errorf("don chain selector invalid: %w", err)
}
if state.Chains[chainSelector].OffRamp == nil {
// should not be possible, but a defensive check.
return fmt.Errorf("OffRamp contract does not exist on don chain selector %d", chainSelector)
if err := state.ValidateState(chainSelector); err != nil {
return err
}
if s.PluginType != types.PluginTypeCCIPCommit &&
s.PluginType != types.PluginTypeCCIPExec {
Expand Down Expand Up @@ -423,10 +417,16 @@ func AddDonAndSetCandidateChangeset(
}
var donOps []mcms.Operation
for chainSelector, params := range cfg.OCRConfigPerRemoteChainSelector {
var offRampAddress []byte
if deployment.IsSolanaChainFamily(chainSelector) {
offRampAddress = state.SolChains[chainSelector].SolCcipRouter.Bytes()
} else {
offRampAddress = state.Chains[chainSelector].OffRamp.Address().Bytes()
}
newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome(
e.OCRSecrets,
state.Chains[chainSelector].OffRamp,
e.Chains[chainSelector],
offRampAddress,
chainSelector,
nodes.NonBootstraps(),
state.Chains[cfg.HomeChainSelector].RMNHome.Address(),
params.OCRParameters,
Expand Down Expand Up @@ -598,10 +598,16 @@ func SetCandidateChangeset(
}
var setCandidateOps []mcms.Operation
for chainSelector, params := range cfg.OCRConfigPerRemoteChainSelector {
var offRampAddress []byte
if deployment.IsSolanaChainFamily(chainSelector) {
offRampAddress = state.SolChains[chainSelector].SolCcipRouter.Bytes()
} else {
offRampAddress = state.Chains[chainSelector].OffRamp.Address().Bytes()
}
newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome(
e.OCRSecrets,
state.Chains[chainSelector].OffRamp,
e.Chains[chainSelector],
offRampAddress,
chainSelector,
nodes.NonBootstraps(),
state.Chains[cfg.HomeChainSelector].RMNHome.Address(),
params.OCRParameters,
Expand Down
12 changes: 6 additions & 6 deletions deployment/ccip/changeset/internal/deploy_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ func BuildSetOCR3ConfigArgs(

func BuildOCR3ConfigForCCIPHome(
ocrSecrets deployment.OCRSecrets,
offRamp *offramp.OffRamp,
dest deployment.Chain,
offRampAddress []byte,
destSelector uint64,
nodes deployment.Nodes,
rmnHomeAddress common.Address,
ocrParams types2.OCRParameters,
Expand All @@ -212,9 +212,9 @@ func BuildOCR3ConfigForCCIPHome(
var oracles []confighelper.OracleIdentityExtra
for _, node := range nodes {
schedule = append(schedule, 1)
cfg, exists := node.OCRConfigForChainSelector(dest.Selector)
cfg, exists := node.OCRConfigForChainSelector(destSelector)
if !exists {
return nil, fmt.Errorf("no OCR config for chain %d", dest.Selector)
return nil, fmt.Errorf("no OCR config for chain %d", destSelector)
}
oracles = append(oracles, confighelper.OracleIdentityExtra{
OracleIdentity: confighelper.OracleIdentity{
Expand Down Expand Up @@ -314,10 +314,10 @@ func BuildOCR3ConfigForCCIPHome(

ocr3Configs[pluginType] = ccip_home.CCIPHomeOCR3Config{
PluginType: uint8(pluginType),
ChainSelector: dest.Selector,
ChainSelector: destSelector,
FRoleDON: configF,
OffchainConfigVersion: offchainConfigVersion,
OfframpAddress: offRamp.Address().Bytes(),
OfframpAddress: offRampAddress,
Nodes: ocrNodes,
OffchainConfig: offchainConfig,
RmnHomeAddress: rmnHomeAddress.Bytes(),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[101,238,189,81,99,141,117,176,11,49,33,2,218,239,163,125,209,246,2,133,177,222,143,89,48,80,244,247,247,141,216,183,145,28,85,130,47,80,170,11,121,40,143,49,171,88,54,235,39,125,182,141,1,69,71,62,148,230,124,191,22,218,25,173]
41 changes: 40 additions & 1 deletion deployment/ccip/changeset/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry_1_1_0"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/burn_mint_erc677"

chain_selectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/nonce_manager"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/offramp"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp"
Expand Down Expand Up @@ -347,6 +348,9 @@ func (s CCIPOnChainState) SupportedChains() map[uint64]struct{} {
for chain := range s.Chains {
chains[chain] = struct{}{}
}
for chain := range s.SolChains {
chains[chain] = struct{}{}
}
return chains
}

Expand Down Expand Up @@ -375,8 +379,13 @@ func (s CCIPOnChainState) View(chains []uint64) (map[string]view.ChainView, erro
}

func LoadOnchainState(e deployment.Environment) (CCIPOnChainState, error) {
solState, err := LoadOnchainStateSolana(e)
if err != nil {
return CCIPOnChainState{}, err
}
state := CCIPOnChainState{
Chains: make(map[uint64]CCIPChainState),
Chains: make(map[uint64]CCIPChainState),
SolChains: solState.SolChains,
}
for chainSelector, chain := range e.Chains {
addresses, err := e.ExistingAddresses.AddressesForChain(chainSelector)
Expand Down Expand Up @@ -664,3 +673,33 @@ func LoadChainState(chain deployment.Chain, addresses map[string]deployment.Type
}
return state, nil
}

func (s CCIPOnChainState) ValidateState(chainSelector uint64) error {
family, err := chain_selectors.GetSelectorFamily(chainSelector)
if err != nil {
return err
}
switch family {
case chain_selectors.FamilyEVM:
chainState, exists := s.Chains[chainSelector]
if !exists {
return fmt.Errorf("chain %d does not exist", chainSelector)
}
if chainState.OffRamp == nil {
// should not be possible, but a defensive check.
return errors.New("OffRamp contract does not exist")
}
case chain_selectors.FamilySolana:
chainState, exists := s.SolChains[chainSelector]
if !exists {
return fmt.Errorf("chain %d does not exist", chainSelector)
}
if chainState.SolCcipRouter.IsZero() {
// should not be possible, but a defensive check.
return errors.New("CCIP router contract does not exist")
}
default:
return fmt.Errorf("unknown chain family %s", family)
}
return nil
}
18 changes: 12 additions & 6 deletions deployment/ccip/changeset/test_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ func (d *DeployedEnv) SetupJobs(t *testing.T) {

type MemoryEnvironment struct {
DeployedEnv
Chains map[uint64]deployment.Chain
Chains map[uint64]deployment.Chain
SolChains map[uint64]deployment.SolChain
}

func (m *MemoryEnvironment) DeployedEnvironment() DeployedEnv {
Expand All @@ -259,12 +260,14 @@ func (m *MemoryEnvironment) StartChains(t *testing.T, tc *TestConfigs) {
chains, users = memory.NewMemoryChains(t, tc.Chains, tc.NumOfUsersPerChain)
}
m.Chains = chains
m.SolChains = memory.NewMemoryChainsSol(t, 1)
homeChainSel, feedSel := allocateCCIPChainSelectors(chains)
replayBlocks, err := LatestBlocksByChain(ctx, chains)
require.NoError(t, err)
m.DeployedEnv = DeployedEnv{
Env: deployment.Environment{
Chains: m.Chains,
Chains: m.Chains,
SolChains: m.SolChains,
},
HomeChainSel: homeChainSel,
FeedChainSel: feedSel,
Expand All @@ -276,7 +279,7 @@ func (m *MemoryEnvironment) StartChains(t *testing.T, tc *TestConfigs) {
func (m *MemoryEnvironment) StartNodes(t *testing.T, tc *TestConfigs, crConfig deployment.CapabilityRegistryConfig) {
require.NotNil(t, m.Chains, "start chains first, chains are empty")
require.NotNil(t, m.DeployedEnv, "start chains and initiate deployed env first before starting nodes")
nodes := memory.NewNodes(t, zapcore.InfoLevel, m.Chains, tc.Nodes, tc.Bootstraps, crConfig)
nodes := memory.NewNodes(t, zapcore.InfoLevel, m.Chains, m.SolChains, tc.Nodes, tc.Bootstraps, crConfig)
ctx := testcontext.Get(t)
lggr := logger.Test(t)
for _, node := range nodes {
Expand All @@ -285,7 +288,7 @@ func (m *MemoryEnvironment) StartNodes(t *testing.T, tc *TestConfigs, crConfig d
require.NoError(t, node.App.Stop())
})
}
m.DeployedEnv.Env = memory.NewMemoryEnvironmentFromChainsNodes(func() context.Context { return ctx }, lggr, m.Chains, nodes)
m.DeployedEnv.Env = memory.NewMemoryEnvironmentFromChainsNodes(func() context.Context { return ctx }, lggr, m.Chains, m.SolChains, nodes)
}

func (m *MemoryEnvironment) MockUSDCAttestationServer(t *testing.T, isUSDCAttestationMissing bool) string {
Expand Down Expand Up @@ -463,7 +466,10 @@ func NewEnvironmentWithJobsAndContracts(t *testing.T, tc *TestConfigs, tEnv Test
require.NotNil(t, state.Chains[e.FeedChainSel].LinkToken)
require.NotNil(t, state.Chains[e.FeedChainSel].Weth9)

tokenConfig := NewTestTokenConfig(state.Chains[e.FeedChainSel].USDFeeds)
tokenConfig := NewTestTokenConfig(
state.Chains[e.FeedChainSel].USDFeeds[LinkSymbol].Address().String(),
state.Chains[e.FeedChainSel].USDFeeds[WethSymbol].Address().String(),
e.FeedChainSel)
var tokenDataProviders []pluginconfig.TokenDataObserverConfig
if tc.IsUSDC {
endpoint := tEnv.MockUSDCAttestationServer(t, tc.IsUSDCAttestationMissing)
Expand Down Expand Up @@ -498,7 +504,7 @@ func NewEnvironmentWithJobsAndContracts(t *testing.T, tc *TestConfigs, tEnv Test
Timelock: state.Chains[chain].Timelock,
CallProxy: state.Chains[chain].CallProxy,
}
tokenInfo := tokenConfig.GetTokenInfo(e.Env.Logger, state.Chains[chain].LinkToken, state.Chains[chain].Weth9)
tokenInfo := tokenConfig.GetTokenInfo(e.Env.Logger, state.Chains[chain].LinkToken.Address().String(), state.Chains[chain].Weth9.Address().String())
ocrParams := DefaultOCRParams(e.FeedChainSel, tokenInfo, tokenDataProviders)
if tc.OCRConfigOverride != nil {
ocrParams = tc.OCRConfigOverride(ocrParams)
Expand Down
24 changes: 14 additions & 10 deletions deployment/ccip/changeset/token_info.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package changeset

import (
chain_selectors "github.com/smartcontractkit/chain-selectors"
"github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3"
"github.com/smartcontractkit/chainlink-ccip/pluginconfig"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/link_token"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/weth9"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/shared/generated/aggregator_v3_interface"
)

type TokenSymbol string
Expand Down Expand Up @@ -38,20 +36,26 @@ func NewTokenConfig() TokenConfig {
}
}

func NewTestTokenConfig(feeds map[TokenSymbol]*aggregator_v3_interface.AggregatorV3Interface) TokenConfig {
func NewTestTokenConfig(linkSymbolAddress, wethSymbolAddress string, chainSelector uint64) TokenConfig {
tc := NewTokenConfig()
family, err := chain_selectors.GetSelectorFamily(chainSelector)
if err != nil {
return tc
}
tc.UpsertTokenInfo(LinkSymbol,
pluginconfig.TokenInfo{
AggregatorAddress: ccipocr3.UnknownEncodedAddress(feeds[LinkSymbol].Address().String()),
AggregatorAddress: ccipocr3.UnknownEncodedAddress(linkSymbolAddress),
Decimals: LinkDecimals,
DeviationPPB: TestDeviationPPB,
ChainFamily: family,
},
)
tc.UpsertTokenInfo(WethSymbol,
pluginconfig.TokenInfo{
AggregatorAddress: ccipocr3.UnknownEncodedAddress(feeds[WethSymbol].Address().String()),
AggregatorAddress: ccipocr3.UnknownEncodedAddress(wethSymbolAddress),
Decimals: WethDecimals,
DeviationPPB: TestDeviationPPB,
ChainFamily: family,
},
)
return tc
Expand All @@ -67,23 +71,23 @@ func (tc *TokenConfig) UpsertTokenInfo(
// GetTokenInfo Adds mapping between dest chain tokens and their respective aggregators on feed chain.
func (tc *TokenConfig) GetTokenInfo(
lggr logger.Logger,
linkToken *link_token.LinkToken,
wethToken *weth9.WETH9,
linkTokenAddress string,
wethTokenAddress string,
) map[ccipocr3.UnknownEncodedAddress]pluginconfig.TokenInfo {
tokenToAggregate := make(map[ccipocr3.UnknownEncodedAddress]pluginconfig.TokenInfo)
if _, ok := tc.TokenSymbolToInfo[LinkSymbol]; !ok {
lggr.Debugw("Link aggregator not found, deploy without mapping link token")
} else {
lggr.Debugw("Mapping LinkToken to Link aggregator")
acc := ccipocr3.UnknownEncodedAddress(linkToken.Address().String())
acc := ccipocr3.UnknownEncodedAddress(linkTokenAddress)
tokenToAggregate[acc] = tc.TokenSymbolToInfo[LinkSymbol]
}

if _, ok := tc.TokenSymbolToInfo[WethSymbol]; !ok {
lggr.Debugw("Weth aggregator not found, deploy without mapping link token")
} else {
lggr.Debugw("Mapping WethToken to Weth aggregator")
acc := ccipocr3.UnknownEncodedAddress(wethToken.Address().String())
acc := ccipocr3.UnknownEncodedAddress(wethTokenAddress)
tokenToAggregate[acc] = tc.TokenSymbolToInfo[WethSymbol]
}

Expand Down
6 changes: 6 additions & 0 deletions deployment/common/changeset/deploy_mcms_with_timelock.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"

"github.com/gagliardetto/solana-go"
"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/common/changeset/internal"
"github.com/smartcontractkit/chainlink/deployment/common/types"
Expand Down Expand Up @@ -37,3 +38,8 @@ func ValidateOwnership(ctx context.Context, mcms bool, deployerKey, timelock com
}
return nil
}

// TODO: SOLANA_CCIP
func ValidateOwnershipSolana(ctx context.Context, mcms bool, deployerKey, timelock, ccipRouter solana.PublicKey) error {
return nil
}
8 changes: 8 additions & 0 deletions deployment/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,11 @@ func ValidateSelectorsInEnvironment(e Environment, chains []uint64) error {
}
return nil
}

func IsSolanaChainFamily(cs uint64) bool {
family, err := chain_selectors.GetSelectorFamily(cs)
if err != nil {
return false
}
return family == chain_selectors.FamilySolana
}

0 comments on commit 57965b9

Please sign in to comment.