Skip to content

Commit

Permalink
PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
connorwstein committed Dec 16, 2024
1 parent f0c8ba8 commit 7aef1bd
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
36 changes: 15 additions & 21 deletions deployment/ccip/changeset/cs_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ type RemoveDONsConfig struct {
}

func (c RemoveDONsConfig) Validate(homeChain CCIPChainState) error {
if c.HomeChainSel == 0 {
return fmt.Errorf("home chain selector must be set")
if err := deployment.IsValidChainSelector(c.HomeChainSel); err != nil {
return fmt.Errorf("home chain selector must be set %w", err)
}
if len(c.DonIDs) == 0 {
return fmt.Errorf("don ids must be set")
Expand All @@ -347,22 +347,8 @@ func (c RemoveDONsConfig) Validate(homeChain CCIPChainState) error {
if homeChain.CCIPHome == nil {
return fmt.Errorf("ccip home does not exist")
}
// DON ids must exist
dons, err := homeChain.CapabilityRegistry.GetDONs(nil)
if err != nil {
return fmt.Errorf("failed to get dons: %w", err)
}
for _, donID := range c.DonIDs {
exists := false
for _, don := range dons {
if don.Id == donID {
exists = true
break
}
}
if !exists {
return fmt.Errorf("don id %d does not exist", donID)
}
if err := internal.DONIdExists(homeChain.CapabilityRegistry, c.DonIDs); err != nil {
return err
}
return nil
}
Expand All @@ -375,13 +361,19 @@ func RemoveDONs(e deployment.Environment, cfg RemoveDONsConfig) (deployment.Chan
if err != nil {
return deployment.ChangesetOutput{}, err
}
homeChain := e.Chains[cfg.HomeChainSel]
homeChain, ok := e.Chains[cfg.HomeChainSel]
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("home chain %d not found", cfg.HomeChainSel)
}
homeChainState := state.Chains[cfg.HomeChainSel]
if err := cfg.Validate(homeChainState); err != nil {
return deployment.ChangesetOutput{}, err
}
txOpts := homeChain.DeployerKey
if cfg.MCMS != nil {
// Remove all DONs
txOpts = deployment.SimTransactOpts()
}
homeChainState := state.Chains[cfg.HomeChainSel]

tx, err := homeChainState.CapabilityRegistry.RemoveDONs(txOpts, cfg.DonIDs)
if err != nil {
return deployment.ChangesetOutput{}, err
Expand All @@ -391,6 +383,7 @@ func RemoveDONs(e deployment.Environment, cfg RemoveDONsConfig) (deployment.Chan
if err != nil {
return deployment.ChangesetOutput{}, err
}
e.Logger.Infof("Removed dons using deployer key tx %s", tx.Hash().String())
return deployment.ChangesetOutput{}, nil
}
p, err := proposalutils.BuildProposalFromBatches(
Expand Down Expand Up @@ -418,6 +411,7 @@ func RemoveDONs(e deployment.Environment, cfg RemoveDONsConfig) (deployment.Chan
if err != nil {
return deployment.ChangesetOutput{}, err
}
e.Logger.Infof("Created proposal to remove dons")
return deployment.ChangesetOutput{Proposals: []timelock.MCMSWithTimelockProposal{
*p,
}}, nil
Expand Down
24 changes: 23 additions & 1 deletion deployment/ccip/changeset/internal/deploy_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper"

"github.com/smartcontractkit/chainlink-common/pkg/logger"

"github.com/smartcontractkit/chainlink-ccip/pluginconfig"

"github.com/smartcontractkit/chainlink/deployment"
Expand Down Expand Up @@ -552,3 +553,24 @@ func BuildOCR3ConfigForCCIPHome(

return ocr3Configs, nil
}

func DONIdExists(cr *capabilities_registry.CapabilitiesRegistry, donIDs []uint32) error {
// DON ids must exist
dons, err := cr.GetDONs(nil)
if err != nil {
return fmt.Errorf("failed to get dons: %w", err)
}
for _, donID := range donIDs {
exists := false
for _, don := range dons {
if don.Id == donID {
exists = true
break
}
}
if !exists {
return fmt.Errorf("don id %d does not exist", donID)
}
}
return nil
}

0 comments on commit 7aef1bd

Please sign in to comment.