Skip to content

make gatewayConnector into a gRPC service#1233

Closed
jinhoonbang wants to merge 4 commits into
mainfrom
PRODCRE-409-gateway-connector-as-grpc-service
Closed

make gatewayConnector into a gRPC service#1233
jinhoonbang wants to merge 4 commits into
mainfrom
PRODCRE-409-gateway-connector-as-grpc-service

Conversation

@jinhoonbang

Copy link
Copy Markdown
Contributor
  • make gatewayConnector into a gRPC service
  • move common Gateway code from core for re-use in capabilities repo

https://smartcontract-it.atlassian.net/browse/PRODCRE-409

@jinhoonbang jinhoonbang force-pushed the PRODCRE-409-gateway-connector-as-grpc-service branch from 221b69a to 59461ad Compare June 4, 2025 10:10
@jinhoonbang jinhoonbang force-pushed the PRODCRE-409-gateway-connector-as-grpc-service branch from a97cdd2 to 59461ad Compare June 4, 2025 10:18
@jinhoonbang jinhoonbang requested a review from Copilot June 5, 2025 17:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the gatewayConnector into a gRPC service while extracting common gateway code for reuse in the capabilities repo. Key changes include new proto definitions and generated files for gateway messages, the addition of gRPC client/server implementations for gateway connectors, and updates to capabilities services to integrate the gatewayConnector dependency.

Reviewed Changes

Copilot reviewed 37 out of 37 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/loop/internal/pb/gatewayconnector/gateway_common.proto New proto definitions for gateway message types
pkg/loop/internal/core/services/gateway/gateway_connector_handler.go Implementation of the gateway connector handler client/server
pkg/loop/internal/core/services/gateway/gateway_connector.go Adds gRPC client and server for gateway connector and integrates AddHandler functionality
pkg/loop/internal/core/services/capability/standard/* Updates to include a new gatewayConnector dependency in capability initialization flows
pkg/capabilities/* Updates across capabilities proto and generated files to add the gateway connector parameter
go.mod Minor dependency updates

Comment thread pkg/loop/internal/core/services/gateway/gateway_connector.go Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
func (cs *CronServer) Initialise(ctx context.Context, config string, telemetryService core.TelemetryService, store core.KeyValueStore, capabilityRegistry core.CapabilitiesRegistry, errorLog core.ErrorLog, pipelineRunner core.PipelineRunnerService, relayerSet core.RelayerSet, oracleFactory core.OracleFactory) error {
if err := cs.CronCapability.Initialise(ctx, config, telemetryService, store, errorLog, pipelineRunner, relayerSet, oracleFactory); err != nil {
func (cs *CronServer) Initialise(ctx context.Context, config string, telemetryService core.TelemetryService, store core.KeyValueStore, capabilityRegistry core.CapabilitiesRegistry, errorLog core.ErrorLog, pipelineRunner core.PipelineRunnerService, relayerSet core.RelayerSet, oracleFactory core.OracleFactory, gatewayConnector core.GatewayConnector) error {
if err := cs.CronCapability.Initialise(ctx, config, telemetryService, store, errorLog, pipelineRunner, relayerSet, oracleFactory, gatewayConnector); err != nil {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will update once this PR is merged

pipelineRunner core.PipelineRunnerService,
relayerSet core.RelayerSet,
oracleFactory core.OracleFactory,
gatewayConnector core.GatewayConnector,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change will need to be carried through to each capability. Is there a fast follow planned for that?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes can update all capabilities after this PR is merged

)

// GatewayConnector is a component run by Nodes to connect to a set of Gateways.
type GatewayConnector interface {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a ticket already made to track consuming this code shuffle back into core?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justinkaseman justinkaseman self-requested a review June 11, 2025 22:10
// GatewayConnector is a component run by Nodes to connect to a set of Gateways.
type GatewayConnector interface {
// Start starts the GatewayConnector
Start(context.Context) error

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need Start and Close here. This interface is exposed to capabilities but under the hood there is a singleton object and its lifecycle is managed by core.

@jinhoonbang jinhoonbang Jun 12, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that this interface is used in both core and capabilities. Are you suggesting we keep this interface narrow and define a broader interface in core like below? That sounds totally feasible too:

type GatewayConnector interface {
	services.Service
	network.ConnectionInitiator
    core.GatewayConnector // narrow interface defined in chainlink-common for shared functionalities 
                                              // between core and capabilities repo
}


import "google/protobuf/empty.proto";

message MessageBody {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like that the Message struct is duplicated as a proto. It was supposed to be an internal representation. Over the wire we send JSON-RPC-encoded messages. If @DeividasK adds his own version of Message, we would need to duplicate it too.

Another option to consider is to send raw bytes in the gRPC service and decode in the Handler using our own JSON-RPC codec. WDYT? cc @cedric-cordenier

Longer term, when we move to don2don framework for Gateways, we'll be passing raw bytes anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does that imply that original JSON-RPC from the user will be relayed from the gateway to the DONs as "pass-through"? What if the gateway needs to append some data before sending the request data to the DONs? Sending raw bytes makes sense to me but the underlying message format should allow for wrapping the original request with additional data. Gateway Message format already allows for such flexibility because it has a raw bytes payload field. Thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another option to consider is to send raw bytes in the gRPC service and decode in the Handler using our own JSON-RPC codec. WDYT? cc @cedric-cordenier

I agree with this (and in fact that was my understanding of how Deividas was going to refactor things anyway)


message SendMessageRequest {
string gateway_id = 1;
Message message = 2;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could put a byte array here (see comment above).

Comment thread pkg/loop/internal/pb/gatewayconnector/gateway_connector.proto
Comment thread pkg/types/gateway/message.go
@jinhoonbang

Copy link
Copy Markdown
Contributor Author

Closing this PR and dividing it into 3 separate ones:

  1. make gatewayConnector into a gRPC service #1256 - make gateway connector into a grpc service. no breaking changes.
  2. move common gateway code from core #1257 - move common gateway code for reuse in capabilities repo. no breaking changes. Unblocks progress in capabilities repo.
  3. add gateway connector to standard capabilities interface #1258 - update standard capabilities interface with gateway connector. Breaking change for chainlink core and capabilities repo

cc @bolekk

@jinhoonbang jinhoonbang requested a review from bolekk June 13, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants