Skip to content

Commit

Permalink
[CAPPL-20] Pass GatewayConnector to standard capability Delegate (#14397
Browse files Browse the repository at this point in the history
)

Add a placeholder for one of the new Web API capabilities.
  • Loading branch information
bolekk authored Sep 11, 2024
1 parent b9d95c5 commit bfb66fa
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 14 deletions.
7 changes: 4 additions & 3 deletions core/capabilities/gateway_connector/service_wrapper_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package gatewayconnector
package gatewayconnector_test

import (
"crypto/ecdsa"
Expand All @@ -9,6 +9,7 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

gatewayconnector "github.com/smartcontractkit/chainlink/v2/core/capabilities/gateway_connector"
"github.com/smartcontractkit/chainlink/v2/core/config/toml"
"github.com/smartcontractkit/chainlink/v2/core/internal/testutils"
"github.com/smartcontractkit/chainlink/v2/core/logger"
Expand All @@ -17,7 +18,7 @@ import (
ksmocks "github.com/smartcontractkit/chainlink/v2/core/services/keystore/mocks"
)

func generateWrapper(t *testing.T, privateKey *ecdsa.PrivateKey, keystoreKey *ecdsa.PrivateKey) (*ServiceWrapper, error) {
func generateWrapper(t *testing.T, privateKey *ecdsa.PrivateKey, keystoreKey *ecdsa.PrivateKey) (*gatewayconnector.ServiceWrapper, error) {
logger := logger.TestLogger(t)
privateKeyV2 := ethkey.FromPrivateKey(privateKey)
addr := privateKeyV2.Address
Expand All @@ -43,7 +44,7 @@ func generateWrapper(t *testing.T, privateKey *ecdsa.PrivateKey, keystoreKey *ec
ethKeystore := ksmocks.NewEth(t)
ethKeystore.On("EnabledKeysForChain", mock.Anything, mock.Anything).Return([]ethkey.KeyV2{keystoreKeyV2}, nil)
gc := config.Capabilities().GatewayConnector()
wrapper := NewGatewayConnectorServiceWrapper(gc, ethKeystore, clockwork.NewFakeClock(), logger)
wrapper := gatewayconnector.NewGatewayConnectorServiceWrapper(gc, ethKeystore, clockwork.NewFakeClock(), logger)
require.NoError(t, err)
return wrapper, err
}
Expand Down
18 changes: 18 additions & 0 deletions core/capabilities/webapi/trigger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package webapi

import (
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/gateway/connector"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
)

func NewTrigger(config string, registry core.CapabilitiesRegistry, connector connector.GatewayConnector, lggr logger.Logger) (job.ServiceCtx, error) {
// TODO (CAPPL-22, CAPPL-24):
// - decode config
// - create an implementation of the capability API and add it to the Registry
// - create a handler and register it with Gateway Connector
// - manage trigger subscriptions
// - process incoming trigger events and related metadata
return nil, nil
}
15 changes: 14 additions & 1 deletion core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/build"
"github.com/smartcontractkit/chainlink/v2/core/capabilities"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/ccip"
gatewayconnector "github.com/smartcontractkit/chainlink/v2/core/capabilities/gateway_connector"
"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"
Expand Down Expand Up @@ -265,6 +266,17 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
opts.CapabilitiesRegistry.SetLocalRegistry(&capabilities.TestMetadataRegistry{})
}

var gatewayConnectorWrapper *gatewayconnector.ServiceWrapper
if cfg.Capabilities().GatewayConnector().DonID() != "" {
globalLogger.Debugw("Creating GatewayConnector wrapper", "donID", cfg.Capabilities().GatewayConnector().DonID())
gatewayConnectorWrapper = gatewayconnector.NewGatewayConnectorServiceWrapper(
cfg.Capabilities().GatewayConnector(),
keyStore.Eth(),
clockwork.NewRealClock(),
globalLogger)
srvcs = append(srvcs, gatewayConnectorWrapper)
}

// LOOPs can be created as options, in the case of LOOP relayers, or
// as OCR2 job implementations, in the case of Median today.
// We will have a non-nil registry here in LOOP relayers are being used, otherwise
Expand Down Expand Up @@ -445,7 +457,8 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
loopRegistrarConfig,
telemetryManager,
pipelineRunner,
opts.RelayerChainInteroperators),
opts.RelayerChainInteroperators,
gatewayConnectorWrapper),
}
webhookJobRunner = delegates[job.Webhook].(*webhook.Delegate).WebhookJobRunner()
)
Expand Down
40 changes: 30 additions & 10 deletions core/services/standardcapabilities/delegate.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/sqlutil"
"github.com/smartcontractkit/chainlink-common/pkg/types"
"github.com/smartcontractkit/chainlink-common/pkg/types/core"
gatewayconnector "github.com/smartcontractkit/chainlink/v2/core/capabilities/gateway_connector"
"github.com/smartcontractkit/chainlink/v2/core/capabilities/webapi"
"github.com/smartcontractkit/chainlink/v2/core/logger"
"github.com/smartcontractkit/chainlink/v2/core/services/job"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr2/plugins/generic"
Expand All @@ -26,23 +28,28 @@ type RelayGetter interface {
}

