Skip to content

Commit

Permalink
Fix add and remove don (#16523)
Browse files Browse the repository at this point in the history
* remove don fix

* fixes

* fix lint
  • Loading branch information
AnieeG authored Feb 21, 2025
1 parent fa5d1b2 commit 4675d7f
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 6 deletions.
2 changes: 2 additions & 0 deletions deployment/ccip/changeset/internal/deploy_home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, ma
return nopIdByName, nil
}

// LatestCCIPDON returns the latest CCIP DON from the capabilities registry
// Keeping this function for reference
func LatestCCIPDON(registry *capabilities_registry.CapabilitiesRegistry) (*capabilities_registry.CapabilitiesRegistryDONInfo, error) {
dons, err := registry.GetDONs(nil)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions deployment/ccip/changeset/v1_6/cs_ccip_home.go
Original file line number Diff line number Diff line change
Expand Up @@ -649,18 +649,18 @@ func AddDonAndSetCandidateChangeset(
return deployment.ChangesetOutput{}, err
}

latestDon, err := internal.LatestCCIPDON(state.Chains[cfg.HomeChainSelector].CapabilityRegistry)
if err != nil {
return deployment.ChangesetOutput{}, err
}

pluginOCR3Config, ok := newDONArgs[cfg.PluginInfo.PluginType]
if !ok {
return deployment.ChangesetOutput{}, fmt.Errorf("missing plugin %s in ocr3Configs",
cfg.PluginInfo.PluginType.String())
}

expectedDonID := latestDon.Id + 1
expectedDonID, err := state.Chains[cfg.HomeChainSelector].CapabilityRegistry.GetNextDONId(&bind.CallOpts{
Context: e.GetContext(),
})
if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("get next don id: %w", err)
}
addDonOp, err := newDonWithCandidateOp(
txOpts,
e.Chains[cfg.HomeChainSelector],
Expand Down
77 changes: 77 additions & 0 deletions deployment/ccip/changeset/v1_6/cs_home_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/stretchr/testify/require"
"go.uber.org/zap/zapcore"

"github.com/smartcontractkit/chainlink-integrations/evm/utils"

"github.com/smartcontractkit/chainlink/deployment"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset"
"github.com/smartcontractkit/chainlink/deployment/ccip/changeset/testhelpers"
Expand All @@ -15,6 +17,7 @@ import (
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
"github.com/smartcontractkit/chainlink/deployment/common/view/v1_0"
"github.com/smartcontractkit/chainlink/deployment/environment/memory"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/types"
"github.com/smartcontractkit/chainlink/v2/core/logger"
)

Expand Down Expand Up @@ -196,3 +199,77 @@ func TestRemoveDons(t *testing.T) {
require.NoError(t, err)
require.Len(t, donsAfter, len(donsBefore)-1)
}

func TestAddDonAfterRemoveDons(t *testing.T) {
e, _ := testhelpers.NewMemoryEnvironment(t)
s, err := changeset.LoadOnchainState(e.Env)
require.NoError(t, err)
allChains := e.Env.AllChainSelectors()
homeChain := s.Chains[e.HomeChainSel]
ocrConfigs := make(map[uint64]v1_6.CCIPOCRParams)
ocrParams := v1_6.DeriveCCIPOCRParams(
v1_6.WithDefaultCommitOffChainConfig(e.FeedChainSel, nil),
v1_6.WithDefaultExecuteOffChainConfig(nil),
)
// Remove a don
donsBefore, err := homeChain.CapabilityRegistry.GetDONs(nil)
require.NoError(t, err)
e.Env, err = commoncs.Apply(t, e.Env, nil,
commoncs.Configure(
deployment.CreateLegacyChangeSet(v1_6.RemoveDONs),
v1_6.RemoveDONsConfig{
HomeChainSel: e.HomeChainSel,
DonIDs: []uint32{donsBefore[len(donsBefore)-1].Id},
},
),
)
require.NoError(t, err)
donsAfter, err := homeChain.CapabilityRegistry.GetDONs(nil)
require.NoError(t, err)
require.Len(t, donsAfter, len(donsBefore)-1)

encoded, err := utils.ABIEncode(`[{"type": "string"}, {"type": "string"}]`, "ccip", "v1.0.0")
require.NoError(t, err)
capabilityID := utils.Keccak256Fixed(encoded)
ccipHome := s.Chains[e.HomeChainSel].CCIPHome
donRemovedForChain := uint64(0)
for _, chain := range allChains {
chainFound := false
for _, don := range donsAfter {
if len(don.CapabilityConfigurations) == 1 &&
don.CapabilityConfigurations[0].CapabilityId == capabilityID {
configs, err := ccipHome.GetAllConfigs(nil, don.Id, uint8(types.PluginTypeCCIPCommit))
require.NoError(t, err)
if configs.ActiveConfig.ConfigDigest == [32]byte{} && configs.CandidateConfig.ConfigDigest == [32]byte{} {
configs, err = ccipHome.GetAllConfigs(nil, don.Id, uint8(types.PluginTypeCCIPExec))
require.NoError(t, err)
}
if configs.ActiveConfig.Config.ChainSelector == chain || configs.CandidateConfig.Config.ChainSelector == chain {
chainFound = true
}
}
}
if !chainFound {
donRemovedForChain = chain
break
}
}
ocrConfigs[donRemovedForChain] = ocrParams
// try to add the another don
e.Env, err = commoncs.Apply(t, e.Env, nil,
commoncs.Configure(
deployment.CreateLegacyChangeSet(v1_6.AddDonAndSetCandidateChangeset),
v1_6.AddDonAndSetCandidateChangesetConfig{
SetCandidateConfigBase: v1_6.SetCandidateConfigBase{
HomeChainSelector: e.HomeChainSel,
FeedChainSelector: e.FeedChainSel,
},
PluginInfo: v1_6.SetCandidatePluginInfo{
OCRConfigPerRemoteChainSelector: ocrConfigs,
PluginType: types.PluginTypeCCIPCommit,
},
},
),
)
require.NoError(t, err)
}

0 comments on commit 4675d7f

Please sign in to comment.