From e35df28ec47b057a0eb78ddcd0098f7ea73a918b Mon Sep 17 00:00:00 2001 From: asoliman Date: Wed, 7 Aug 2024 18:19:37 +0400 Subject: [PATCH] Move registrySyncer creation into ccip delegate --- core/capabilities/ccip/delegate.go | 39 ++++++++++++++++++++++---- core/services/chainlink/application.go | 2 +- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/core/capabilities/ccip/delegate.go b/core/capabilities/ccip/delegate.go index f697043c98b..0aabccb8082 100644 --- a/core/capabilities/ccip/delegate.go +++ b/core/capabilities/ccip/delegate.go @@ -5,10 +5,14 @@ import ( "fmt" "time" + "github.com/smartcontractkit/chainlink-common/pkg/loop" "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/common" configsevm "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/configs/evm" "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/launcher" "github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip/oraclecreator" + "github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon" + p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types" + "github.com/smartcontractkit/chainlink/v2/core/services/registrysyncer" ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types" @@ -27,25 +31,28 @@ import ( "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ocr2key" "github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" "github.com/smartcontractkit/chainlink/v2/core/services/ocr2" - "github.com/smartcontractkit/chainlink/v2/core/services/ocrcommon" "github.com/smartcontractkit/chainlink/v2/core/services/pipeline" - "github.com/smartcontractkit/chainlink/v2/core/services/registrysyncer" "github.com/smartcontractkit/chainlink/v2/core/services/relay" "github.com/smartcontractkit/chainlink/v2/core/services/relay/evm" "github.com/smartcontractkit/chainlink/v2/core/services/telemetry" "github.com/smartcontractkit/chainlink/v2/plugins" ) +type RelayGetter interface { + Get(types.RelayID) (loop.Relayer, error) + GetIDToRelayerMap() (map[types.RelayID]loop.Relayer, error) +} + type Delegate struct { lggr logger.Logger registrarConfig plugins.RegistrarConfig pipelineRunner pipeline.Runner chains legacyevm.LegacyChainContainer + relayers RelayGetter keystore keystore.Master ds sqlutil.DataSource peerWrapper *ocrcommon.SingletonPeerWrapper monitoringEndpointGen telemetry.MonitoringEndpointGenerator - registrySyncer registrysyncer.Syncer capabilityConfig config.Capabilities isNewlyCreatedJob bool @@ -56,7 +63,7 @@ func NewDelegate( registrarConfig plugins.RegistrarConfig, pipelineRunner pipeline.Runner, chains legacyevm.LegacyChainContainer, - registrySyncer registrysyncer.Syncer, + relayers RelayGetter, keystore keystore.Master, ds sqlutil.DataSource, peerWrapper *ocrcommon.SingletonPeerWrapper, @@ -68,7 +75,7 @@ func NewDelegate( registrarConfig: registrarConfig, pipelineRunner: pipelineRunner, chains: chains, - registrySyncer: registrySyncer, + relayers: relayers, ds: ds, keystore: keystore, peerWrapper: peerWrapper, @@ -99,6 +106,25 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services return nil, fmt.Errorf("failed to get all p2p keys: %w", err) } + 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) + } + registrySyncer, err := registrysyncer.New( + d.lggr, + func() (p2ptypes.PeerID, error) { + return p2ptypes.PeerID(p2pID.PeerID()), nil + }, + relayer, + registryAddress, + ) + if err != nil { + return nil, fmt.Errorf("could not configure syncer: %w", err) + } + ocrKeys, err := d.getOCRKeys(spec.CCIPSpec.OCRKeyBundleIDs) if err != nil { return nil, err @@ -160,9 +186,10 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) (services ) // register the capability launcher with the registry syncer - d.registrySyncer.AddLauncher(capLauncher) + registrySyncer.AddLauncher(capLauncher) return []job.ServiceCtx{ + registrySyncer, hcr, capLauncher, }, nil diff --git a/core/services/chainlink/application.go b/core/services/chainlink/application.go index 8e582f939ad..907080d74a0 100644 --- a/core/services/chainlink/application.go +++ b/core/services/chainlink/application.go @@ -535,7 +535,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) { loopRegistrarConfig, pipelineRunner, opts.RelayerChainInteroperators.LegacyEVMChains(), - capabilityRegistrySyncer, + relayerChainInterops, opts.KeyStore, opts.DS, peerWrapper,