Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ccip-4675 promote candidate digest by plugin type #15763

Merged
merged 12 commits into from
Dec 19, 2024
Merged
67 changes: 23 additions & 44 deletions deployment/ccip/changeset/cs_ccip_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"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"
Expand Down Expand Up @@ -113,6 +114,7 @@
// 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.
Expand All @@ -135,6 +137,11 @@
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")

Check failure on line 142 in deployment/ccip/changeset/cs_ccip_home.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

fmt.Errorf can be replaced with errors.New (perfsprint)
}

var donIDs []uint32
for _, chainSelector := range p.RemoteChainSelectors {
if err := deployment.IsValidChainSelector(chainSelector); err != nil {
Expand All @@ -158,31 +165,19 @@
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)
}
Expand Down Expand Up @@ -238,12 +233,13 @@
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.
Expand Down Expand Up @@ -791,44 +787,27 @@
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")

Check failure on line 794 in deployment/ccip/changeset/cs_ccip_home.go

View workflow job for this annotation

GitHub Actions / GolangCI Lint (deployment)

fmt.Errorf can be replaced with errors.New (perfsprint)
}

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 {
Expand Down
9 changes: 6 additions & 3 deletions deployment/ccip/changeset/cs_ccip_home_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,25 @@ 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 {
mcmsConfig = &MCMSConfig{
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,
Expand All @@ -90,6 +92,7 @@ func Test_PromoteCandidate(t *testing.T) {
HomeChainSelector: tenv.HomeChainSel,
RemoteChainSelectors: []uint64{dest},
MCMS: mcmsConfig,
PluginType: types.PluginTypeCCIPCommit,
},
},
})
Expand All @@ -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)
})
}
}
Expand Down
6 changes: 6 additions & 0 deletions deployment/ccip/changeset/internal/deploy_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
11 changes: 11 additions & 0 deletions deployment/ccip/changeset/test_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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,
},
},
{
Expand Down
Loading