type Delegate struct {
logger logger.Logger
ds sqlutil.DataSource
jobORM job.ORM
registry core.CapabilitiesRegistry
cfg plugins.RegistrarConfig
monitoringEndpointGen telemetry.MonitoringEndpointGenerator
pipelineRunner pipeline.Runner
relayers RelayGetter
logger logger.Logger
ds sqlutil.DataSource
jobORM job.ORM
registry core.CapabilitiesRegistry
cfg plugins.RegistrarConfig
monitoringEndpointGen telemetry.MonitoringEndpointGenerator
pipelineRunner pipeline.Runner
relayers RelayGetter
gatewayConnectorWrapper *gatewayconnector.ServiceWrapper

isNewlyCreatedJob bool
}

const (
commandOverrideForWebAPITrigger = "__builtin_web-api-trigger"
)

func NewDelegate(logger logger.Logger, ds sqlutil.DataSource, jobORM job.ORM, registry core.CapabilitiesRegistry,
cfg plugins.RegistrarConfig, monitoringEndpointGen telemetry.MonitoringEndpointGenerator, pipelineRunner pipeline.Runner,
relayers RelayGetter) *Delegate {
relayers RelayGetter, gatewayConnectorWrapper *gatewayconnector.ServiceWrapper) *Delegate {
return &Delegate{logger: logger, ds: ds, jobORM: jobORM, registry: registry, cfg: cfg, monitoringEndpointGen: monitoringEndpointGen, pipelineRunner: pipelineRunner,
relayers: relayers, isNewlyCreatedJob: false}
relayers: relayers, isNewlyCreatedJob: false, gatewayConnectorWrapper: gatewayConnectorWrapper}
}

func (d *Delegate) JobType() job.Type {
Expand All @@ -67,6 +74,19 @@ func (d *Delegate) ServicesForSpec(ctx context.Context, spec job.Job) ([]job.Ser
return nil, fmt.Errorf("failed to create relayer set: %w", err)
}

// NOTE: special cases for built-in capabilities (to be moved into LOOPPs in the future)
if spec.StandardCapabilitiesSpec.Command == commandOverrideForWebAPITrigger {
if d.gatewayConnectorWrapper == nil {
return nil, errors.New("gateway connector is required for web API Trigger capability")
}
connector := d.gatewayConnectorWrapper.GetGatewayConnector()
triggerSrvc, err := webapi.NewTrigger(spec.StandardCapabilitiesSpec.Config, d.registry, connector, log)
if err != nil {
return nil, fmt.Errorf("failed to create a Web API Trigger service: %w", err)
}
return []job.ServiceCtx{triggerSrvc}, nil
}

standardCapability := newStandardCapabilities(log, spec.StandardCapabilitiesSpec, d.cfg, telemetryService, kvStore, d.registry, errorLog,
pr, relayerSet)

Expand Down

0 comments on commit bfb66fa

Please sign in to comment.