From 4d372b49f4d1d44f21bc5411d74bc5660f2027b7 Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Thu, 12 Dec 2024 15:22:10 +0200 Subject: [PATCH 1/8] deployment/ccip/changeset: mcms optional ccip home cses Add MCMS optionality for the rest of the CCIPHome changesets, and organize things a little bit better by moving the AddDON changeset into cs_ccip_home.go out of cs_add_chain.go --- .../ccip/changeset/accept_ownership_test.go | 4 +- deployment/ccip/changeset/cs_add_chain.go | 170 +--------- .../ccip/changeset/cs_add_chain_test.go | 10 +- deployment/ccip/changeset/cs_ccip_home.go | 308 ++++++++++++++++-- .../ccip/changeset/cs_ccip_home_test.go | 198 +++++++++-- 5 files changed, 473 insertions(+), 217 deletions(-) diff --git a/deployment/ccip/changeset/accept_ownership_test.go b/deployment/ccip/changeset/accept_ownership_test.go index 5580b31a85a..937f50c8ce9 100644 --- a/deployment/ccip/changeset/accept_ownership_test.go +++ b/deployment/ccip/changeset/accept_ownership_test.go @@ -21,11 +21,11 @@ func Test_NewAcceptOwnershipChangeset(t *testing.T) { dest := allChains[1] timelockContracts := map[uint64]*commonchangeset.TimelockExecutionContracts{ - source: &commonchangeset.TimelockExecutionContracts{ + source: { Timelock: state.Chains[source].Timelock, CallProxy: state.Chains[source].CallProxy, }, - dest: &commonchangeset.TimelockExecutionContracts{ + dest: { Timelock: state.Chains[dest].Timelock, CallProxy: state.Chains[dest].CallProxy, }, diff --git a/deployment/ccip/changeset/cs_add_chain.go b/deployment/ccip/changeset/cs_add_chain.go index b3d0df04c93..ddb6e61d5ba 100644 --- a/deployment/ccip/changeset/cs_add_chain.go +++ b/deployment/ccip/changeset/cs_add_chain.go @@ -8,18 +8,14 @@ import ( "github.com/smartcontractkit/chainlink-ccip/chainconfig" "github.com/smartcontractkit/chainlink-ccip/pkg/types/ccipocr3" - - "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" - "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "github.com/smartcontractkit/chainlink/deployment" + "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/fee_quoter" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/onramp" ) @@ -136,135 +132,6 @@ func NewChainInboundChangeset( }, nil } -type AddDonAndSetCandidateChangesetConfig struct { - HomeChainSelector uint64 - FeedChainSelector uint64 - NewChainSelector uint64 - PluginType types.PluginType - NodeIDs []string - CCIPOCRParams CCIPOCRParams -} - -func (a AddDonAndSetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { - if a.HomeChainSelector == 0 { - return nil, fmt.Errorf("HomeChainSelector must be set") - } - if a.FeedChainSelector == 0 { - return nil, fmt.Errorf("FeedChainSelector must be set") - } - if a.NewChainSelector == 0 { - return nil, fmt.Errorf("ocr config chain selector must be set") - } - if a.PluginType != types.PluginTypeCCIPCommit && - a.PluginType != types.PluginTypeCCIPExec { - return nil, fmt.Errorf("PluginType must be set to either CCIPCommit or CCIPExec") - } - // TODO: validate token config - if len(a.NodeIDs) == 0 { - return nil, fmt.Errorf("nodeIDs must be set") - } - nodes, err := deployment.NodeInfo(a.NodeIDs, e.Offchain) - if err != nil { - return nil, fmt.Errorf("get node info: %w", err) - } - - // check that chain config is set up for the new chain - chainConfig, err := state.Chains[a.HomeChainSelector].CCIPHome.GetChainConfig(nil, a.NewChainSelector) - if err != nil { - return nil, fmt.Errorf("get all chain configs: %w", err) - } - - // FChain should never be zero if a chain config is set in CCIPHome - if chainConfig.FChain == 0 { - return nil, fmt.Errorf("chain config not set up for new chain %d", a.NewChainSelector) - } - - err = a.CCIPOCRParams.Validate() - if err != nil { - return nil, fmt.Errorf("invalid ccip ocr params: %w", err) - } - - if e.OCRSecrets.IsEmpty() { - return nil, fmt.Errorf("OCR secrets must be set") - } - - return nodes, nil -} - -// AddDonAndSetCandidateChangeset adds new DON for destination to home chain -// and sets the commit plugin config as candidateConfig for the don. -func AddDonAndSetCandidateChangeset( - e deployment.Environment, - cfg AddDonAndSetCandidateChangesetConfig, -) (deployment.ChangesetOutput, error) { - state, err := LoadOnchainState(e) - if err != nil { - return deployment.ChangesetOutput{}, err - } - - nodes, err := cfg.Validate(e, state) - if err != nil { - return deployment.ChangesetOutput{}, fmt.Errorf("%w: %w", deployment.ErrInvalidConfig, err) - } - - newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome( - e.OCRSecrets, - state.Chains[cfg.NewChainSelector].OffRamp, - e.Chains[cfg.NewChainSelector], - nodes.NonBootstraps(), - state.Chains[cfg.HomeChainSelector].RMNHome.Address(), - cfg.CCIPOCRParams.OCRParameters, - cfg.CCIPOCRParams.CommitOffChainConfig, - cfg.CCIPOCRParams.ExecuteOffChainConfig, - ) - if err != nil { - return deployment.ChangesetOutput{}, err - } - latestDon, err := internal.LatestCCIPDON(state.Chains[cfg.HomeChainSelector].CapabilityRegistry) - if err != nil { - return deployment.ChangesetOutput{}, err - } - commitConfig, ok := newDONArgs[cfg.PluginType] - if !ok { - return deployment.ChangesetOutput{}, fmt.Errorf("missing commit plugin in ocr3Configs") - } - donID := latestDon.Id + 1 - addDonOp, err := newDonWithCandidateOp( - donID, commitConfig, - state.Chains[cfg.HomeChainSelector].CapabilityRegistry, - nodes.NonBootstraps(), - ) - if err != nil { - return deployment.ChangesetOutput{}, err - } - - var ( - timelocksPerChain = map[uint64]common.Address{ - cfg.HomeChainSelector: state.Chains[cfg.HomeChainSelector].Timelock.Address(), - } - proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{ - cfg.HomeChainSelector: state.Chains[cfg.HomeChainSelector].ProposerMcm, - } - ) - prop, err := proposalutils.BuildProposalFromBatches( - timelocksPerChain, - proposerMCMSes, - []timelock.BatchChainOperation{{ - ChainIdentifier: mcms.ChainIdentifier(cfg.HomeChainSelector), - Batch: []mcms.Operation{addDonOp}, - }}, - "setCandidate for commit and AddDon on new Chain", - 0, // minDelay - ) - if err != nil { - return deployment.ChangesetOutput{}, fmt.Errorf("failed to build proposal from batch: %w", err) - } - - return deployment.ChangesetOutput{ - Proposals: []timelock.MCMSWithTimelockProposal{*prop}, - }, nil -} - func applyChainConfigUpdatesOp( e deployment.Environment, state CCIPOnChainState, @@ -304,38 +171,3 @@ func applyChainConfigUpdatesOp( Value: big.NewInt(0), }, nil } - -// newDonWithCandidateOp sets the candidate commit config by calling setCandidate on CCIPHome contract through the AddDON call on CapReg contract -// This should be done first before calling any other UpdateDON calls -// This proposes to set up OCR3 config for the commit plugin for the DON -func newDonWithCandidateOp( - donID uint32, - pluginConfig ccip_home.CCIPHomeOCR3Config, - capReg *capabilities_registry.CapabilitiesRegistry, - nodes deployment.Nodes, -) (mcms.Operation, error) { - encodedSetCandidateCall, err := internal.CCIPHomeABI.Pack( - "setCandidate", - donID, - pluginConfig.PluginType, - pluginConfig, - [32]byte{}, - ) - if err != nil { - return mcms.Operation{}, fmt.Errorf("pack set candidate call: %w", err) - } - addDonTx, err := capReg.AddDON(deployment.SimTransactOpts(), nodes.PeerIDs(), []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ - { - CapabilityId: internal.CCIPCapabilityID, - Config: encodedSetCandidateCall, - }, - }, false, false, nodes.DefaultF()) - if err != nil { - return mcms.Operation{}, fmt.Errorf("could not generate add don tx w/ commit config: %w", err) - } - return mcms.Operation{ - To: capReg.Address(), - Data: addDonTx.Data(), - Value: big.NewInt(0), - }, nil -} diff --git a/deployment/ccip/changeset/cs_add_chain_test.go b/deployment/ccip/changeset/cs_add_chain_test.go index b21d7411ce7..3ff1e312b75 100644 --- a/deployment/ccip/changeset/cs_add_chain_test.go +++ b/deployment/ccip/changeset/cs_add_chain_test.go @@ -206,10 +206,10 @@ func TestAddChainInbound(t *testing.T) { }, []commonchangeset.ChangesetApplication{ { Changeset: commonchangeset.WrapChangeSet(AddDonAndSetCandidateChangeset), - Config: AddDonAndSetCandidateChangesetConfig{ + Config: SetCandidateChangesetConfig{ HomeChainSelector: e.HomeChainSel, FeedChainSelector: e.FeedChainSel, - NewChainSelector: newChain, + DONChainSelector: newChain, PluginType: types.PluginTypeCCIPCommit, NodeIDs: nodeIDs, CCIPOCRParams: DefaultOCRParams( @@ -220,11 +220,11 @@ func TestAddChainInbound(t *testing.T) { }, }, { - Changeset: commonchangeset.WrapChangeSet(SetCandidatePluginChangeset), - Config: AddDonAndSetCandidateChangesetConfig{ + Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), + Config: SetCandidateChangesetConfig{ HomeChainSelector: e.HomeChainSel, FeedChainSelector: e.FeedChainSel, - NewChainSelector: newChain, + DONChainSelector: newChain, PluginType: types.PluginTypeCCIPExec, NodeIDs: nodeIDs, CCIPOCRParams: DefaultOCRParams( diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index 202d4216b60..59715fbd373 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -14,23 +14,30 @@ import ( "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" + "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/ccip_home" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" ) var ( + _ deployment.ChangeSet[AddDONAndSetCandidateChangesetConfig] = AddDonAndSetCandidateChangeset _ deployment.ChangeSet[PromoteAllCandidatesChangesetConfig] = PromoteAllCandidatesChangeset - _ deployment.ChangeSet[AddDonAndSetCandidateChangesetConfig] = SetCandidatePluginChangeset + _ deployment.ChangeSet[SetCandidateChangesetConfig] = SetCandidateChangeset ) type PromoteAllCandidatesChangesetConfig struct { HomeChainSelector uint64 + // DONChainSelector is the chain selector of the DON that we want to promote the candidate config of. // Note that each (chain, ccip capability version) pair has a unique DON ID. DONChainSelector uint64 NodeIDs []string - MCMS *MCMSConfig + + // MCMS is optional MCMS configuration, if provided the changeset will generate an MCMS proposal. + // If nil, the changeset will execute the commands directly using the deployer key + // of the provided environment. + MCMS *MCMSConfig } func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { @@ -160,10 +167,114 @@ func PromoteAllCandidatesChangeset( }, nil } -// SetCandidatePluginChangeset calls setCandidate on the CCIPHome for setting up OCR3 exec Plugin config for the new chain. -func SetCandidatePluginChangeset( +// AddDONAndSetCandidateChangesetConfig is a separate config struct +// because the validation is slightly different from SetCandidateChangesetConfig. +// In particular, we check to make sure we don't already have a DON for the chain. +type AddDONAndSetCandidateChangesetConfig struct { + SetCandidateChangesetConfig +} + +func (a AddDONAndSetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { + nodes, err := a.SetCandidateChangesetConfig.Validate(e, state) + if err != nil { + return nil, err + } + + // check if a DON already exists for this chain + donID, err := internal.DonIDForChain( + state.Chains[a.HomeChainSelector].CapabilityRegistry, + state.Chains[a.HomeChainSelector].CCIPHome, + a.DONChainSelector, + ) + if err != nil { + return nil, fmt.Errorf("fetch don id for chain: %w", err) + } + if donID != 0 { + return nil, fmt.Errorf("don already exists in CR for chain %d, it has id %d", a.DONChainSelector, donID) + } + + return nodes, nil +} + +type SetCandidateChangesetConfig struct { + HomeChainSelector uint64 + FeedChainSelector uint64 + + // DONChainSelector is the chain selector of the chain where the DON will be added. + DONChainSelector uint64 + + PluginType types.PluginType + NodeIDs []string + CCIPOCRParams CCIPOCRParams + + // MCMS is optional MCMS configuration, if provided the changeset will generate an MCMS proposal. + // If nil, the changeset will execute the commands directly using the deployer key + // of the provided environment. + MCMS *MCMSConfig +} + +func (s SetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { + if err := deployment.IsValidChainSelector(s.HomeChainSelector); err != nil { + return nil, fmt.Errorf("home chain selector invalid: %w", err) + } + if err := deployment.IsValidChainSelector(s.FeedChainSelector); err != nil { + return nil, fmt.Errorf("feed chain selector invalid: %w", err) + } + if err := deployment.IsValidChainSelector(s.DONChainSelector); err != nil { + return nil, fmt.Errorf("don chain selector invalid: %w", err) + } + if len(s.NodeIDs) == 0 { + return nil, fmt.Errorf("nodeIDs must be set") + } + if state.Chains[s.HomeChainSelector].CCIPHome == nil { + return nil, fmt.Errorf("CCIPHome contract does not exist") + } + if state.Chains[s.HomeChainSelector].CapabilityRegistry == nil { + return nil, fmt.Errorf("CapabilityRegistry contract does not exist") + } + if s.PluginType != types.PluginTypeCCIPCommit && + s.PluginType != types.PluginTypeCCIPExec { + return nil, fmt.Errorf("PluginType must be set to either CCIPCommit or CCIPExec") + } + + nodes, err := deployment.NodeInfo(s.NodeIDs, e.Offchain) + if err != nil { + return nil, fmt.Errorf("get node info: %w", err) + } + + // TODO: validate token config + + // check that chain config is set up for the new chain + chainConfig, err := state.Chains[s.HomeChainSelector].CCIPHome.GetChainConfig(nil, s.DONChainSelector) + if err != nil { + return nil, fmt.Errorf("get all chain configs: %w", err) + } + + // FChain should never be zero if a chain config is set in CCIPHome + if chainConfig.FChain == 0 { + return nil, fmt.Errorf("chain config not set up for new chain %d", s.DONChainSelector) + } + + err = s.CCIPOCRParams.Validate() + if err != nil { + return nil, fmt.Errorf("invalid ccip ocr params: %w", err) + } + + if e.OCRSecrets.IsEmpty() { + return nil, fmt.Errorf("OCR secrets must be set") + } + + return nodes, nil +} + +// AddDonAndSetCandidateChangeset adds new DON for destination to home chain +// and sets the plugin config as candidateConfig for the don. +// Note that these operations must be done together because the createDON call +// in the capability registry calls the capability config contract, so we must +// provide suitable calldata for CCIPHome. +func AddDonAndSetCandidateChangeset( e deployment.Environment, - cfg AddDonAndSetCandidateChangesetConfig, + cfg AddDONAndSetCandidateChangesetConfig, ) (deployment.ChangesetOutput, error) { state, err := LoadOnchainState(e) if err != nil { @@ -175,10 +286,154 @@ func SetCandidatePluginChangeset( return deployment.ChangesetOutput{}, fmt.Errorf("%w: %w", deployment.ErrInvalidConfig, err) } + txOpts := e.Chains[cfg.HomeChainSelector].DeployerKey + if cfg.MCMS != nil { + txOpts = deployment.SimTransactOpts() + } + newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome( e.OCRSecrets, - state.Chains[cfg.NewChainSelector].OffRamp, - e.Chains[cfg.NewChainSelector], + state.Chains[cfg.DONChainSelector].OffRamp, + e.Chains[cfg.DONChainSelector], + nodes.NonBootstraps(), + state.Chains[cfg.HomeChainSelector].RMNHome.Address(), + cfg.CCIPOCRParams.OCRParameters, + cfg.CCIPOCRParams.CommitOffChainConfig, + cfg.CCIPOCRParams.ExecuteOffChainConfig, + ) + if err != nil { + return deployment.ChangesetOutput{}, err + } + + latestDon, err := internal.LatestCCIPDON(state.Chains[cfg.HomeChainSelector].CapabilityRegistry) + if err != nil { + return deployment.ChangesetOutput{}, err + } + + pluginOCR3Config, ok := newDONArgs[cfg.PluginType] + if !ok { + return deployment.ChangesetOutput{}, fmt.Errorf("missing commit plugin in ocr3Configs") + } + + expectedDonID := latestDon.Id + 1 + addDonOp, err := newDonWithCandidateOp( + txOpts, + e.Chains[cfg.HomeChainSelector], + expectedDonID, + pluginOCR3Config, + state.Chains[cfg.HomeChainSelector].CapabilityRegistry, + nodes.NonBootstraps(), + cfg.MCMS != nil, + ) + if err != nil { + return deployment.ChangesetOutput{}, err + } + if cfg.MCMS == nil { + return deployment.ChangesetOutput{}, nil + } + + prop, err := proposalutils.BuildProposalFromBatches( + map[uint64]common.Address{ + cfg.HomeChainSelector: state.Chains[cfg.HomeChainSelector].Timelock.Address(), + }, + map[uint64]*gethwrappers.ManyChainMultiSig{ + cfg.HomeChainSelector: state.Chains[cfg.HomeChainSelector].ProposerMcm, + }, + []timelock.BatchChainOperation{{ + ChainIdentifier: mcms.ChainIdentifier(cfg.HomeChainSelector), + Batch: []mcms.Operation{addDonOp}, + }}, + fmt.Sprintf("addDON on new Chain && setCandidate for plugin %s", cfg.PluginType.String()), + cfg.MCMS.MinDelay, + ) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("failed to build proposal from batch: %w", err) + } + + return deployment.ChangesetOutput{ + Proposals: []timelock.MCMSWithTimelockProposal{*prop}, + }, nil +} + +// newDonWithCandidateOp sets the candidate commit config by calling setCandidate on CCIPHome contract through the AddDON call on CapReg contract +// This should be done first before calling any other UpdateDON calls +// This proposes to set up OCR3 config for the commit plugin for the DON +func newDonWithCandidateOp( + txOpts *bind.TransactOpts, + homeChain deployment.Chain, + donID uint32, + pluginConfig ccip_home.CCIPHomeOCR3Config, + capReg *capabilities_registry.CapabilitiesRegistry, + nodes deployment.Nodes, + mcmsEnabled bool, +) (mcms.Operation, error) { + encodedSetCandidateCall, err := internal.CCIPHomeABI.Pack( + "setCandidate", + donID, + pluginConfig.PluginType, + pluginConfig, + [32]byte{}, + ) + if err != nil { + return mcms.Operation{}, fmt.Errorf("pack set candidate call: %w", err) + } + + addDonTx, err := capReg.AddDON( + txOpts, + nodes.PeerIDs(), + []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ + { + CapabilityId: internal.CCIPCapabilityID, + Config: encodedSetCandidateCall, + }, + }, + false, // isPublic + false, // acceptsWorkflows + nodes.DefaultF(), + ) + if err != nil { + return mcms.Operation{}, fmt.Errorf("could not generate add don tx w/ commit config: %w", err) + } + if !mcmsEnabled { + _, err = deployment.ConfirmIfNoError(homeChain, addDonTx, err) + if err != nil { + return mcms.Operation{}, fmt.Errorf("error confirming addDon call: %w", err) + } + } + + return mcms.Operation{ + To: capReg.Address(), + Data: addDonTx.Data(), + Value: big.NewInt(0), + }, nil +} + +// SetCandidateChangeset generates a proposal to call setCandidate on the CCIPHome through the capability registry. +// If the MCMS is enabled, it will generate an MCMS proposal. +// If the MCMS is disabled, it will execute the txes directly using the deployer key. +func SetCandidateChangeset( + e deployment.Environment, + cfg SetCandidateChangesetConfig, +) (deployment.ChangesetOutput, error) { + state, err := LoadOnchainState(e) + if err != nil { + return deployment.ChangesetOutput{}, err + } + + nodes, err := cfg.Validate(e, state) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("%w: %w", deployment.ErrInvalidConfig, err) + } + + txOpts := e.Chains[cfg.HomeChainSelector].DeployerKey + if cfg.MCMS != nil { + txOpts = deployment.SimTransactOpts() + } + + newDONArgs, err := internal.BuildOCR3ConfigForCCIPHome( + e.OCRSecrets, + state.Chains[cfg.DONChainSelector].OffRamp, + e.Chains[cfg.DONChainSelector], nodes.NonBootstraps(), state.Chains[cfg.HomeChainSelector].RMNHome.Address(), cfg.CCIPOCRParams.OCRParameters, @@ -195,33 +450,36 @@ func SetCandidatePluginChangeset( } setCandidateMCMSOps, err := setCandidateOnExistingDon( + txOpts, + e.Chains[cfg.HomeChainSelector], config, state.Chains[cfg.HomeChainSelector].CapabilityRegistry, state.Chains[cfg.HomeChainSelector].CCIPHome, - cfg.NewChainSelector, + cfg.DONChainSelector, nodes.NonBootstraps(), + cfg.MCMS != nil, ) if err != nil { return deployment.ChangesetOutput{}, err } - var ( - timelocksPerChain = map[uint64]common.Address{ + if cfg.MCMS == nil { + return deployment.ChangesetOutput{}, nil + } + + prop, err := proposalutils.BuildProposalFromBatches( + map[uint64]common.Address{ cfg.HomeChainSelector: state.Chains[cfg.HomeChainSelector].Timelock.Address(), - } - proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{ + }, + map[uint64]*gethwrappers.ManyChainMultiSig{ cfg.HomeChainSelector: state.Chains[cfg.HomeChainSelector].ProposerMcm, - } - ) - prop, err := proposalutils.BuildProposalFromBatches( - timelocksPerChain, - proposerMCMSes, + }, []timelock.BatchChainOperation{{ ChainIdentifier: mcms.ChainIdentifier(cfg.HomeChainSelector), Batch: setCandidateMCMSOps, }}, fmt.Sprintf("SetCandidate for %s plugin", cfg.PluginType.String()), - 0, // minDelay + cfg.MCMS.MinDelay, ) if err != nil { return deployment.ChangesetOutput{}, err @@ -236,11 +494,14 @@ func SetCandidatePluginChangeset( // setCandidateOnExistingDon calls setCandidate on CCIPHome contract through the UpdateDON call on CapReg contract // This proposes to set up OCR3 config for the provided plugin for the DON func setCandidateOnExistingDon( + txOpts *bind.TransactOpts, + homeChain deployment.Chain, pluginConfig ccip_home.CCIPHomeOCR3Config, capReg *capabilities_registry.CapabilitiesRegistry, ccipHome *ccip_home.CCIPHome, chainSelector uint64, nodes deployment.Nodes, + mcmsEnabled bool, ) ([]mcms.Operation, error) { // fetch DON ID for the chain donID, err := internal.DonIDForChain(capReg, ccipHome, chainSelector) @@ -251,7 +512,8 @@ func setCandidateOnExistingDon( return nil, fmt.Errorf("don doesn't exist in CR for chain %d", chainSelector) } - fmt.Printf("donID: %d", donID) + fmt.Printf("donID for chain %d: %d", chainSelector, donID) + encodedSetCandidateCall, err := internal.CCIPHomeABI.Pack( "setCandidate", donID, @@ -265,7 +527,7 @@ func setCandidateOnExistingDon( // set candidate call updateDonTx, err := capReg.UpdateDON( - deployment.SimTransactOpts(), + txOpts, donID, nodes.PeerIDs(), []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ @@ -280,6 +542,12 @@ func setCandidateOnExistingDon( if err != nil { return nil, fmt.Errorf("update don w/ exec config: %w", err) } + if !mcmsEnabled { + _, err = deployment.ConfirmIfNoError(homeChain, updateDonTx, err) + if err != nil { + return nil, fmt.Errorf("error confirming updateDon call: %w", err) + } + } return []mcms.Operation{{ To: capReg.Address(), diff --git a/deployment/ccip/changeset/cs_ccip_home_test.go b/deployment/ccip/changeset/cs_ccip_home_test.go index 92784551957..018a1e7c036 100644 --- a/deployment/ccip/changeset/cs_ccip_home_test.go +++ b/deployment/ccip/changeset/cs_ccip_home_test.go @@ -16,6 +16,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" + "github.com/smartcontractkit/chainlink/v2/core/logger" "github.com/smartcontractkit/chainlink/deployment" @@ -164,11 +165,14 @@ func TestActiveCandidate(t *testing.T) { } ) setCommitCandidateOp, err := setCandidateOnExistingDon( + deployment.SimTransactOpts(), + tenv.Env.Chains[tenv.HomeChainSel], ocr3ConfigMap[cctypes.PluginTypeCCIPCommit], state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps(), + true, ) require.NoError(t, err) setCommitCandidateProposal, err := proposalutils.BuildProposalFromBatches(timelocksPerChain, proposerMCMSes, []timelock.BatchChainOperation{{ @@ -184,11 +188,14 @@ func TestActiveCandidate(t *testing.T) { // create the op for the commit plugin as well setExecCandidateOp, err := setCandidateOnExistingDon( + deployment.SimTransactOpts(), + tenv.Env.Chains[tenv.HomeChainSel], ocr3ConfigMap[cctypes.PluginTypeCCIPExec], state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome, tenv.FeedChainSel, nodes.NonBootstraps(), + true, ) require.NoError(t, err) @@ -298,27 +305,7 @@ func Test_PromoteCandidate(t *testing.T) { if tc.mcmsEnabled { // Transfer ownership to timelock so that we can promote the zero digest later down the line. - _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{ - source: { - Timelock: state.Chains[source].Timelock, - CallProxy: state.Chains[source].CallProxy, - }, - dest: { - Timelock: state.Chains[dest].Timelock, - CallProxy: state.Chains[dest].CallProxy, - }, - tenv.HomeChainSel: { - Timelock: state.Chains[tenv.HomeChainSel].Timelock, - CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, - }, - }, []commonchangeset.ChangesetApplication{ - { - Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock), - Config: genTestTransferOwnershipConfig(tenv, allChains, state), - }, - }) - require.NoError(t, err) - assertTimelockOwnership(t, tenv, allChains, state) + transferToTimelock(t, tenv, state, source, dest) } var ( @@ -378,3 +365,172 @@ func Test_PromoteCandidate(t *testing.T) { }) } } + +func Test_AddDonSetCandidate(t *testing.T) { + for _, tc := range []struct { + name string + mcmsEnabled bool + }{ + { + name: "MCMS enabled", + mcmsEnabled: true, + }, + { + name: "MCMS disabled", + mcmsEnabled: false, + }, + } { + t.Run(tc.name, func(t *testing.T) { + }) + } +} + +func Test_SetCandidate(t *testing.T) { + for _, tc := range []struct { + name string + mcmsEnabled bool + }{ + { + name: "MCMS enabled", + mcmsEnabled: true, + }, + { + name: "MCMS disabled", + mcmsEnabled: false, + }, + } { + t.Run(tc.name, func(t *testing.T) { + ctx := testcontext.Get(t) + tenv := NewMemoryEnvironment(t, + WithChains(2), + WithNodes(4)) + state, err := LoadOnchainState(tenv.Env) + require.NoError(t, err) + + // Deploy to all chains. + allChains := maps.Keys(tenv.Env.Chains) + source := allChains[0] + dest := allChains[1] + + nodes, err := deployment.NodeInfo(tenv.Env.NodeIDs, tenv.Env.Offchain) + require.NoError(t, err) + + var nodeIDs []string + for _, node := range nodes { + nodeIDs = append(nodeIDs, node.NodeID) + } + + if tc.mcmsEnabled { + // Transfer ownership to timelock so that we can promote the zero digest later down the line. + transferToTimelock(t, tenv, state, source, dest) + } + + var ( + capReg = state.Chains[tenv.HomeChainSel].CapabilityRegistry + ccipHome = state.Chains[tenv.HomeChainSel].CCIPHome + ) + donID, err := internal.DonIDForChain(capReg, ccipHome, dest) + require.NoError(t, err) + require.NotEqual(t, uint32(0), donID) + candidateDigestCommitBefore, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPCommit)) + require.NoError(t, err) + require.Equal(t, [32]byte{}, candidateDigestCommitBefore) + candidateDigestExecBefore, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPExec)) + require.NoError(t, err) + require.Equal(t, [32]byte{}, candidateDigestExecBefore) + + var mcmsConfig *MCMSConfig + if tc.mcmsEnabled { + mcmsConfig = &MCMSConfig{ + MinDelay: 0, + } + } + tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds) + _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{ + tenv.HomeChainSel: { + Timelock: state.Chains[tenv.HomeChainSel].Timelock, + CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, + }, + }, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), + Config: SetCandidateChangesetConfig{ + HomeChainSelector: tenv.HomeChainSel, + FeedChainSelector: tenv.FeedChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPCommit, + NodeIDs: nodeIDs, + CCIPOCRParams: DefaultOCRParams( + tenv.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), + nil, + ), + MCMS: mcmsConfig, + }, + }, + { + Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), + Config: SetCandidateChangesetConfig{ + HomeChainSelector: tenv.HomeChainSel, + FeedChainSelector: tenv.FeedChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPExec, + NodeIDs: nodeIDs, + CCIPOCRParams: DefaultOCRParams( + tenv.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), + nil, + ), + MCMS: mcmsConfig, + }, + }, + }) + require.NoError(t, err) + + // after setting a new candidate on both plugins, the candidate config digest + // should be nonzero. + candidateDigestCommitAfter, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPCommit)) + require.NoError(t, err) + require.NotEqual(t, [32]byte{}, candidateDigestCommitAfter) + require.NotEqual(t, candidateDigestCommitBefore, candidateDigestCommitAfter) + + candidateDigestExecAfter, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPExec)) + require.NoError(t, err) + require.NotEqual(t, [32]byte{}, candidateDigestExecAfter) + require.NotEqual(t, candidateDigestExecBefore, candidateDigestExecAfter) + }) + } +} + +func transferToTimelock(t *testing.T, tenv DeployedEnv, state CCIPOnChainState, source, dest uint64) { + // Transfer ownership to timelock so that we can promote the zero digest later down the line. + _, err := commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{ + source: { + Timelock: state.Chains[source].Timelock, + CallProxy: state.Chains[source].CallProxy, + }, + dest: { + Timelock: state.Chains[dest].Timelock, + CallProxy: state.Chains[dest].CallProxy, + }, + tenv.HomeChainSel: { + Timelock: state.Chains[tenv.HomeChainSel].Timelock, + CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, + }, + }, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock), + Config: genTestTransferOwnershipConfig(tenv, []uint64{source, dest}, state), + }, + }) + require.NoError(t, err) + assertTimelockOwnership(t, tenv, []uint64{source, dest}, state) +} From 9492c9b032fa43faa9b97b3695edc1b8fa79030c Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Thu, 12 Dec 2024 17:12:07 +0200 Subject: [PATCH 2/8] fixes --- .../ccip/changeset/cs_add_chain_test.go | 31 ++++++++++++------- deployment/ccip/changeset/cs_ccip_home.go | 10 +++--- .../ccip/changeset/cs_ccip_home_test.go | 26 ++++------------ .../ccip/changeset/cs_initial_add_chain.go | 2 +- 4 files changed, 32 insertions(+), 37 deletions(-) diff --git a/deployment/ccip/changeset/cs_add_chain_test.go b/deployment/ccip/changeset/cs_add_chain_test.go index 3ff1e312b75..f89c987c336 100644 --- a/deployment/ccip/changeset/cs_add_chain_test.go +++ b/deployment/ccip/changeset/cs_add_chain_test.go @@ -206,17 +206,22 @@ func TestAddChainInbound(t *testing.T) { }, []commonchangeset.ChangesetApplication{ { Changeset: commonchangeset.WrapChangeSet(AddDonAndSetCandidateChangeset), - Config: SetCandidateChangesetConfig{ - HomeChainSelector: e.HomeChainSel, - FeedChainSelector: e.FeedChainSel, - DONChainSelector: newChain, - PluginType: types.PluginTypeCCIPCommit, - NodeIDs: nodeIDs, - CCIPOCRParams: DefaultOCRParams( - e.FeedChainSel, - tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[newChain].LinkToken, state.Chains[newChain].Weth9), - nil, - ), + Config: AddDonAndSetCandidateChangesetConfig{ + SetCandidateChangesetConfig: SetCandidateChangesetConfig{ + HomeChainSelector: e.HomeChainSel, + FeedChainSelector: e.FeedChainSel, + DONChainSelector: newChain, + PluginType: types.PluginTypeCCIPCommit, + NodeIDs: nodeIDs, + CCIPOCRParams: DefaultOCRParams( + e.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[newChain].LinkToken, state.Chains[newChain].Weth9), + nil, + ), + MCMS: &MCMSConfig{ + MinDelay: 0, + }, + }, }, }, { @@ -232,6 +237,9 @@ func TestAddChainInbound(t *testing.T) { tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[newChain].LinkToken, state.Chains[newChain].Weth9), nil, ), + MCMS: &MCMSConfig{ + MinDelay: 0, + }, }, }, { @@ -246,6 +254,7 @@ func TestAddChainInbound(t *testing.T) { }, }, }) + require.NoError(t, err) // verify if the configs are updated require.NoError(t, ValidateCCIPHomeConfigSetUp( diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index 59715fbd373..6bba629ab3a 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -21,7 +21,7 @@ import ( ) var ( - _ deployment.ChangeSet[AddDONAndSetCandidateChangesetConfig] = AddDonAndSetCandidateChangeset + _ deployment.ChangeSet[AddDonAndSetCandidateChangesetConfig] = AddDonAndSetCandidateChangeset _ deployment.ChangeSet[PromoteAllCandidatesChangesetConfig] = PromoteAllCandidatesChangeset _ deployment.ChangeSet[SetCandidateChangesetConfig] = SetCandidateChangeset ) @@ -167,14 +167,14 @@ func PromoteAllCandidatesChangeset( }, nil } -// AddDONAndSetCandidateChangesetConfig is a separate config struct +// AddDonAndSetCandidateChangesetConfig is a separate config struct // because the validation is slightly different from SetCandidateChangesetConfig. // In particular, we check to make sure we don't already have a DON for the chain. -type AddDONAndSetCandidateChangesetConfig struct { +type AddDonAndSetCandidateChangesetConfig struct { SetCandidateChangesetConfig } -func (a AddDONAndSetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { +func (a AddDonAndSetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { nodes, err := a.SetCandidateChangesetConfig.Validate(e, state) if err != nil { return nil, err @@ -274,7 +274,7 @@ func (s SetCandidateChangesetConfig) Validate(e deployment.Environment, state CC // provide suitable calldata for CCIPHome. func AddDonAndSetCandidateChangeset( e deployment.Environment, - cfg AddDONAndSetCandidateChangesetConfig, + cfg AddDonAndSetCandidateChangesetConfig, ) (deployment.ChangesetOutput, error) { state, err := LoadOnchainState(e) if err != nil { diff --git a/deployment/ccip/changeset/cs_ccip_home_test.go b/deployment/ccip/changeset/cs_ccip_home_test.go index 018a1e7c036..c17d4e8fbe9 100644 --- a/deployment/ccip/changeset/cs_ccip_home_test.go +++ b/deployment/ccip/changeset/cs_ccip_home_test.go @@ -366,25 +366,6 @@ func Test_PromoteCandidate(t *testing.T) { } } -func Test_AddDonSetCandidate(t *testing.T) { - for _, tc := range []struct { - name string - mcmsEnabled bool - }{ - { - name: "MCMS enabled", - mcmsEnabled: true, - }, - { - name: "MCMS disabled", - mcmsEnabled: false, - }, - } { - t.Run(tc.name, func(t *testing.T) { - }) - } -} - func Test_SetCandidate(t *testing.T) { for _, tc := range []struct { name string @@ -510,7 +491,12 @@ func Test_SetCandidate(t *testing.T) { } } -func transferToTimelock(t *testing.T, tenv DeployedEnv, state CCIPOnChainState, source, dest uint64) { +func transferToTimelock( + t *testing.T, + tenv DeployedEnv, + state CCIPOnChainState, + source, + dest uint64) { // Transfer ownership to timelock so that we can promote the zero digest later down the line. _, err := commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{ source: { diff --git a/deployment/ccip/changeset/cs_initial_add_chain.go b/deployment/ccip/changeset/cs_initial_add_chain.go index 5ba648d74b5..4f8b2ac2722 100644 --- a/deployment/ccip/changeset/cs_initial_add_chain.go +++ b/deployment/ccip/changeset/cs_initial_add_chain.go @@ -483,7 +483,7 @@ func ValidateCCIPHomeConfigSetUp( return fmt.Errorf("fetch don id for chain: %w", err) } if donID == 0 { - return fmt.Errorf("don id for chain(%d) does not exist", chainSel) + return fmt.Errorf("don id for chain (%d) does not exist", chainSel) } // final sanity checks on configs. From f119740ce76f87ee358c6b8622a3e41c407eca4c Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Thu, 12 Dec 2024 18:38:07 +0200 Subject: [PATCH 3/8] deployment/ccip/changeset: add RevokeCandidate cs Add the revoke candidate changeset for CCIPHome w/ optional MCMS, along with a basic unit test. --- deployment/ccip/changeset/cs_ccip_home.go | 188 +++++++++++++++++- .../ccip/changeset/cs_ccip_home_test.go | 168 ++++++++++++++++ 2 files changed, 355 insertions(+), 1 deletion(-) diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index 6bba629ab3a..6d63346b373 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -540,7 +540,7 @@ func setCandidateOnExistingDon( nodes.DefaultF(), ) if err != nil { - return nil, fmt.Errorf("update don w/ exec config: %w", err) + return nil, fmt.Errorf("update don w/ setCandidate call: %w", err) } if !mcmsEnabled { _, err = deployment.ConfirmIfNoError(homeChain, updateDonTx, err) @@ -647,3 +647,189 @@ func promoteAllCandidatesForChainOps( return mcmsOps, nil } + +type RevokeCandidateChangesetConfig struct { + HomeChainSelector uint64 + + // DONChainSelector is the chain selector whose candidate config we want to revoke. + DONChainSelector uint64 + NodeIDs []string + PluginType types.PluginType + + // MCMS is optional MCMS configuration, if provided the changeset will generate an MCMS proposal. + // If nil, the changeset will execute the commands directly using the deployer key + // of the provided environment. + MCMS *MCMSConfig +} + +func (r RevokeCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { + if err := deployment.IsValidChainSelector(r.HomeChainSelector); err != nil { + return nil, fmt.Errorf("home chain selector invalid: %w", err) + } + if err := deployment.IsValidChainSelector(r.DONChainSelector); err != nil { + return nil, fmt.Errorf("don chain selector invalid: %w", err) + } + if len(r.NodeIDs) == 0 { + return nil, fmt.Errorf("NodeIDs must be set") + } + if state.Chains[r.HomeChainSelector].CCIPHome == nil { + return nil, fmt.Errorf("CCIPHome contract does not exist") + } + if state.Chains[r.HomeChainSelector].CapabilityRegistry == nil { + return nil, fmt.Errorf("CapabilityRegistry contract does not exist") + } + + nodes, err := deployment.NodeInfo(r.NodeIDs, e.Offchain) + if err != nil { + return nil, fmt.Errorf("fetch node info: %w", err) + } + + // check that the don exists for this chain + donID, err := internal.DonIDForChain( + state.Chains[r.HomeChainSelector].CapabilityRegistry, + state.Chains[r.HomeChainSelector].CCIPHome, + r.DONChainSelector, + ) + if err != nil { + return nil, fmt.Errorf("fetch don id for chain: %w", err) + } + if donID == 0 { + return nil, fmt.Errorf("don doesn't exist in CR for chain %d", r.DONChainSelector) + } + + // check that candidate digest is not zero - this is enforced onchain. + candidateDigest, err := state.Chains[r.HomeChainSelector].CCIPHome.GetCandidateDigest(nil, donID, uint8(r.PluginType)) + if err != nil { + return nil, fmt.Errorf("fetching candidate digest from cciphome: %w", err) + } + if candidateDigest == [32]byte{} { + return nil, fmt.Errorf("candidate config digest is zero, can't revoke it") + } + + return nodes, nil +} + +func RevokeCandidateChangeset(e deployment.Environment, cfg RevokeCandidateChangesetConfig) (deployment.ChangesetOutput, error) { + state, err := LoadOnchainState(e) + if err != nil { + return deployment.ChangesetOutput{}, err + } + + nodes, err := cfg.Validate(e, state) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("%w: %w", deployment.ErrInvalidConfig, err) + } + + txOpts := e.Chains[cfg.HomeChainSelector].DeployerKey + if cfg.MCMS != nil { + txOpts = deployment.SimTransactOpts() + } + + homeChain := e.Chains[cfg.HomeChainSelector] + ops, err := revokeCandidateOps( + txOpts, + homeChain, + state.Chains[cfg.HomeChainSelector].CapabilityRegistry, + state.Chains[cfg.HomeChainSelector].CCIPHome, + cfg.DONChainSelector, + uint8(cfg.PluginType), + nodes.NonBootstraps(), + cfg.MCMS != nil, + ) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("revoke candidate ops: %w", err) + } + if cfg.MCMS == nil { + return deployment.ChangesetOutput{}, nil + } + + prop, err := proposalutils.BuildProposalFromBatches( + map[uint64]common.Address{ + cfg.HomeChainSelector: state.Chains[cfg.HomeChainSelector].Timelock.Address(), + }, + map[uint64]*gethwrappers.ManyChainMultiSig{ + cfg.HomeChainSelector: state.Chains[cfg.HomeChainSelector].ProposerMcm, + }, + []timelock.BatchChainOperation{{ + ChainIdentifier: mcms.ChainIdentifier(cfg.HomeChainSelector), + Batch: ops, + }}, + fmt.Sprintf("revokeCandidate for don %d", cfg.DONChainSelector), + cfg.MCMS.MinDelay, + ) + if err != nil { + return deployment.ChangesetOutput{}, err + } + + return deployment.ChangesetOutput{ + Proposals: []timelock.MCMSWithTimelockProposal{ + *prop, + }, + }, nil +} + +func revokeCandidateOps( + txOpts *bind.TransactOpts, + homeChain deployment.Chain, + capReg *capabilities_registry.CapabilitiesRegistry, + ccipHome *ccip_home.CCIPHome, + chainSelector uint64, + pluginType uint8, + nodes deployment.Nodes, + mcmsEnabled bool, +) ([]mcms.Operation, error) { + // fetch DON ID for the chain + donID, err := internal.DonIDForChain(capReg, ccipHome, chainSelector) + if err != nil { + return nil, fmt.Errorf("fetch don id for chain: %w", err) + } + if donID == 0 { + return nil, fmt.Errorf("don doesn't exist in CR for chain %d", chainSelector) + } + + candidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, pluginType) + if err != nil { + return nil, fmt.Errorf("fetching candidate digest from cciphome: %w", err) + } + + encodedRevokeCandidateCall, err := internal.CCIPHomeABI.Pack( + "revokeCandidate", + donID, + pluginType, + candidateDigest, + ) + if err != nil { + return nil, fmt.Errorf("pack set candidate call: %w", err) + } + + fmt.Printf("encoded revoke candidate call: %x\n", encodedRevokeCandidateCall) + + updateDonTx, err := capReg.UpdateDON( + txOpts, + donID, + nodes.PeerIDs(), + []capabilities_registry.CapabilitiesRegistryCapabilityConfiguration{ + { + CapabilityId: internal.CCIPCapabilityID, + Config: encodedRevokeCandidateCall, + }, + }, + false, // isPublic + nodes.DefaultF(), + ) + if err != nil { + return nil, fmt.Errorf("update don w/ revokeCandidate call: %w", deployment.MaybeDataErr(err)) + } + if !mcmsEnabled { + _, err = deployment.ConfirmIfNoError(homeChain, updateDonTx, err) + if err != nil { + return nil, fmt.Errorf("error confirming updateDon call: %w", err) + } + } + + return []mcms.Operation{{ + To: capReg.Address(), + Data: updateDonTx.Data(), + Value: big.NewInt(0), + }}, nil +} diff --git a/deployment/ccip/changeset/cs_ccip_home_test.go b/deployment/ccip/changeset/cs_ccip_home_test.go index c17d4e8fbe9..fc4c9002eda 100644 --- a/deployment/ccip/changeset/cs_ccip_home_test.go +++ b/deployment/ccip/changeset/cs_ccip_home_test.go @@ -491,6 +491,174 @@ func Test_SetCandidate(t *testing.T) { } } +func Test_RevokeCandidate(t *testing.T) { + for _, tc := range []struct { + name string + mcmsEnabled bool + }{ + { + name: "MCMS enabled", + mcmsEnabled: true, + }, + { + name: "MCMS disabled", + mcmsEnabled: false, + }, + } { + t.Run(tc.name, func(t *testing.T) { + ctx := testcontext.Get(t) + tenv := NewMemoryEnvironment(t, + WithChains(2), + WithNodes(4)) + state, err := LoadOnchainState(tenv.Env) + require.NoError(t, err) + + // Deploy to all chains. + allChains := maps.Keys(tenv.Env.Chains) + source := allChains[0] + dest := allChains[1] + + nodes, err := deployment.NodeInfo(tenv.Env.NodeIDs, tenv.Env.Offchain) + require.NoError(t, err) + + var nodeIDs []string + for _, node := range nodes { + nodeIDs = append(nodeIDs, node.NodeID) + } + + if tc.mcmsEnabled { + // Transfer ownership to timelock so that we can promote the zero digest later down the line. + transferToTimelock(t, tenv, state, source, dest) + } + + var ( + capReg = state.Chains[tenv.HomeChainSel].CapabilityRegistry + ccipHome = state.Chains[tenv.HomeChainSel].CCIPHome + ) + donID, err := internal.DonIDForChain(capReg, ccipHome, dest) + require.NoError(t, err) + require.NotEqual(t, uint32(0), donID) + candidateDigestCommitBefore, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPCommit)) + require.NoError(t, err) + require.Equal(t, [32]byte{}, candidateDigestCommitBefore) + candidateDigestExecBefore, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPExec)) + require.NoError(t, err) + require.Equal(t, [32]byte{}, candidateDigestExecBefore) + + var mcmsConfig *MCMSConfig + if tc.mcmsEnabled { + mcmsConfig = &MCMSConfig{ + MinDelay: 0, + } + } + tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds) + _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{ + tenv.HomeChainSel: { + Timelock: state.Chains[tenv.HomeChainSel].Timelock, + CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, + }, + }, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), + Config: SetCandidateChangesetConfig{ + HomeChainSelector: tenv.HomeChainSel, + FeedChainSelector: tenv.FeedChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPCommit, + NodeIDs: nodeIDs, + CCIPOCRParams: DefaultOCRParams( + tenv.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), + nil, + ), + MCMS: mcmsConfig, + }, + }, + { + Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), + Config: SetCandidateChangesetConfig{ + HomeChainSelector: tenv.HomeChainSel, + FeedChainSelector: tenv.FeedChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPExec, + NodeIDs: nodeIDs, + CCIPOCRParams: DefaultOCRParams( + tenv.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), + nil, + ), + MCMS: mcmsConfig, + }, + }, + }) + require.NoError(t, err) + + // after setting a new candidate on both plugins, the candidate config digest + // should be nonzero. + candidateDigestCommitAfter, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPCommit)) + require.NoError(t, err) + require.NotEqual(t, [32]byte{}, candidateDigestCommitAfter) + require.NotEqual(t, candidateDigestCommitBefore, candidateDigestCommitAfter) + + candidateDigestExecAfter, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPExec)) + require.NoError(t, err) + require.NotEqual(t, [32]byte{}, candidateDigestExecAfter) + require.NotEqual(t, candidateDigestExecBefore, candidateDigestExecAfter) + + // next we can revoke candidate - this should set the candidate digest back to zero + _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{ + tenv.HomeChainSel: { + Timelock: state.Chains[tenv.HomeChainSel].Timelock, + CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, + }, + }, []commonchangeset.ChangesetApplication{ + { + Changeset: commonchangeset.WrapChangeSet(RevokeCandidateChangeset), + Config: RevokeCandidateChangesetConfig{ + HomeChainSelector: tenv.HomeChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPCommit, + MCMS: mcmsConfig, + NodeIDs: nodeIDs, + }, + }, + { + Changeset: commonchangeset.WrapChangeSet(RevokeCandidateChangeset), + Config: RevokeCandidateChangesetConfig{ + HomeChainSelector: tenv.HomeChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPExec, + MCMS: mcmsConfig, + NodeIDs: nodeIDs, + }, + }, + }) + require.NoError(t, err) + + // after revoking the candidate, the candidate digest should be zero + candidateDigestCommitAfterRevoke, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPCommit)) + require.NoError(t, err) + require.Equal(t, [32]byte{}, candidateDigestCommitAfterRevoke) + + candidateDigestExecAfterRevoke, err := ccipHome.GetCandidateDigest(&bind.CallOpts{ + Context: ctx, + }, donID, uint8(types.PluginTypeCCIPExec)) + require.NoError(t, err) + require.Equal(t, [32]byte{}, candidateDigestExecAfterRevoke) + }) + } +} + func transferToTimelock( t *testing.T, tenv DeployedEnv, From 5489ff9536372fecb8006a2f525c7e660401094c Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Fri, 13 Dec 2024 13:38:39 +0200 Subject: [PATCH 4/8] small cleanup --- deployment/ccip/changeset/cs_ccip_home.go | 2 -- deployment/ccip/changeset/internal/deploy_home_chain.go | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index 54f0f1dc1d0..b2c13486ede 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -826,8 +826,6 @@ func revokeCandidateOps( return nil, fmt.Errorf("pack set candidate call: %w", err) } - fmt.Printf("encoded revoke candidate call: %x\n", encodedRevokeCandidateCall) - updateDonTx, err := capReg.UpdateDON( txOpts, donID, diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index aa029fd4bec..5697c0e2f73 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -143,6 +143,8 @@ func DonIDForChain(registry *capabilities_registry.CapabilitiesRegistry, ccipHom return donIDs[0], nil } +// BuildSetOCR3ConfigArgs builds the OCR3 config arguments for the OffRamp contract +// using the donID's OCR3 configs from the CCIPHome contract. func BuildSetOCR3ConfigArgs( donID uint32, ccipHome *ccip_home.CCIPHome, From d4bce9aad1e7bd2ecd760626e2a9a7949691d0fa Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Fri, 13 Dec 2024 13:51:52 +0200 Subject: [PATCH 5/8] fixes --- deployment/ccip/changeset/cs_ccip_home.go | 6 +++--- deployment/ccip/changeset/cs_ccip_home_test.go | 6 ++---- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index b2c13486ede..c372221c64f 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -253,9 +253,6 @@ func (s SetCandidateChangesetConfig) Validate(e deployment.Environment, state CC return nil, fmt.Errorf("get node info: %w", err) } - // TODO: validate token config - // TODO: validate gas config - // check that chain config is set up for the new chain chainConfig, err := state.Chains[s.HomeChainSelector].CCIPHome.GetChainConfig(nil, s.DONChainSelector) if err != nil { @@ -272,6 +269,9 @@ func (s SetCandidateChangesetConfig) Validate(e deployment.Environment, state CC return nil, fmt.Errorf("invalid ccip ocr params: %w", err) } + // TODO: validate token config in the commit config, if commit is the plugin. + // TODO: validate gas config in the chain config in cciphome for this DONChainSelector. + if e.OCRSecrets.IsEmpty() { return nil, fmt.Errorf("OCR secrets must be set") } diff --git a/deployment/ccip/changeset/cs_ccip_home_test.go b/deployment/ccip/changeset/cs_ccip_home_test.go index ddb59bb58a6..7785062bc66 100644 --- a/deployment/ccip/changeset/cs_ccip_home_test.go +++ b/deployment/ccip/changeset/cs_ccip_home_test.go @@ -539,7 +539,7 @@ func Test_RevokeCandidate(t *testing.T) { } } tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds) - _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{ + _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{ tenv.HomeChainSel: { Timelock: state.Chains[tenv.HomeChainSel].Timelock, CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, @@ -552,7 +552,6 @@ func Test_RevokeCandidate(t *testing.T) { FeedChainSelector: tenv.FeedChainSel, DONChainSelector: dest, PluginType: types.PluginTypeCCIPCommit, - NodeIDs: nodeIDs, CCIPOCRParams: DefaultOCRParams( tenv.FeedChainSel, tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), @@ -568,7 +567,6 @@ func Test_RevokeCandidate(t *testing.T) { FeedChainSelector: tenv.FeedChainSel, DONChainSelector: dest, PluginType: types.PluginTypeCCIPExec, - NodeIDs: nodeIDs, CCIPOCRParams: DefaultOCRParams( tenv.FeedChainSel, tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), @@ -597,7 +595,7 @@ func Test_RevokeCandidate(t *testing.T) { require.NotEqual(t, candidateDigestExecBefore, candidateDigestExecAfter) // next we can revoke candidate - this should set the candidate digest back to zero - _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*commonchangeset.TimelockExecutionContracts{ + _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{ tenv.HomeChainSel: { Timelock: state.Chains[tenv.HomeChainSel].Timelock, CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, From a0a3d2e2b797dd5bb51bd7216425c28760f9438b Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Fri, 13 Dec 2024 14:29:18 +0200 Subject: [PATCH 6/8] fix validation --- .../ccip/changeset/cs_add_chain_test.go | 4 +- deployment/ccip/changeset/cs_ccip_home.go | 295 ++++++++------- .../ccip/changeset/cs_ccip_home_test.go | 350 +++--------------- 3 files changed, 212 insertions(+), 437 deletions(-) diff --git a/deployment/ccip/changeset/cs_add_chain_test.go b/deployment/ccip/changeset/cs_add_chain_test.go index a8fdf50b0c1..9b8e908de24 100644 --- a/deployment/ccip/changeset/cs_add_chain_test.go +++ b/deployment/ccip/changeset/cs_add_chain_test.go @@ -196,7 +196,7 @@ func TestAddChainInbound(t *testing.T) { { Changeset: commonchangeset.WrapChangeSet(AddDonAndSetCandidateChangeset), Config: AddDonAndSetCandidateChangesetConfig{ - SetCandidateChangesetConfig: SetCandidateChangesetConfig{ + SetCandidateConfigBase: SetCandidateConfigBase{ HomeChainSelector: e.HomeChainSel, FeedChainSelector: e.FeedChainSel, DONChainSelector: newChain, @@ -214,7 +214,7 @@ func TestAddChainInbound(t *testing.T) { }, { Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), - Config: SetCandidateChangesetConfig{ + Config: SetCandidateConfigBase{ HomeChainSelector: e.HomeChainSel, FeedChainSelector: e.FeedChainSel, DONChainSelector: newChain, diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index c372221c64f..dff19a37dc6 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -10,7 +10,6 @@ import ( "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" - "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" @@ -40,42 +39,37 @@ type PromoteAllCandidatesChangesetConfig struct { MCMS *MCMSConfig } -func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { +func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (donID uint32, err error) { if err := deployment.IsValidChainSelector(p.HomeChainSelector); err != nil { - return nil, fmt.Errorf("home chain selector invalid: %w", err) + return 0, fmt.Errorf("home chain selector invalid: %w", err) } if err := deployment.IsValidChainSelector(p.DONChainSelector); err != nil { - return nil, fmt.Errorf("don chain selector invalid: %w", err) + return 0, fmt.Errorf("don chain selector invalid: %w", err) } if len(e.NodeIDs) == 0 { - return nil, fmt.Errorf("NodeIDs must be set") + return 0, fmt.Errorf("NodeIDs must be set") } if state.Chains[p.HomeChainSelector].CCIPHome == nil { - return nil, fmt.Errorf("CCIPHome contract does not exist") + return 0, fmt.Errorf("CCIPHome contract does not exist") } if state.Chains[p.HomeChainSelector].CapabilityRegistry == nil { - return nil, fmt.Errorf("CapabilityRegistry contract does not exist") + return 0, fmt.Errorf("CapabilityRegistry contract does not exist") } if state.Chains[p.DONChainSelector].OffRamp == nil { // should not be possible, but a defensive check. - return nil, fmt.Errorf("OffRamp contract does not exist") + return 0, fmt.Errorf("OffRamp contract does not exist") } - nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) - if err != nil { - return nil, fmt.Errorf("fetch node info: %w", err) - } - - donID, err := internal.DonIDForChain( + donID, err = internal.DonIDForChain( state.Chains[p.HomeChainSelector].CapabilityRegistry, state.Chains[p.HomeChainSelector].CCIPHome, p.DONChainSelector, ) if err != nil { - return nil, fmt.Errorf("fetch don id for chain: %w", err) + return 0, fmt.Errorf("fetch don id for chain: %w", err) } if donID == 0 { - return nil, fmt.Errorf("don doesn't exist in CR for chain %d", p.DONChainSelector) + return 0, fmt.Errorf("don doesn't exist in CR for chain %d", p.DONChainSelector) } // Check that candidate digest and active digest are not both zero - this is enforced onchain. @@ -83,27 +77,27 @@ func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment, Context: context.Background(), }, donID, uint8(cctypes.PluginTypeCCIPCommit)) if err != nil { - return nil, fmt.Errorf("fetching commit configs from cciphome: %w", err) + return 0, fmt.Errorf("fetching commit configs from cciphome: %w", err) } execConfigs, err := state.Chains[p.HomeChainSelector].CCIPHome.GetAllConfigs(&bind.CallOpts{ Context: context.Background(), }, donID, uint8(cctypes.PluginTypeCCIPExec)) if err != nil { - return nil, fmt.Errorf("fetching exec configs from cciphome: %w", err) + return 0, fmt.Errorf("fetching exec configs from cciphome: %w", err) } if commitConfigs.ActiveConfig.ConfigDigest == [32]byte{} && commitConfigs.CandidateConfig.ConfigDigest == [32]byte{} { - return nil, fmt.Errorf("commit active and candidate config digests are both zero") + return 0, fmt.Errorf("commit active and candidate config digests are both zero") } if execConfigs.ActiveConfig.ConfigDigest == [32]byte{} && execConfigs.CandidateConfig.ConfigDigest == [32]byte{} { - return nil, fmt.Errorf("exec active and candidate config digests are both zero") + return 0, fmt.Errorf("exec active and candidate config digests are both zero") } - return nodes, nil + return donID, nil } // PromoteAllCandidatesChangeset generates a proposal to call promoteCandidate on the CCIPHome through CapReg. @@ -120,11 +114,16 @@ func PromoteAllCandidatesChangeset( return deployment.ChangesetOutput{}, err } - nodes, err := cfg.Validate(e, state) + donID, err := cfg.Validate(e, state) if err != nil { return deployment.ChangesetOutput{}, fmt.Errorf("%w: %w", deployment.ErrInvalidConfig, err) } + nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("fetch node info: %w", err) + } + txOpts := e.Chains[cfg.HomeChainSelector].DeployerKey if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() @@ -133,12 +132,12 @@ func PromoteAllCandidatesChangeset( homeChain := e.Chains[cfg.HomeChainSelector] promoteCandidateOps, err := promoteAllCandidatesForChainOps( - homeChain, txOpts, + homeChain, state.Chains[cfg.HomeChainSelector].CapabilityRegistry, state.Chains[cfg.HomeChainSelector].CCIPHome, - cfg.DONChainSelector, nodes.NonBootstraps(), + donID, cfg.MCMS != nil, ) if err != nil { @@ -174,36 +173,7 @@ func PromoteAllCandidatesChangeset( }, nil } -// AddDonAndSetCandidateChangesetConfig is a separate config struct -// because the validation is slightly different from SetCandidateChangesetConfig. -// In particular, we check to make sure we don't already have a DON for the chain. -type AddDonAndSetCandidateChangesetConfig struct { - SetCandidateChangesetConfig -} - -func (a AddDonAndSetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { - nodes, err := a.SetCandidateChangesetConfig.Validate(e, state) - if err != nil { - return nil, err - } - - // check if a DON already exists for this chain - donID, err := internal.DonIDForChain( - state.Chains[a.HomeChainSelector].CapabilityRegistry, - state.Chains[a.HomeChainSelector].CCIPHome, - a.DONChainSelector, - ) - if err != nil { - return nil, fmt.Errorf("fetch don id for chain: %w", err) - } - if donID != 0 { - return nil, fmt.Errorf("don already exists in CR for chain %d, it has id %d", a.DONChainSelector, donID) - } - - return nodes, nil -} - -type SetCandidateChangesetConfig struct { +type SetCandidateConfigBase struct { HomeChainSelector uint64 FeedChainSelector uint64 @@ -220,63 +190,91 @@ type SetCandidateChangesetConfig struct { MCMS *MCMSConfig } -func (s SetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { +func (s SetCandidateConfigBase) Validate(e deployment.Environment, state CCIPOnChainState) error { if err := deployment.IsValidChainSelector(s.HomeChainSelector); err != nil { - return nil, fmt.Errorf("home chain selector invalid: %w", err) + return fmt.Errorf("home chain selector invalid: %w", err) } if err := deployment.IsValidChainSelector(s.FeedChainSelector); err != nil { - return nil, fmt.Errorf("feed chain selector invalid: %w", err) + return fmt.Errorf("feed chain selector invalid: %w", err) } if err := deployment.IsValidChainSelector(s.DONChainSelector); err != nil { - return nil, fmt.Errorf("don chain selector invalid: %w", err) + return fmt.Errorf("don chain selector invalid: %w", err) } if len(e.NodeIDs) == 0 { - return nil, fmt.Errorf("nodeIDs must be set") + return fmt.Errorf("nodeIDs must be set") } if state.Chains[s.HomeChainSelector].CCIPHome == nil { - return nil, fmt.Errorf("CCIPHome contract does not exist") + return fmt.Errorf("CCIPHome contract does not exist") } if state.Chains[s.HomeChainSelector].CapabilityRegistry == nil { - return nil, fmt.Errorf("CapabilityRegistry contract does not exist") + return fmt.Errorf("CapabilityRegistry contract does not exist") } if state.Chains[s.DONChainSelector].OffRamp == nil { // should not be possible, but a defensive check. - return nil, fmt.Errorf("OffRamp contract does not exist on don chain selector %d", s.DONChainSelector) + return fmt.Errorf("OffRamp contract does not exist on don chain selector %d", s.DONChainSelector) } if s.PluginType != types.PluginTypeCCIPCommit && s.PluginType != types.PluginTypeCCIPExec { - return nil, fmt.Errorf("PluginType must be set to either CCIPCommit or CCIPExec") + return fmt.Errorf("PluginType must be set to either CCIPCommit or CCIPExec") } - nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) - if err != nil { - return nil, fmt.Errorf("get node info: %w", err) - } + // no donID check since this config is used for both adding a new DON and updating an existing one. + // see AddDonAndSetCandidateChangesetConfig.Validate and SetCandidateChangesetConfig.Validate + // for these checks. // check that chain config is set up for the new chain chainConfig, err := state.Chains[s.HomeChainSelector].CCIPHome.GetChainConfig(nil, s.DONChainSelector) if err != nil { - return nil, fmt.Errorf("get all chain configs: %w", err) + return fmt.Errorf("get all chain configs: %w", err) } // FChain should never be zero if a chain config is set in CCIPHome if chainConfig.FChain == 0 { - return nil, fmt.Errorf("chain config not set up for new chain %d", s.DONChainSelector) + return fmt.Errorf("chain config not set up for new chain %d", s.DONChainSelector) } err = s.CCIPOCRParams.Validate() if err != nil { - return nil, fmt.Errorf("invalid ccip ocr params: %w", err) + return fmt.Errorf("invalid ccip ocr params: %w", err) } // TODO: validate token config in the commit config, if commit is the plugin. // TODO: validate gas config in the chain config in cciphome for this DONChainSelector. if e.OCRSecrets.IsEmpty() { - return nil, fmt.Errorf("OCR secrets must be set") + return fmt.Errorf("OCR secrets must be set") + } + + return nil +} + +// AddDonAndSetCandidateChangesetConfig is a separate config struct +// because the validation is slightly different from SetCandidateChangesetConfig. +// In particular, we check to make sure we don't already have a DON for the chain. +type AddDonAndSetCandidateChangesetConfig struct { + SetCandidateConfigBase +} + +func (a AddDonAndSetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) error { + err := a.SetCandidateConfigBase.Validate(e, state) + if err != nil { + return err } - return nodes, nil + // check if a DON already exists for this chain + donID, err := internal.DonIDForChain( + state.Chains[a.HomeChainSelector].CapabilityRegistry, + state.Chains[a.HomeChainSelector].CCIPHome, + a.DONChainSelector, + ) + if err != nil { + return fmt.Errorf("fetch don id for chain: %w", err) + } + if donID != 0 { + return fmt.Errorf("don already exists in CR for chain %d, it has id %d", a.DONChainSelector, donID) + } + + return nil } // AddDonAndSetCandidateChangeset adds new DON for destination to home chain @@ -298,11 +296,16 @@ func AddDonAndSetCandidateChangeset( return deployment.ChangesetOutput{}, err } - nodes, err := cfg.Validate(e, state) + err = cfg.Validate(e, state) if err != nil { return deployment.ChangesetOutput{}, fmt.Errorf("%w: %w", deployment.ErrInvalidConfig, err) } + nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("get node info: %w", err) + } + txOpts := e.Chains[cfg.HomeChainSelector].DeployerKey if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() @@ -425,6 +428,31 @@ func newDonWithCandidateOp( }, nil } +type SetCandidateChangesetConfig struct { + SetCandidateConfigBase +} + +func (s SetCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (donID uint32, err error) { + err = s.SetCandidateConfigBase.Validate(e, state) + if err != nil { + return 0, err + } + + donID, err = internal.DonIDForChain( + state.Chains[s.HomeChainSelector].CapabilityRegistry, + state.Chains[s.HomeChainSelector].CCIPHome, + s.DONChainSelector, + ) + if err != nil { + return 0, fmt.Errorf("fetch don id for chain: %w", err) + } + if donID == 0 { + return 0, fmt.Errorf("don doesn't exist in CR for chain %d", s.DONChainSelector) + } + + return donID, nil +} + // SetCandidateChangeset generates a proposal to call setCandidate on the CCIPHome through the capability registry. // A DON must exist in order to use this changeset effectively, i.e AddDonAndSetCandidateChangeset must be called first. func SetCandidateChangeset( @@ -436,11 +464,16 @@ func SetCandidateChangeset( return deployment.ChangesetOutput{}, err } - nodes, err := cfg.Validate(e, state) + donID, err := cfg.Validate(e, state) if err != nil { return deployment.ChangesetOutput{}, fmt.Errorf("%w: %w", deployment.ErrInvalidConfig, err) } + nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("get node info: %w", err) + } + txOpts := e.Chains[cfg.HomeChainSelector].DeployerKey if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() @@ -466,14 +499,12 @@ func SetCandidateChangeset( } setCandidateMCMSOps, err := setCandidateOnExistingDon( - e.Logger, txOpts, e.Chains[cfg.HomeChainSelector], - config, state.Chains[cfg.HomeChainSelector].CapabilityRegistry, - state.Chains[cfg.HomeChainSelector].CCIPHome, - cfg.DONChainSelector, nodes.NonBootstraps(), + donID, + config, cfg.MCMS != nil, ) if err != nil { @@ -511,27 +542,18 @@ func SetCandidateChangeset( // setCandidateOnExistingDon calls setCandidate on CCIPHome contract through the UpdateDON call on CapReg contract // This proposes to set up OCR3 config for the provided plugin for the DON func setCandidateOnExistingDon( - lggr logger.Logger, txOpts *bind.TransactOpts, homeChain deployment.Chain, - pluginConfig ccip_home.CCIPHomeOCR3Config, capReg *capabilities_registry.CapabilitiesRegistry, - ccipHome *ccip_home.CCIPHome, - chainSelector uint64, nodes deployment.Nodes, + donID uint32, + pluginConfig ccip_home.CCIPHomeOCR3Config, mcmsEnabled bool, ) ([]mcms.Operation, error) { - // fetch DON ID for the chain - donID, err := internal.DonIDForChain(capReg, ccipHome, chainSelector) - if err != nil { - return nil, fmt.Errorf("fetch don id for chain: %w", err) - } if donID == 0 { - return nil, fmt.Errorf("don doesn't exist in CR for chain %d", chainSelector) + return nil, fmt.Errorf("donID is zero") } - lggr.Infof("donID for chain %d: %d", chainSelector, donID) - encodedSetCandidateCall, err := internal.CCIPHomeABI.Pack( "setCandidate", donID, @@ -582,13 +604,13 @@ func setCandidateOnExistingDon( // promoteCandidateOp will create the MCMS Operation for `promoteCandidateAndRevokeActive` directed towards the capabilityRegistry func promoteCandidateOp( - homeChain deployment.Chain, txOpts *bind.TransactOpts, - donID uint32, - pluginType uint8, + homeChain deployment.Chain, capReg *capabilities_registry.CapabilitiesRegistry, ccipHome *ccip_home.CCIPHome, nodes deployment.Nodes, + donID uint32, + pluginType uint8, mcmsEnabled bool, ) (mcms.Operation, error) { allConfigs, err := ccipHome.GetAllConfigs(nil, donID, pluginType) @@ -639,31 +661,44 @@ func promoteCandidateOp( // promoteAllCandidatesForChainOps promotes the candidate commit and exec configs to active by calling promoteCandidateAndRevokeActive on CCIPHome through the UpdateDON call on CapReg contract func promoteAllCandidatesForChainOps( - homeChain deployment.Chain, txOpts *bind.TransactOpts, + homeChain deployment.Chain, capReg *capabilities_registry.CapabilitiesRegistry, ccipHome *ccip_home.CCIPHome, - chainSelector uint64, nodes deployment.Nodes, + donID uint32, mcmsEnabled bool, ) ([]mcms.Operation, error) { - // fetch DON ID for the chain - donID, err := internal.DonIDForChain(capReg, ccipHome, chainSelector) - if err != nil { - return nil, fmt.Errorf("fetch don id for chain: %w", err) - } if donID == 0 { - return nil, fmt.Errorf("don doesn't exist in CR for chain %d", chainSelector) + return nil, fmt.Errorf("donID is zero") } var mcmsOps []mcms.Operation - updateCommitOp, err := promoteCandidateOp(homeChain, txOpts, donID, uint8(cctypes.PluginTypeCCIPCommit), capReg, ccipHome, nodes, mcmsEnabled) + updateCommitOp, err := promoteCandidateOp( + txOpts, + homeChain, + capReg, + ccipHome, + nodes, + donID, + uint8(cctypes.PluginTypeCCIPCommit), + mcmsEnabled, + ) if err != nil { return nil, fmt.Errorf("promote candidate op: %w", err) } mcmsOps = append(mcmsOps, updateCommitOp) - updateExecOp, err := promoteCandidateOp(homeChain, txOpts, donID, uint8(cctypes.PluginTypeCCIPExec), capReg, ccipHome, nodes, mcmsEnabled) + updateExecOp, err := promoteCandidateOp( + txOpts, + homeChain, + capReg, + ccipHome, + nodes, + donID, + uint8(cctypes.PluginTypeCCIPExec), + mcmsEnabled, + ) if err != nil { return nil, fmt.Errorf("promote candidate op: %w", err) } @@ -677,7 +712,6 @@ type RevokeCandidateChangesetConfig struct { // DONChainSelector is the chain selector whose candidate config we want to revoke. DONChainSelector uint64 - NodeIDs []string PluginType types.PluginType // MCMS is optional MCMS configuration, if provided the changeset will generate an MCMS proposal. @@ -686,51 +720,46 @@ type RevokeCandidateChangesetConfig struct { MCMS *MCMSConfig } -func (r RevokeCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (deployment.Nodes, error) { +func (r RevokeCandidateChangesetConfig) Validate(e deployment.Environment, state CCIPOnChainState) (donID uint32, err error) { if err := deployment.IsValidChainSelector(r.HomeChainSelector); err != nil { - return nil, fmt.Errorf("home chain selector invalid: %w", err) + return 0, fmt.Errorf("home chain selector invalid: %w", err) } if err := deployment.IsValidChainSelector(r.DONChainSelector); err != nil { - return nil, fmt.Errorf("don chain selector invalid: %w", err) + return 0, fmt.Errorf("don chain selector invalid: %w", err) } - if len(r.NodeIDs) == 0 { - return nil, fmt.Errorf("NodeIDs must be set") + if len(e.NodeIDs) == 0 { + return 0, fmt.Errorf("NodeIDs must be set") } if state.Chains[r.HomeChainSelector].CCIPHome == nil { - return nil, fmt.Errorf("CCIPHome contract does not exist") + return 0, fmt.Errorf("CCIPHome contract does not exist") } if state.Chains[r.HomeChainSelector].CapabilityRegistry == nil { - return nil, fmt.Errorf("CapabilityRegistry contract does not exist") - } - - nodes, err := deployment.NodeInfo(r.NodeIDs, e.Offchain) - if err != nil { - return nil, fmt.Errorf("fetch node info: %w", err) + return 0, fmt.Errorf("CapabilityRegistry contract does not exist") } // check that the don exists for this chain - donID, err := internal.DonIDForChain( + donID, err = internal.DonIDForChain( state.Chains[r.HomeChainSelector].CapabilityRegistry, state.Chains[r.HomeChainSelector].CCIPHome, r.DONChainSelector, ) if err != nil { - return nil, fmt.Errorf("fetch don id for chain: %w", err) + return 0, fmt.Errorf("fetch don id for chain: %w", err) } if donID == 0 { - return nil, fmt.Errorf("don doesn't exist in CR for chain %d", r.DONChainSelector) + return 0, fmt.Errorf("don doesn't exist in CR for chain %d", r.DONChainSelector) } // check that candidate digest is not zero - this is enforced onchain. candidateDigest, err := state.Chains[r.HomeChainSelector].CCIPHome.GetCandidateDigest(nil, donID, uint8(r.PluginType)) if err != nil { - return nil, fmt.Errorf("fetching candidate digest from cciphome: %w", err) + return 0, fmt.Errorf("fetching candidate digest from cciphome: %w", err) } if candidateDigest == [32]byte{} { - return nil, fmt.Errorf("candidate config digest is zero, can't revoke it") + return 0, fmt.Errorf("candidate config digest is zero, can't revoke it") } - return nodes, nil + return donID, nil } func RevokeCandidateChangeset(e deployment.Environment, cfg RevokeCandidateChangesetConfig) (deployment.ChangesetOutput, error) { @@ -739,11 +768,16 @@ func RevokeCandidateChangeset(e deployment.Environment, cfg RevokeCandidateChang return deployment.ChangesetOutput{}, err } - nodes, err := cfg.Validate(e, state) + donID, err := cfg.Validate(e, state) if err != nil { return deployment.ChangesetOutput{}, fmt.Errorf("%w: %w", deployment.ErrInvalidConfig, err) } + nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) + if err != nil { + return deployment.ChangesetOutput{}, fmt.Errorf("fetch nodes info: %w", err) + } + txOpts := e.Chains[cfg.HomeChainSelector].DeployerKey if cfg.MCMS != nil { txOpts = deployment.SimTransactOpts() @@ -755,9 +789,9 @@ func RevokeCandidateChangeset(e deployment.Environment, cfg RevokeCandidateChang homeChain, state.Chains[cfg.HomeChainSelector].CapabilityRegistry, state.Chains[cfg.HomeChainSelector].CCIPHome, - cfg.DONChainSelector, - uint8(cfg.PluginType), nodes.NonBootstraps(), + donID, + uint8(cfg.PluginType), cfg.MCMS != nil, ) if err != nil { @@ -797,18 +831,13 @@ func revokeCandidateOps( homeChain deployment.Chain, capReg *capabilities_registry.CapabilitiesRegistry, ccipHome *ccip_home.CCIPHome, - chainSelector uint64, - pluginType uint8, nodes deployment.Nodes, + donID uint32, + pluginType uint8, mcmsEnabled bool, ) ([]mcms.Operation, error) { - // fetch DON ID for the chain - donID, err := internal.DonIDForChain(capReg, ccipHome, chainSelector) - if err != nil { - return nil, fmt.Errorf("fetch don id for chain: %w", err) - } if donID == 0 { - return nil, fmt.Errorf("don doesn't exist in CR for chain %d", chainSelector) + return nil, fmt.Errorf("donID is zero") } candidateDigest, err := ccipHome.GetCandidateDigest(nil, donID, pluginType) diff --git a/deployment/ccip/changeset/cs_ccip_home_test.go b/deployment/ccip/changeset/cs_ccip_home_test.go index 7785062bc66..b728e7b0c1d 100644 --- a/deployment/ccip/changeset/cs_ccip_home_test.go +++ b/deployment/ccip/changeset/cs_ccip_home_test.go @@ -4,272 +4,20 @@ import ( "testing" "github.com/ethereum/go-ethereum/accounts/abi/bind" - "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" - "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/mcms" - "github.com/smartcontractkit/ccip-owner-contracts/pkg/proposal/timelock" "golang.org/x/exp/maps" "github.com/smartcontractkit/chainlink-testing-framework/lib/utils/testcontext" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" - cctypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types" - "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/ccip/generated/router" "github.com/smartcontractkit/chainlink/v2/core/logger" - "github.com/smartcontractkit/chainlink/deployment" - "github.com/stretchr/testify/require" commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" "github.com/smartcontractkit/chainlink/deployment/common/proposalutils" ) -func TestActiveCandidate(t *testing.T) { - t.Skipf("to be enabled after latest cl-ccip is compatible") - t.Parallel() - tenv := NewMemoryEnvironment(t, - WithChains(3), - WithNodes(5)) - e := tenv.Env - state, err := LoadOnchainState(tenv.Env) - require.NoError(t, err) - allChains := maps.Keys(e.Chains) - - // Add all lanes - require.NoError(t, AddLanesForAll(e, state)) - // Need to keep track of the block number for each chain so that event subscription can be done from that block. - startBlocks := make(map[uint64]*uint64) - // Send a message from each chain to every other chain. - expectedSeqNum := make(map[SourceDestPair]uint64) - expectedSeqNumExec := make(map[SourceDestPair][]uint64) - for src := range e.Chains { - for dest, destChain := range e.Chains { - if src == dest { - continue - } - latesthdr, err := destChain.Client.HeaderByNumber(testcontext.Get(t), nil) - require.NoError(t, err) - block := latesthdr.Number.Uint64() - startBlocks[dest] = &block - msgSentEvent := TestSendRequest(t, e, state, src, dest, false, router.ClientEVM2AnyMessage{ - Receiver: common.LeftPadBytes(state.Chains[dest].Receiver.Address().Bytes(), 32), - Data: []byte("hello world"), - TokenAmounts: nil, - FeeToken: common.HexToAddress("0x0"), - ExtraArgs: nil, - }) - expectedSeqNum[SourceDestPair{ - SourceChainSelector: src, - DestChainSelector: dest, - }] = msgSentEvent.SequenceNumber - expectedSeqNumExec[SourceDestPair{ - SourceChainSelector: src, - DestChainSelector: dest, - }] = []uint64{msgSentEvent.SequenceNumber} - } - } - - // Wait for all commit reports to land. - ConfirmCommitForAllWithExpectedSeqNums(t, e, state, expectedSeqNum, startBlocks) - - //After commit is reported on all chains, token prices should be updated in FeeQuoter. - for dest := range e.Chains { - linkAddress := state.Chains[dest].LinkToken.Address() - feeQuoter := state.Chains[dest].FeeQuoter - timestampedPrice, err := feeQuoter.GetTokenPrice(nil, linkAddress) - require.NoError(t, err) - require.Equal(t, MockLinkPrice, timestampedPrice.Value) - } - - //Wait for all exec reports to land - ConfirmExecWithSeqNrsForAll(t, e, state, expectedSeqNumExec, startBlocks) - - // compose the transfer ownership and accept ownership changesets - timelockContracts := make(map[uint64]*proposalutils.TimelockExecutionContracts) - for _, chain := range allChains { - timelockContracts[chain] = &proposalutils.TimelockExecutionContracts{ - Timelock: state.Chains[chain].Timelock, - CallProxy: state.Chains[chain].CallProxy, - } - } - - _, err = commonchangeset.ApplyChangesets(t, e, timelockContracts, []commonchangeset.ChangesetApplication{ - // note this doesn't have proposals. - { - Changeset: commonchangeset.WrapChangeSet(commonchangeset.TransferToMCMSWithTimelock), - Config: genTestTransferOwnershipConfig(tenv, allChains, state), - }, - }) - require.NoError(t, err) - // Apply the accept ownership proposal to all the chains. - - err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 2) - require.NoError(t, err) - - // [ACTIVE, CANDIDATE] setup by setting candidate through cap reg - capReg, ccipHome := state.Chains[tenv.HomeChainSel].CapabilityRegistry, state.Chains[tenv.HomeChainSel].CCIPHome - donID, err := internal.DonIDForChain(capReg, ccipHome, tenv.FeedChainSel) - require.NoError(t, err) - require.NotEqual(t, uint32(0), donID) - donInfo, err := state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID) - require.NoError(t, err) - require.Equal(t, 5, len(donInfo.NodeP2PIds)) - require.Equal(t, uint32(4), donInfo.ConfigCount) - - state, err = LoadOnchainState(e) - require.NoError(t, err) - - // delete a non-bootstrap node - nodes, err := deployment.NodeInfo(e.NodeIDs, e.Offchain) - require.NoError(t, err) - var newNodeIDs []string - // make sure we delete a node that is NOT bootstrap. - // we will remove bootstrap later by calling nodes.NonBootstrap() - if nodes[0].IsBootstrap { - newNodeIDs = e.NodeIDs[:len(e.NodeIDs)-1] - } else { - newNodeIDs = e.NodeIDs[1:] - } - nodes, err = deployment.NodeInfo(newNodeIDs, e.Offchain) - require.NoError(t, err) - - // this will construct ocr3 configurations for the - // commit and exec plugin we will be using - rmnHomeAddress := state.Chains[tenv.HomeChainSel].RMNHome.Address() - tokenConfig := NewTestTokenConfig(state.Chains[tenv.FeedChainSel].USDFeeds) - ccipOCRParams := DefaultOCRParams( - tenv.FeedChainSel, - tokenConfig.GetTokenInfo(e.Logger, state.Chains[tenv.FeedChainSel].LinkToken, state.Chains[tenv.FeedChainSel].Weth9), - nil, - ) - ocr3ConfigMap, err := internal.BuildOCR3ConfigForCCIPHome( - e.OCRSecrets, - state.Chains[tenv.FeedChainSel].OffRamp, - e.Chains[tenv.FeedChainSel], - nodes.NonBootstraps(), - rmnHomeAddress, - ccipOCRParams.OCRParameters, - ccipOCRParams.CommitOffChainConfig, - ccipOCRParams.ExecuteOffChainConfig, - ) - require.NoError(t, err) - - var ( - timelocksPerChain = map[uint64]common.Address{ - tenv.HomeChainSel: state.Chains[tenv.HomeChainSel].Timelock.Address(), - } - proposerMCMSes = map[uint64]*gethwrappers.ManyChainMultiSig{ - tenv.HomeChainSel: state.Chains[tenv.HomeChainSel].ProposerMcm, - } - ) - setCommitCandidateOp, err := setCandidateOnExistingDon( - e.Logger, - deployment.SimTransactOpts(), - tenv.Env.Chains[tenv.HomeChainSel], - ocr3ConfigMap[cctypes.PluginTypeCCIPCommit], - state.Chains[tenv.HomeChainSel].CapabilityRegistry, - state.Chains[tenv.HomeChainSel].CCIPHome, - tenv.FeedChainSel, - nodes.NonBootstraps(), - true, - ) - require.NoError(t, err) - setCommitCandidateProposal, err := proposalutils.BuildProposalFromBatches(timelocksPerChain, proposerMCMSes, []timelock.BatchChainOperation{{ - ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), - Batch: setCommitCandidateOp, - }}, "set new candidates on commit plugin", 0) - require.NoError(t, err) - setCommitCandidateSigned := proposalutils.SignProposal(t, e, setCommitCandidateProposal) - proposalutils.ExecuteProposal(t, e, setCommitCandidateSigned, &proposalutils.TimelockExecutionContracts{ - Timelock: state.Chains[tenv.HomeChainSel].Timelock, - CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, - }, tenv.HomeChainSel) - - // create the op for the commit plugin as well - setExecCandidateOp, err := setCandidateOnExistingDon( - e.Logger, - deployment.SimTransactOpts(), - tenv.Env.Chains[tenv.HomeChainSel], - ocr3ConfigMap[cctypes.PluginTypeCCIPExec], - state.Chains[tenv.HomeChainSel].CapabilityRegistry, - state.Chains[tenv.HomeChainSel].CCIPHome, - tenv.FeedChainSel, - nodes.NonBootstraps(), - true, - ) - require.NoError(t, err) - - setExecCandidateProposal, err := proposalutils.BuildProposalFromBatches(timelocksPerChain, proposerMCMSes, []timelock.BatchChainOperation{{ - ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), - Batch: setExecCandidateOp, - }}, "set new candidates on commit and exec plugins", 0) - require.NoError(t, err) - setExecCandidateSigned := proposalutils.SignProposal(t, e, setExecCandidateProposal) - proposalutils.ExecuteProposal(t, e, setExecCandidateSigned, &proposalutils.TimelockExecutionContracts{ - Timelock: state.Chains[tenv.HomeChainSel].Timelock, - CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, - }, tenv.HomeChainSel) - - // check setup was successful by confirming number of nodes from cap reg - donInfo, err = state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID) - require.NoError(t, err) - require.Equal(t, 4, len(donInfo.NodeP2PIds)) - require.Equal(t, uint32(6), donInfo.ConfigCount) - // [ACTIVE, CANDIDATE] done setup - - // [ACTIVE, CANDIDATE] make sure we can still send successful transaction without updating job specs - err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 3) - require.NoError(t, err) - // [ACTIVE, CANDIDATE] done send successful transaction on active - - // [NEW ACTIVE, NO CANDIDATE] promote to active - // confirm by getting old candidate digest and making sure new active matches - oldCandidateDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec)) - require.NoError(t, err) - - promoteOps, err := promoteAllCandidatesForChainOps( - tenv.Env.Chains[tenv.HomeChainSel], - deployment.SimTransactOpts(), - state.Chains[tenv.HomeChainSel].CapabilityRegistry, - state.Chains[tenv.HomeChainSel].CCIPHome, - tenv.FeedChainSel, - nodes.NonBootstraps(), - true) - require.NoError(t, err) - promoteProposal, err := proposalutils.BuildProposalFromBatches(timelocksPerChain, proposerMCMSes, []timelock.BatchChainOperation{{ - ChainIdentifier: mcms.ChainIdentifier(tenv.HomeChainSel), - Batch: promoteOps, - }}, "promote candidates and revoke actives", 0) - require.NoError(t, err) - promoteSigned := proposalutils.SignProposal(t, e, promoteProposal) - proposalutils.ExecuteProposal(t, e, promoteSigned, &proposalutils.TimelockExecutionContracts{ - Timelock: state.Chains[tenv.HomeChainSel].Timelock, - CallProxy: state.Chains[tenv.HomeChainSel].CallProxy, - }, tenv.HomeChainSel) - // [NEW ACTIVE, NO CANDIDATE] done promoting - - // [NEW ACTIVE, NO CANDIDATE] check onchain state - newActiveDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetActiveDigest(nil, donID, uint8(cctypes.PluginTypeCCIPExec)) - require.NoError(t, err) - require.Equal(t, oldCandidateDigest, newActiveDigest) - - newCandidateDigest, err := state.Chains[tenv.HomeChainSel].CCIPHome.GetCandidateDigest(nil, donID, uint8(cctypes.PluginTypeCCIPCommit)) - require.NoError(t, err) - require.Equal(t, newCandidateDigest, [32]byte{}) - // [NEW ACTIVE, NO CANDIDATE] done checking on chain state - - // [NEW ACTIVE, NO CANDIDATE] send successful request on new active - donInfo, err = state.Chains[tenv.HomeChainSel].CapabilityRegistry.GetDON(nil, donID) - require.NoError(t, err) - require.Equal(t, uint32(8), donInfo.ConfigCount) - - err = ConfirmRequestOnSourceAndDest(t, e, state, tenv.HomeChainSel, tenv.FeedChainSel, 4) - require.NoError(t, err) - // [NEW ACTIVE, NO CANDIDATE] done sending successful request -} - func Test_PromoteCandidate(t *testing.T) { for _, tc := range []struct { name string @@ -425,31 +173,35 @@ func Test_SetCandidate(t *testing.T) { { Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), Config: SetCandidateChangesetConfig{ - HomeChainSelector: tenv.HomeChainSel, - FeedChainSelector: tenv.FeedChainSel, - DONChainSelector: dest, - PluginType: types.PluginTypeCCIPCommit, - CCIPOCRParams: DefaultOCRParams( - tenv.FeedChainSel, - tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), - nil, - ), - MCMS: mcmsConfig, + SetCandidateConfigBase: SetCandidateConfigBase{ + HomeChainSelector: tenv.HomeChainSel, + FeedChainSelector: tenv.FeedChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPCommit, + CCIPOCRParams: DefaultOCRParams( + tenv.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), + nil, + ), + MCMS: mcmsConfig, + }, }, }, { Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), Config: SetCandidateChangesetConfig{ - HomeChainSelector: tenv.HomeChainSel, - FeedChainSelector: tenv.FeedChainSel, - DONChainSelector: dest, - PluginType: types.PluginTypeCCIPExec, - CCIPOCRParams: DefaultOCRParams( - tenv.FeedChainSel, - tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), - nil, - ), - MCMS: mcmsConfig, + SetCandidateConfigBase: SetCandidateConfigBase{ + HomeChainSelector: tenv.HomeChainSel, + FeedChainSelector: tenv.FeedChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPExec, + CCIPOCRParams: DefaultOCRParams( + tenv.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), + nil, + ), + MCMS: mcmsConfig, + }, }, }, }) @@ -501,14 +253,6 @@ func Test_RevokeCandidate(t *testing.T) { source := allChains[0] dest := allChains[1] - nodes, err := deployment.NodeInfo(tenv.Env.NodeIDs, tenv.Env.Offchain) - require.NoError(t, err) - - var nodeIDs []string - for _, node := range nodes { - nodeIDs = append(nodeIDs, node.NodeID) - } - if tc.mcmsEnabled { // Transfer ownership to timelock so that we can promote the zero digest later down the line. transferToTimelock(t, tenv, state, source, dest) @@ -548,31 +292,35 @@ func Test_RevokeCandidate(t *testing.T) { { Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), Config: SetCandidateChangesetConfig{ - HomeChainSelector: tenv.HomeChainSel, - FeedChainSelector: tenv.FeedChainSel, - DONChainSelector: dest, - PluginType: types.PluginTypeCCIPCommit, - CCIPOCRParams: DefaultOCRParams( - tenv.FeedChainSel, - tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), - nil, - ), - MCMS: mcmsConfig, + SetCandidateConfigBase: SetCandidateConfigBase{ + HomeChainSelector: tenv.HomeChainSel, + FeedChainSelector: tenv.FeedChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPCommit, + CCIPOCRParams: DefaultOCRParams( + tenv.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), + nil, + ), + MCMS: mcmsConfig, + }, }, }, { Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), Config: SetCandidateChangesetConfig{ - HomeChainSelector: tenv.HomeChainSel, - FeedChainSelector: tenv.FeedChainSel, - DONChainSelector: dest, - PluginType: types.PluginTypeCCIPExec, - CCIPOCRParams: DefaultOCRParams( - tenv.FeedChainSel, - tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), - nil, - ), - MCMS: mcmsConfig, + SetCandidateConfigBase: SetCandidateConfigBase{ + HomeChainSelector: tenv.HomeChainSel, + FeedChainSelector: tenv.FeedChainSel, + DONChainSelector: dest, + PluginType: types.PluginTypeCCIPExec, + CCIPOCRParams: DefaultOCRParams( + tenv.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[dest].LinkToken, state.Chains[dest].Weth9), + nil, + ), + MCMS: mcmsConfig, + }, }, }, }) @@ -608,7 +356,6 @@ func Test_RevokeCandidate(t *testing.T) { DONChainSelector: dest, PluginType: types.PluginTypeCCIPCommit, MCMS: mcmsConfig, - NodeIDs: nodeIDs, }, }, { @@ -618,7 +365,6 @@ func Test_RevokeCandidate(t *testing.T) { DONChainSelector: dest, PluginType: types.PluginTypeCCIPExec, MCMS: mcmsConfig, - NodeIDs: nodeIDs, }, }, }) From 71bf9d0a6fbc69360dcab5b09071c33e07bf8c61 Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Fri, 13 Dec 2024 14:33:27 +0200 Subject: [PATCH 7/8] fix cs_add_chain_test.go --- .../ccip/changeset/cs_add_chain_test.go | 26 ++++++++++--------- deployment/ccip/changeset/cs_ccip_home.go | 3 +++ 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/deployment/ccip/changeset/cs_add_chain_test.go b/deployment/ccip/changeset/cs_add_chain_test.go index 9b8e908de24..fa99bfb1ad6 100644 --- a/deployment/ccip/changeset/cs_add_chain_test.go +++ b/deployment/ccip/changeset/cs_add_chain_test.go @@ -214,18 +214,20 @@ func TestAddChainInbound(t *testing.T) { }, { Changeset: commonchangeset.WrapChangeSet(SetCandidateChangeset), - Config: SetCandidateConfigBase{ - HomeChainSelector: e.HomeChainSel, - FeedChainSelector: e.FeedChainSel, - DONChainSelector: newChain, - PluginType: types.PluginTypeCCIPExec, - CCIPOCRParams: DefaultOCRParams( - e.FeedChainSel, - tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[newChain].LinkToken, state.Chains[newChain].Weth9), - nil, - ), - MCMS: &MCMSConfig{ - MinDelay: 0, + Config: SetCandidateChangesetConfig{ + SetCandidateConfigBase: SetCandidateConfigBase{ + HomeChainSelector: e.HomeChainSel, + FeedChainSelector: e.FeedChainSel, + DONChainSelector: newChain, + PluginType: types.PluginTypeCCIPExec, + CCIPOCRParams: DefaultOCRParams( + e.FeedChainSel, + tokenConfig.GetTokenInfo(logger.TestLogger(t), state.Chains[newChain].LinkToken, state.Chains[newChain].Weth9), + nil, + ), + MCMS: &MCMSConfig{ + MinDelay: 0, + }, }, }, }, diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index dff19a37dc6..3ad57d8c28e 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -173,6 +173,9 @@ func PromoteAllCandidatesChangeset( }, nil } +// SetCandidateConfigBase is a common base config struct for AddDonAndSetCandidateChangesetConfig and SetCandidateChangesetConfig. +// This is extracted to deduplicate most of the validation logic. +// Remaining validation logic is done in the specific config structs that inherit from this. type SetCandidateConfigBase struct { HomeChainSelector uint64 FeedChainSelector uint64 From bf366b960ec419158f3a65c895c7961b7c8b8f52 Mon Sep 17 00:00:00 2001 From: Makram Kamaleddine Date: Fri, 13 Dec 2024 14:37:26 +0200 Subject: [PATCH 8/8] add type assertion --- deployment/ccip/changeset/cs_ccip_home.go | 1 + 1 file changed, 1 insertion(+) diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index 3ad57d8c28e..f1e860d9d28 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -24,6 +24,7 @@ var ( _ deployment.ChangeSet[AddDonAndSetCandidateChangesetConfig] = AddDonAndSetCandidateChangeset _ deployment.ChangeSet[PromoteAllCandidatesChangesetConfig] = PromoteAllCandidatesChangeset _ deployment.ChangeSet[SetCandidateChangesetConfig] = SetCandidateChangeset + _ deployment.ChangeSet[RevokeCandidateChangesetConfig] = RevokeCandidateChangeset ) type PromoteAllCandidatesChangesetConfig struct {