Skip to content

Commit

Permalink
promote digest by plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
AnieeG committed Dec 19, 2024
1 parent e5040ff commit 954f5b3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 48 deletions.
70 changes: 25 additions & 45 deletions deployment/ccip/changeset/cs_ccip_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,15 @@ type PromoteAllCandidatesChangesetConfig struct {

// RemoteChainSelectors is the chain selector of the DONs that we want to promote the candidate config of.
// Note that each (chain, ccip capability version) pair has a unique DON ID.
RemoteChainCfg []PromoteAllCandidatesChangesetConfigPerRemoteChain
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.
MCMS *MCMSConfig
}

type PromoteAllCandidatesChangesetConfigPerRemoteChain struct {
Chain uint64
PluginType types.PluginType
}

func (p PromoteAllCandidatesChangesetConfig) Validate(e deployment.Environment) ([]uint32, error) {
state, err := LoadOnchainState(e)
if err != nil {
Expand All @@ -141,47 +137,47 @@ 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 _, cfg := range p.RemoteChainCfg {
if err := deployment.IsValidChainSelector(cfg.Chain); err != nil {
for _, selector := range p.RemoteChainSelectors {
if err := deployment.IsValidChainSelector(selector); err != nil {
return nil, fmt.Errorf("don chain selector invalid: %w", err)
}
chainState, exists := state.Chains[cfg.Chain]
chainState, exists := state.Chains[selector]
if !exists {
return nil, fmt.Errorf("chain %d does not exist", cfg.Chain)
return nil, fmt.Errorf("chain %d does not exist", selector)
}
if chainState.OffRamp == nil {
// should not be possible, but a defensive check.
return nil, fmt.Errorf("OffRamp contract does not exist")
}

if cfg.PluginType != types.PluginTypeCCIPCommit &&
cfg.PluginType != types.PluginTypeCCIPExec {
return nil, fmt.Errorf("PluginType must be set to either CCIPCommit or CCIPExec for chain %d", cfg.Chain)
}

donID, err := internal.DonIDForChain(
state.Chains[p.HomeChainSelector].CapabilityRegistry,
state.Chains[p.HomeChainSelector].CCIPHome,
cfg.Chain,
selector,
)
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", cfg.Chain)
return nil, fmt.Errorf("don doesn't exist in CR for chain %d", selector)
}
// Check that candidate digest and active digest are not both zero - this is enforced onchain.
pluginConfigs, err := state.Chains[p.HomeChainSelector].CCIPHome.GetAllConfigs(&bind.CallOpts{
Context: e.GetContext(),
}, donID, uint8(cfg.PluginType))
}, donID, uint8(p.PluginType))
if err != nil {
return nil, fmt.Errorf("fetching %s configs from cciphome: %w", cfg.PluginType.String(), err)
return nil, fmt.Errorf("fetching %s configs from cciphome: %w", p.PluginType.String(), err)
}

if pluginConfigs.ActiveConfig.ConfigDigest == [32]byte{} &&
pluginConfigs.CandidateConfig.ConfigDigest == [32]byte{} {
return nil, fmt.Errorf("%s active and candidate config digests are both zero", cfg.PluginType.String())
return nil, fmt.Errorf("%s active and candidate config digests are both zero", p.PluginType.String())
}
donIDs = append(donIDs, donID)
}
Expand Down Expand Up @@ -237,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.
Expand Down Expand Up @@ -790,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 {
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

0 comments on commit 954f5b3

Please sign in to comment.