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, }, }, })