Skip to content

Commit

Permalink
Merge branch 'relayer/submitter' into fix/txtype [goreleaser] stage #…
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed Apr 1, 2024
2 parents f1c0f9e + 3bd8de4 commit d8fa2bb
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
26 changes: 26 additions & 0 deletions services/cctp-relayer/relayer/options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package relayer

import "github.com/synapsecns/sanguine/ethergo/submitter"

// relayerOptions is a struct that holds the options for the relayer.
type relayerOptions struct {
submitter submitter.TransactionSubmitter
}

// OptionsArgsOption is an option passed into the relayer.
type OptionsArgsOption func(options *relayerOptions)

// WithSubmitter sets the submitter for the relayer.
func WithSubmitter(txSubmitter submitter.TransactionSubmitter) OptionsArgsOption {
return func(options *relayerOptions) {
options.submitter = txSubmitter
}

Check warning on line 17 in services/cctp-relayer/relayer/options.go

View check run for this annotation

Codecov / codecov/patch

services/cctp-relayer/relayer/options.go#L14-L17

Added lines #L14 - L17 were not covered by tests
}

func makeOptions(opts []OptionsArgsOption) *relayerOptions {
args := &relayerOptions{}
for _, opt := range opts {
opt(args)
}

Check warning on line 24 in services/cctp-relayer/relayer/options.go

View check run for this annotation

Codecov / codecov/patch

services/cctp-relayer/relayer/options.go#L23-L24

Added lines #L23 - L24 were not covered by tests
return args
}
9 changes: 7 additions & 2 deletions services/cctp-relayer/relayer/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ type CCTPRelayer struct {
}

// NewCCTPRelayer creates a new CCTPRelayer.
func NewCCTPRelayer(ctx context.Context, cfg config.Config, store db2.CCTPRelayerDB, scribeClient client.ScribeClient, omniRPCClient omniClient.RPCClient, handler metrics.Handler, attestationAPI attestation.CCTPAPI) (*CCTPRelayer, error) {
func NewCCTPRelayer(ctx context.Context, cfg config.Config, store db2.CCTPRelayerDB, scribeClient client.ScribeClient, omniRPCClient omniClient.RPCClient, handler metrics.Handler, attestationAPI attestation.CCTPAPI, rawOpts ...OptionsArgsOption) (*CCTPRelayer, error) {

Check failure on line 77 in services/cctp-relayer/relayer/relayer.go

View workflow job for this annotation

GitHub Actions / Lint (services/cctp-relayer)

calculated cyclomatic complexity for function NewCCTPRelayer is 13, max is 10 (cyclop)
opts := makeOptions(rawOpts)

conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:%d", scribeClient.URL, scribeClient.Port),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithUnaryInterceptor(otelgrpc.UnaryClientInterceptor(otelgrpc.WithTracerProvider(handler.GetTracerProvider()))),
Expand Down Expand Up @@ -111,7 +113,10 @@ func NewCCTPRelayer(ctx context.Context, cfg config.Config, store db2.CCTPRelaye
return nil, fmt.Errorf("could not make cctp signer: %w", err)
}

txSubmitter := submitter.NewTransactionSubmitter(handler, signer, omniRPCClient, store.SubmitterDB(), &cfg.SubmitterConfig)
txSubmitter := opts.submitter
if txSubmitter == nil {
txSubmitter = submitter.NewTransactionSubmitter(handler, signer, omniRPCClient, store.SubmitterDB(), &cfg.SubmitterConfig)
}
relayerRequestChan := make(chan *api.RelayRequest, 1000)
relayerAPI := api.NewRelayerAPIServer(cfg.Port, cfg.Host, store, relayerRequestChan)

Expand Down
2 changes: 1 addition & 1 deletion services/rfq/relayer/service/relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ func (r *Relayer) startCCTPRelayer(ctx context.Context) (err error) {
scribeClient := client.NewRemoteScribe(uint16(cctpCfg.ScribePort), cctpCfg.ScribeURL, r.metrics).ScribeClient
omnirpcClient := omniClient.NewOmnirpcClient(cctpCfg.BaseOmnirpcURL, r.metrics, omniClient.WithCaptureReqRes())
attAPI := attestation.NewCircleAPI(cctpCfg.CircleAPIURl)
cctpRelayer, err := relayer.NewCCTPRelayer(ctx, *cctpCfg, store, scribeClient, omnirpcClient, r.metrics, attAPI)
cctpRelayer, err := relayer.NewCCTPRelayer(ctx, *cctpCfg, store, scribeClient, omnirpcClient, r.metrics, attAPI, relayer.WithSubmitter(r.submitter))

Check warning on line 277 in services/rfq/relayer/service/relayer.go

View check run for this annotation

Codecov / codecov/patch

services/rfq/relayer/service/relayer.go#L277

Added line #L277 was not covered by tests
if err != nil {
return fmt.Errorf("could not create cctp relayer: %w", err)
}
Expand Down

0 comments on commit d8fa2bb

Please sign in to comment.