From c495985d69fb6a507768d821496d585fa71910fd Mon Sep 17 00:00:00 2001 From: asoliman Date: Wed, 7 Aug 2024 20:04:28 +0400 Subject: [PATCH] Cleaning up --- core/capabilities/ccip/delegate.go | 3 +- core/capabilities/ccip/launcher/diff.go | 6 +- core/capabilities/ccip/launcher/diff_test.go | 45 --------------- core/capabilities/ccip/launcher/launcher.go | 5 +- .../ccip/launcher/test_helpers.go | 56 +++++++++++++++++++ core/services/chainlink/application.go | 11 ++-- 6 files changed, 67 insertions(+), 59 deletions(-) create mode 100644 core/capabilities/ccip/launcher/test_helpers.go diff --git a/core/capabilities/ccip/delegate.go b/core/capabilities/ccip/delegate.go index 0aabccb8082..c9974d62e99 100644 --- a/core/capabilities/ccip/delegate.go +++ b/core/capabilities/ccip/delegate.go @@ -108,7 +108,6 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services cfg := d.capabilityConfig rid := cfg.ExternalRegistry().RelayID() - registryAddress := cfg.ExternalRegistry().Address() relayer, err := d.relayers.Get(rid) if err != nil { return nil, fmt.Errorf("could not fetch relayer %s configured for capabilities registry: %w", rid, err) @@ -119,7 +118,7 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services return p2ptypes.PeerID(p2pID.PeerID()), nil }, relayer, - registryAddress, + cfg.ExternalRegistry().Address(), ) if err != nil { return nil, fmt.Errorf("could not configure syncer: %w", err) diff --git a/core/capabilities/ccip/launcher/diff.go b/core/capabilities/ccip/launcher/diff.go index d0a2d6ed126..e631ea9fc78 100644 --- a/core/capabilities/ccip/launcher/diff.go +++ b/core/capabilities/ccip/launcher/diff.go @@ -87,7 +87,7 @@ func compareDONs( // filterCCIPDONs filters the CCIP DONs from the given state. func filterCCIPDONs( - ccipCapability registrysyncer.Capability, // This will change to registrysyncer.Capability + ccipCapability registrysyncer.Capability, state registrysyncer.LocalRegistry, ) (map[registrysyncer.DonID]registrysyncer.DON, error) { ccipDONs := make(map[registrysyncer.DonID]registrysyncer.DON) @@ -101,8 +101,8 @@ func filterCCIPDONs( return ccipDONs, nil } -// checkCapabilityPresence checks if the capability with the given version and -// labelled name is present in the given capability registry state. +// checkCapabilityPresence checks if the capability with the given capabilityID +// is present in the given capability registry state. func checkCapabilityPresence( capabilityID string, state registrysyncer.LocalRegistry, diff --git a/core/capabilities/ccip/launcher/diff_test.go b/core/capabilities/ccip/launcher/diff_test.go index d03a628b796..f3dd327fe91 100644 --- a/core/capabilities/ccip/launcher/diff_test.go +++ b/core/capabilities/ccip/launcher/diff_test.go @@ -1,13 +1,10 @@ package launcher import ( - "fmt" "math/big" "reflect" "testing" - "github.com/smartcontractkit/chainlink-common/pkg/capabilities" - ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types" "github.com/stretchr/testify/require" @@ -18,40 +15,6 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/registrysyncer" ) -const ( - ccipCapVersion = "v1.0.0" - ccipCapNewVersion = "v1.1.0" - ccipCapName = "ccip" -) - -var defaultCapability = getCapability(ccipCapName, ccipCapVersion) -var newCapability = getCapability(ccipCapName, ccipCapNewVersion) - -func getDON(id uint32, members []ragep2ptypes.PeerID, cfgVersion uint32) capabilities.DON { - return capabilities.DON{ - ID: id, - ConfigVersion: cfgVersion, - F: uint8(1), - IsPublic: true, - AcceptsWorkflows: true, - Members: members, - } -} -func getP2PID(id uint32) ragep2ptypes.PeerID { - return ragep2ptypes.PeerID(p2pkey.MustNewV2XXXTestingOnly(big.NewInt(int64(id))).PeerID()) -} - -var p2pID1 = getP2PID(1) -var p2pID2 = getP2PID(2) - -var defaultCapCfgs = map[string]registrysyncer.CapabilityConfiguration{ - defaultCapability.ID: registrysyncer.CapabilityConfiguration{}, -} -var defaultRegistryDon = registrysyncer.DON{ - DON: getDON(1, []ragep2ptypes.PeerID{p2pID1}, 0), - CapabilityConfigurations: defaultCapCfgs, -} - func Test_diff(t *testing.T) { type args struct { capabilityID string @@ -387,11 +350,3 @@ func Test_isMemberOfBootstrapSubcommittee(t *testing.T) { require.True(t, isMemberOfBootstrapSubcommittee(bootstrapKeys, p2pID1)) require.False(t, isMemberOfBootstrapSubcommittee(bootstrapKeys, getP2PID(5))) } - -func getCapability(ccipCapName, ccipCapVersion string) registrysyncer.Capability { - id := fmt.Sprintf("%s@%s", ccipCapName, ccipCapVersion) - return registrysyncer.Capability{ - CapabilityType: capabilities.CapabilityTypeTarget, - ID: id, - } -} diff --git a/core/capabilities/ccip/launcher/launcher.go b/core/capabilities/ccip/launcher/launcher.go index 29daff68fdc..2dc1a1954f5 100644 --- a/core/capabilities/ccip/launcher/launcher.go +++ b/core/capabilities/ccip/launcher/launcher.go @@ -17,7 +17,6 @@ import ( ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types" ccipreader "github.com/smartcontractkit/chainlink-ccip/pkg/reader" - ccipreaderpkg "github.com/smartcontractkit/chainlink-ccip/pkg/reader" "github.com/smartcontractkit/chainlink-common/pkg/services" @@ -329,7 +328,7 @@ func updateDON( // All other cases are invalid. This is enforced in the ccip config contract. func createFutureBlueGreenDeployment( prevDeployment ccipDeployment, - ocrConfigs []ccipreaderpkg.OCR3ConfigWithMeta, + ocrConfigs []ccipreader.OCR3ConfigWithMeta, oracleCreator cctypes.OracleCreator, pluginType cctypes.PluginType, ) (blueGreenDeployment, error) { @@ -415,7 +414,7 @@ func createOracle( p2pID ragep2ptypes.PeerID, oracleCreator cctypes.OracleCreator, pluginType cctypes.PluginType, - ocrConfigs []ccipreaderpkg.OCR3ConfigWithMeta, + ocrConfigs []ccipreader.OCR3ConfigWithMeta, ) (pluginOracle, bootstrapOracle cctypes.CCIPOracle, err error) { pluginOracle, err = oracleCreator.CreatePluginOracle(pluginType, cctypes.OCR3ConfigWithMeta(ocrConfigs[0])) if err != nil { diff --git a/core/capabilities/ccip/launcher/test_helpers.go b/core/capabilities/ccip/launcher/test_helpers.go new file mode 100644 index 00000000000..a2ebf3fdba9 --- /dev/null +++ b/core/capabilities/ccip/launcher/test_helpers.go @@ -0,0 +1,56 @@ +package launcher + +import ( + "fmt" + "math/big" + + "github.com/smartcontractkit/chainlink-common/pkg/capabilities" + + "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" + "github.com/smartcontractkit/chainlink/v2/core/services/registrysyncer" + + ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types" +) + +const ( + ccipCapVersion = "v1.0.0" + ccipCapNewVersion = "v1.1.0" + ccipCapName = "ccip" +) + +var ( + defaultCapability = getCapability(ccipCapName, ccipCapVersion) + newCapability = getCapability(ccipCapName, ccipCapNewVersion) + p2pID1 = getP2PID(1) + p2pID2 = getP2PID(2) + defaultCapCfgs = map[string]registrysyncer.CapabilityConfiguration{ + defaultCapability.ID: registrysyncer.CapabilityConfiguration{}, + } + defaultRegistryDon = registrysyncer.DON{ + DON: getDON(1, []ragep2ptypes.PeerID{p2pID1}, 0), + CapabilityConfigurations: defaultCapCfgs, + } +) + +func getP2PID(id uint32) ragep2ptypes.PeerID { + return ragep2ptypes.PeerID(p2pkey.MustNewV2XXXTestingOnly(big.NewInt(int64(id))).PeerID()) +} + +func getCapability(ccipCapName, ccipCapVersion string) registrysyncer.Capability { + id := fmt.Sprintf("%s@%s", ccipCapName, ccipCapVersion) + return registrysyncer.Capability{ + CapabilityType: capabilities.CapabilityTypeTarget, + ID: id, + } +} + +func getDON(id uint32, members []ragep2ptypes.PeerID, cfgVersion uint32) capabilities.DON { + return capabilities.DON{ + ID: id, + ConfigVersion: cfgVersion, + F: uint8(1), + IsPublic: true, + AcceptsWorkflows: true, + Members: members, + } +} diff --git a/core/services/chainlink/application.go b/core/services/chainlink/application.go index 907080d74a0..c94d2fb8161 100644 --- a/core/services/chainlink/application.go +++ b/core/services/chainlink/application.go @@ -17,23 +17,20 @@ import ( "go.uber.org/multierr" "go.uber.org/zap/zapcore" - "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip" - "github.com/smartcontractkit/chainlink-common/pkg/loop" commonservices "github.com/smartcontractkit/chainlink-common/pkg/services" "github.com/smartcontractkit/chainlink-common/pkg/sqlutil" "github.com/smartcontractkit/chainlink-common/pkg/utils" "github.com/smartcontractkit/chainlink-common/pkg/utils/jsonserializable" "github.com/smartcontractkit/chainlink-common/pkg/utils/mailbox" - "github.com/smartcontractkit/chainlink/v2/core/capabilities" - "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" - "github.com/smartcontractkit/chainlink/v2/core/services/standardcapabilities" - "github.com/smartcontractkit/chainlink/v2/core/static" "github.com/smartcontractkit/chainlink/v2/core/bridges" "github.com/smartcontractkit/chainlink/v2/core/build" + "github.com/smartcontractkit/chainlink/v2/core/capabilities" + "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip" "github.com/smartcontractkit/chainlink/v2/core/capabilities/remote" remotetypes "github.com/smartcontractkit/chainlink/v2/core/capabilities/remote/types" + "github.com/smartcontractkit/chainlink/v2/core/chains/evm/logpoller" "github.com/smartcontractkit/chainlink/v2/core/chains/evm/txmgr" evmtypes "github.com/smartcontractkit/chainlink/v2/core/chains/evm/types" evmutils "github.com/smartcontractkit/chainlink/v2/core/chains/evm/utils" @@ -63,6 +60,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/registrysyncer" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm/mercury/wsrpc" + "github.com/smartcontractkit/chainlink/v2/core/services/standardcapabilities" "github.com/smartcontractkit/chainlink/v2/core/services/streams" "github.com/smartcontractkit/chainlink/v2/core/services/telemetry" "github.com/smartcontractkit/chainlink/v2/core/services/vrf" @@ -72,6 +70,7 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/sessions" "github.com/smartcontractkit/chainlink/v2/core/sessions/ldapauth" "github.com/smartcontractkit/chainlink/v2/core/sessions/localauth" + "github.com/smartcontractkit/chainlink/v2/core/static" "github.com/smartcontractkit/chainlink/v2/plugins" )