From 0ada38443165aa61613121a8a500ee8f143fb408 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Fri, 21 Feb 2025 11:16:14 -0800 Subject: [PATCH 1/3] remove don fix --- .../changeset/internal/deploy_home_chain.go | 3 + .../ccip/changeset/v1_6/cs_ccip_home.go | 12 +-- .../ccip/changeset/v1_6/cs_home_chain_test.go | 76 +++++++++++++++++++ 3 files changed, 85 insertions(+), 6 deletions(-) diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index e7266e65543..3f4e41eeeb4 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -77,6 +77,9 @@ func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, ma return nopIdByName, nil } +// LatestCCIPDON returns the latest CCIP DON from the capabilities registry +// nolint: unused +// Keeping this function for reference func LatestCCIPDON(registry *capabilities_registry.CapabilitiesRegistry) (*capabilities_registry.CapabilitiesRegistryDONInfo, error) { dons, err := registry.GetDONs(nil) if err != nil { diff --git a/deployment/ccip/changeset/v1_6/cs_ccip_home.go b/deployment/ccip/changeset/v1_6/cs_ccip_home.go index bec314b4518..3ed6017f243 100644 --- a/deployment/ccip/changeset/v1_6/cs_ccip_home.go +++ b/deployment/ccip/changeset/v1_6/cs_ccip_home.go @@ -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], diff --git a/deployment/ccip/changeset/v1_6/cs_home_chain_test.go b/deployment/ccip/changeset/v1_6/cs_home_chain_test.go index 77cfd8c8d2d..79ea10edde6 100644 --- a/deployment/ccip/changeset/v1_6/cs_home_chain_test.go +++ b/deployment/ccip/changeset/v1_6/cs_home_chain_test.go @@ -4,6 +4,7 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" + "github.com/smartcontractkit/chainlink-integrations/evm/utils" "github.com/stretchr/testify/require" "go.uber.org/zap/zapcore" @@ -15,6 +16,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" ) @@ -196,3 +198,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) +} From 2db4ed28537a0b7b13826c471522f5bdc6d7e800 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Fri, 21 Feb 2025 11:38:33 -0800 Subject: [PATCH 2/3] fixes --- deployment/ccip/changeset/internal/deploy_home_chain.go | 1 - 1 file changed, 1 deletion(-) diff --git a/deployment/ccip/changeset/internal/deploy_home_chain.go b/deployment/ccip/changeset/internal/deploy_home_chain.go index 3f4e41eeeb4..ed693c9c693 100644 --- a/deployment/ccip/changeset/internal/deploy_home_chain.go +++ b/deployment/ccip/changeset/internal/deploy_home_chain.go @@ -78,7 +78,6 @@ func getNodeOperatorIDMap(capReg *capabilities_registry.CapabilitiesRegistry, ma } // LatestCCIPDON returns the latest CCIP DON from the capabilities registry -// nolint: unused // Keeping this function for reference func LatestCCIPDON(registry *capabilities_registry.CapabilitiesRegistry) (*capabilities_registry.CapabilitiesRegistryDONInfo, error) { dons, err := registry.GetDONs(nil) From dc9ba396ac11aa961c9d3c7c8dc3ccf0db341a45 Mon Sep 17 00:00:00 2001 From: AnieeG Date: Fri, 21 Feb 2025 11:53:21 -0800 Subject: [PATCH 3/3] fix lint --- deployment/ccip/changeset/v1_6/cs_home_chain_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deployment/ccip/changeset/v1_6/cs_home_chain_test.go b/deployment/ccip/changeset/v1_6/cs_home_chain_test.go index 79ea10edde6..cbcccb52d86 100644 --- a/deployment/ccip/changeset/v1_6/cs_home_chain_test.go +++ b/deployment/ccip/changeset/v1_6/cs_home_chain_test.go @@ -4,10 +4,11 @@ import ( "testing" "github.com/ethereum/go-ethereum/common" - "github.com/smartcontractkit/chainlink-integrations/evm/utils" "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"