diff --git a/deployment/ccip/changeset/cs_ccip_home.go b/deployment/ccip/changeset/cs_ccip_home.go index 1d8c6782b76..6dc47f7259e 100644 --- a/deployment/ccip/changeset/cs_ccip_home.go +++ b/deployment/ccip/changeset/cs_ccip_home.go @@ -20,6 +20,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/config" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" + "github.com/smartcontractkit/chainlink/deployment" "github.com/smartcontractkit/chainlink/deployment/ccip/changeset/internal" commoncs "github.com/smartcontractkit/chainlink/deployment/common/changeset" @@ -113,6 +114,7 @@ type PromoteAllCandidatesChangesetConfig struct { // Note that each (chain, ccip capability version) pair has a unique DON ID. RemoteChainSelectors []uint64 + 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. @@ -135,6 +137,11 @@ func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment) return nil, err } + if p.PluginType != types.PluginTypeCCIPCommit && + p.PluginType != types.PluginTypeCCIPExec { + return nil, fmt.Errorf("PluginType must be set to either CCIPCommit or CCIPExec") + } + var donIDs []uint32 for _, chainSelector := range p.RemoteChainSelectors { if err := deployment.IsValidChainSelector(chainSelector); err != nil { @@ -158,31 +165,19 @@ func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment) 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", p.RemoteChainSelectors) + return nil, fmt.Errorf("don doesn't exist in CR for chain %d", chainSelector) } // Check that candidate digest and active digest are not both zero - this is enforced onchain. - commitConfigs, err := state.Chains[p.HomeChainSelector].CCIPHome.GetAllConfigs(&bind.CallOpts{ + pluginConfigs, err := state.Chains[p.HomeChainSelector].CCIPHome.GetAllConfigs(&bind.CallOpts{ Context: e.GetContext(), - }, donID, uint8(cctypes.PluginTypeCCIPCommit)) + }, donID, uint8(p.PluginType)) if err != nil { - return nil, fmt.Errorf("fetching commit configs from cciphome: %w", err) + return nil, fmt.Errorf("fetching %s configs from cciphome: %w", p.PluginType.String(), err) } - execConfigs, err := state.Chains[p.HomeChainSelector].CCIPHome.GetAllConfigs(&bind.CallOpts{ - Context: e.GetContext(), - }, donID, uint8(cctypes.PluginTypeCCIPExec)) - if err != nil { - return nil, 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") - } - - if execConfigs.ActiveConfig.ConfigDigest == [32]byte{} && - execConfigs.CandidateConfig.ConfigDigest == [32]byte{} { - return nil, fmt.Errorf("exec active and candidate config digests are both zero") + if pluginConfigs.ActiveConfig.ConfigDigest == [32]byte{} && + pluginConfigs.CandidateConfig.ConfigDigest == [32]byte{} { + return nil, fmt.Errorf("%s active and candidate config digests are both zero", p.PluginType.String()) } donIDs = append(donIDs, donID) } @@ -238,12 +233,13 @@ func PromoteAllCandidatesChangeset( state.Chains[cfg.HomeChainSelector].CCIPHome, nodes.NonBootstraps(), donID, + cfg.PluginType, cfg.MCMS != nil, ) if err != nil { return deployment.ChangesetOutput{}, fmt.Errorf("generating promote candidate ops: %w", err) } - ops = append(ops, promoteCandidateOps...) + ops = append(ops, promoteCandidateOps) } // Disabled MCMS means that we already executed the txes, so just return early w/out the proposals. @@ -791,44 +787,27 @@ func promoteAllCandidatesForChainOps( ccipHome *ccip_home.CCIPHome, nodes deployment.Nodes, donID uint32, + pluginType cctypes.PluginType, mcmsEnabled bool, -) ([]mcms.Operation, error) { +) (mcms.Operation, error) { if donID == 0 { - return nil, fmt.Errorf("donID is zero") + return mcms.Operation{}, fmt.Errorf("donID is zero") } - var mcmsOps []mcms.Operation - updateCommitOp, err := promoteCandidateOp( + updatePluginOp, err := promoteCandidateOp( txOpts, homeChain, capReg, ccipHome, nodes, donID, - uint8(cctypes.PluginTypeCCIPCommit), + uint8(pluginType), mcmsEnabled, ) if err != nil { - return nil, fmt.Errorf("promote candidate op: %w", err) + return mcms.Operation{}, fmt.Errorf("promote candidate op for plugin %s: %w", pluginType.String(), err) } - mcmsOps = append(mcmsOps, updateCommitOp) - - 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) - } - mcmsOps = append(mcmsOps, updateExecOp) - - return mcmsOps, nil + return updatePluginOp, nil } type RevokeCandidateChangesetConfig struct { diff --git a/deployment/ccip/changeset/cs_ccip_home_test.go b/deployment/ccip/changeset/cs_ccip_home_test.go index b487f1acc26..6b4683ae12c 100644 --- a/deployment/ccip/changeset/cs_ccip_home_test.go +++ b/deployment/ccip/changeset/cs_ccip_home_test.go @@ -61,16 +61,17 @@ func Test_PromoteCandidate(t *testing.T) { donID, err := internal.DonIDForChain(capReg, ccipHome, dest) require.NoError(t, err) require.NotEqual(t, uint32(0), donID) + t.Logf("donID: %d", 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{ + ActiveDigestExecBefore, err := ccipHome.GetActiveDigest(&bind.CallOpts{ Context: ctx, }, donID, uint8(types.PluginTypeCCIPExec)) require.NoError(t, err) - require.Equal(t, [32]byte{}, candidateDigestExecBefore) + require.NotEqual(t, [32]byte{}, ActiveDigestExecBefore) var mcmsConfig *MCMSConfig if tc.mcmsEnabled { @@ -78,6 +79,7 @@ func Test_PromoteCandidate(t *testing.T) { MinDelay: 0, } } + // promotes zero digest on commit and ensure exec is not affected _, err = commonchangeset.ApplyChangesets(t, tenv.Env, map[uint64]*proposalutils.TimelockExecutionContracts{ tenv.HomeChainSel: { Timelock: state.Chains[tenv.HomeChainSel].Timelock, @@ -90,6 +92,7 @@ func Test_PromoteCandidate(t *testing.T) { HomeChainSelector: tenv.HomeChainSel, RemoteChainSelectors: []uint64{dest}, MCMS: mcmsConfig, + PluginType: types.PluginTypeCCIPCommit, }, }, }) @@ -106,7 +109,7 @@ func Test_PromoteCandidate(t *testing.T) { Context: ctx, }, donID, uint8(types.PluginTypeCCIPExec)) require.NoError(t, err) - require.Equal(t, [32]byte{}, activeDigestExec) + require.Equal(t, ActiveDigestExecBefore, activeDigestExec) }) } } diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index 2c401fd8006..ad87acf1239 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -126,6 +126,12 @@ func DonIDForChain(registry *capabilities_registry.CapabilitiesRegistry, ccipHom if err != nil { return 0, fmt.Errorf("get all commit configs from cciphome: %w", err) } + if configs.ActiveConfig.ConfigDigest == [32]byte{} && configs.CandidateConfig.ConfigDigest == [32]byte{} { + configs, err = ccipHome.GetAllConfigs(nil, don.Id, uint8(types.PluginTypeCCIPExec)) + if err != nil { + return 0, fmt.Errorf("get all exec configs from cciphome: %w", err) + } + } if configs.ActiveConfig.Config.ChainSelector == chainSelector || configs.CandidateConfig.Config.ChainSelector == chainSelector { donIDs = append(donIDs, don.Id) } diff --git a/deployment/ccip/changeset/test_environment.go b/deployment/ccip/changeset/test_environment.go index 8c2ea88b276..8e590da1703 100644 --- a/deployment/ccip/changeset/test_environment.go +++ b/deployment/ccip/changeset/test_environment.go @@ -19,6 +19,7 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/logger" jobv1 "github.com/smartcontractkit/chainlink-protos/job-distributor/v1/job" "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" @@ -468,6 +469,16 @@ func NewEnvironmentWithJobsAndContracts(t *testing.T, tc *TestConfigs, tEnv Test Config: PromoteAllCandidatesChangesetConfig{ HomeChainSelector: e.HomeChainSel, RemoteChainSelectors: allChains, + PluginType: types.PluginTypeCCIPCommit, + }, + }, + { + // Promote everything + Changeset: commonchangeset.WrapChangeSet(PromoteAllCandidatesChangeset), + Config: PromoteAllCandidatesChangesetConfig{ + HomeChainSelector: e.HomeChainSel, + RemoteChainSelectors: allChains, + PluginType: types.PluginTypeCCIPExec, }, }, {