Skip to content

Commit

Permalink
Move registrySyncer creation into ccip delegate
Browse files Browse the repository at this point in the history
  • Loading branch information
asoliman92 committed Aug 7, 2024
1 parent 1267e61 commit e35df28
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
39 changes: 33 additions & 6 deletions core/capabilities/ccip/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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
Expand All @@ -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,
Expand All @@ -68,7 +75,7 @@ func NewDelegate(
registrarConfig: registrarConfig,
pipelineRunner: pipelineRunner,
chains: chains,
registrySyncer: registrySyncer,
relayers: relayers,
ds: ds,
keystore: keystore,
peerWrapper: peerWrapper,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
loopRegistrarConfig,
pipelineRunner,
opts.RelayerChainInteroperators.LegacyEVMChains(),
capabilityRegistrySyncer,
relayerChainInterops,
opts.KeyStore,
opts.DS,
peerWrapper,
Expand Down

0 comments on commit e35df28

Please sign in to comment.