From b290951b30700d6b32d8aabbd648a3e2a831a7bb Mon Sep 17 00:00:00 2001 From: Bolek Kulbabinski <1416262+bolekk@users.noreply.github.com> Date: Fri, 8 Nov 2024 15:53:55 -0800 Subject: [PATCH] [Keystone][Deployment] Dedup NOPs --- deployment/keystone/deploy.go | 10 +++++++--- deployment/keystone/deploy_test.go | 12 ++++++++++-- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/deployment/keystone/deploy.go b/deployment/keystone/deploy.go index 9be1d3c21dd..f0231338ac3 100644 --- a/deployment/keystone/deploy.go +++ b/deployment/keystone/deploy.go @@ -192,14 +192,18 @@ func ConfigureRegistry(ctx context.Context, lggr logger.Logger, req ConfigureCon lggr.Infow("registered capabilities", "capabilities", capabilitiesResp.donToCapabilities) // register node operators - var nops []kcr.CapabilitiesRegistryNodeOperator + dedupedNops := make(map[kcr.CapabilitiesRegistryNodeOperator]struct{}) + var nopsList []kcr.CapabilitiesRegistryNodeOperator for _, nop := range nodeIdToNop { - nops = append(nops, nop) + dedupedNops[nop] = struct{}{} + } + for nop := range dedupedNops { + nopsList = append(nopsList, nop) } nopsResp, err := RegisterNOPS(ctx, lggr, RegisterNOPSRequest{ Chain: registryChain, Registry: registry, - Nops: nops, + Nops: nopsList, }) if err != nil { return nil, fmt.Errorf("failed to register node operators: %w", err) diff --git a/deployment/keystone/deploy_test.go b/deployment/keystone/deploy_test.go index 211e273c38e..96350a91d6c 100644 --- a/deployment/keystone/deploy_test.go +++ b/deployment/keystone/deploy_test.go @@ -120,14 +120,22 @@ func TestDeploy(t *testing.T) { require.True(t, ok) gotRegistry := regChainContracts.CapabilitiesRegistry require.NotNil(t, gotRegistry) - // contract reads + // check DONs gotDons, err := gotRegistry.GetDONs(&bind.CallOpts{}) if err != nil { err = keystone.DecodeErr(kcr.CapabilitiesRegistryABI, err) - require.Fail(t, fmt.Sprintf("failed to get Dons from registry at %s: %s", gotRegistry.Address().String(), err)) + require.Fail(t, fmt.Sprintf("failed to get DONs from registry at %s: %s", gotRegistry.Address().String(), err)) } require.NoError(t, err) assert.Len(t, gotDons, len(deployReq.Dons)) + // check NOPs + nops, err := gotRegistry.GetNodeOperators(&bind.CallOpts{}) + if err != nil { + err = keystone.DecodeErr(kcr.CapabilitiesRegistryABI, err) + require.Fail(t, fmt.Sprintf("failed to get NOPs from registry at %s: %s", gotRegistry.Address().String(), err)) + } + require.NoError(t, err) + assert.Len(t, nops, 26) // 10 NOPs owning workflow & writer DONs + 16 NOPs owning Asset DON for n, info := range deployResp.DonInfos { found := false