Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services/rfq): use one submitter #2418

Merged
merged 2 commits into from
Apr 1, 2024
Merged

feat(services/rfq): use one submitter #2418

merged 2 commits into from
Apr 1, 2024

Conversation

trajan0x
Copy link
Contributor

@trajan0x trajan0x commented Apr 1, 2024

Description

Currently rfq is using two submitter instances: one for cctp and one for rfq. This is leading to a lot of race conditions, over bumping, and many other issues (and exaggerating #2410). This should fix it

Summary by CodeRabbit

  • New Features
    • Introduced options management for the relayer, including the ability to set a custom transaction submitter.
  • Refactor
    • Enhanced the relayer initialization process to accept additional configuration options, improving flexibility.

Copy link
Contributor

coderabbitai bot commented Apr 1, 2024

Warning

Rate Limit Exceeded

@trajan0x has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 50 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between 3bd8de4 and 5dc1101.

Walkthrough

The recent update introduces enhanced functionality for managing relayer options, particularly focusing on transaction submission. A new mechanism allows for the specification of a submitter through variadic parameters, improving flexibility and customization in the relayer's setup. This change affects the initialization process of the CCTPRelayer, enabling the use of a specified submitter if provided, thus refining the relayer's operational capabilities.

Changes

Files Change Summary
.../cctp-relayer/relayer/options.go Introduced functionality for managing relayer options, including setting a transaction submitter.
.../cctp-relayer/relayer/relayer.go Modified NewCCTPRelayer to accept variadic OptionsArgsOption, enabling custom submitter setup.
.../rfq/relayer/service/relayer.go Enhanced startCCTPRelayer to use WithSubmitter for submitter specification in relayer setup.

🐰✨
In the realm of code, where changes abound,
A rabbit hopped in, improvements found.
With a twirl and a tap, options align,
Submitting transactions, oh so fine.
"To the future," it whispers, under moonlight's gleam,
Where code flows like rivers, and developers dream.
🌟🐾

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share

Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

@github-actions github-actions bot added go Pull requests that update Go code size/xs labels Apr 1, 2024
Copy link

cloudflare-workers-and-pages bot commented Apr 1, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5dc1101
Status: ✅  Deploy successful!
Preview URL: https://36744977.sanguine-fe.pages.dev
Branch Preview URL: https://relayer-submitter.sanguine-fe.pages.dev

View logs

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

Review Status

Configuration used: .coderabbit.yaml

Commits Files that changed from the base of the PR and between 4fbad16 and 3bd8de4.
Files selected for processing (3)
  • services/cctp-relayer/relayer/options.go (1 hunks)
  • services/cctp-relayer/relayer/relayer.go (2 hunks)
  • services/rfq/relayer/service/relayer.go (1 hunks)
Additional Context Used
GitHub Check Runs (1)
Lint (services/cctp-relayer) failure (4)

services/cctp-relayer/relayer/relayer.go: [failure] 77-77:
calculated cyclomatic complexity for function NewCCTPRelayer is 13, max is 10 (cyclop)

Additional comments not posted (3)
services/cctp-relayer/relayer/options.go (1)

5-26: The implementation of options for the relayer using the functional options pattern is well done. This pattern is a good choice for configuring objects without needing a large constructor or a configuration struct exposed. It's flexible and allows for future expansion of options without breaking changes.

services/rfq/relayer/service/relayer.go (1)

277-277: Adding relayer.WithSubmitter(r.submitter) as a parameter to NewCCTPRelayer effectively implements the PR's goal of using a single submitter instance across the RFQ service. This change should streamline the submitter management and potentially reduce the issues related to race conditions and transaction bumping. Ensure that the submitter instance passed here is properly initialized and thread-safe, as it will be shared across different parts of the service.

services/cctp-relayer/relayer/relayer.go (1)

113-122: > 📝 NOTE

This review was outside the diff hunks and was mapped to the diff hunk with the greatest overlap. Original lines [77-119]

The introduction of variadic parameters (rawOpts ...OptionsArgsOption) in the NewCCTPRelayer function is a good approach to enhance flexibility and configurability. This change, along with the conditional initialization of txSubmitter based on opts.submitter, aligns with the PR's objective to consolidate submitter usage. However, the cyclomatic complexity of NewCCTPRelayer has increased beyond the recommended threshold. Consider refactoring to simplify the logic, possibly by extracting parts of the initialization process into separate functions.

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) {
+   // Refactored code to reduce complexity
+   conn, grpcClient, err := setupGRPCConnection(ctx, scribeClient, handler)
+   if err != nil {
+       return nil, err
+   }
+
    opts := makeOptions(rawOpts)
    ...
}

+ // setupGRPCConnection encapsulates the gRPC connection setup
+ func setupGRPCConnection(ctx context.Context, scribeClient client.ScribeClient, handler metrics.Handler) (*grpc.ClientConn, pbscribe.ScribeServiceClient, error) {
+   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()))),
+       grpc.WithStreamInterceptor(otelgrpc.StreamClientInterceptor(otelgrpc.WithTracerProvider(handler.GetTracerProvider()))),
+   )
+   if err != nil {
+       return nil, nil, fmt.Errorf("could not dial grpc: %w", err)
+   }
+
+   grpcClient := pbscribe.NewScribeServiceClient(conn)
+   return conn, grpcClient, nil
+ }

Copy link

codecov bot commented Apr 1, 2024

Codecov Report

Attention: Patch coverage is 55.55556% with 8 lines in your changes are missing coverage. Please review.

Project coverage is 46.72382%. Comparing base (4fbad16) to head (5dc1101).

Files Patch % Lines
services/cctp-relayer/relayer/options.go 30.00000% 6 Missing and 1 partial ⚠️
services/rfq/relayer/service/relayer.go 0.00000% 1 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2418         +/-   ##
===================================================
- Coverage   46.85139%   46.72382%   -0.12757%     
===================================================
  Files            399         396          -3     
  Lines          30569       30447        -122     
  Branches          83          83                 
===================================================
- Hits           14322       14226         -96     
+ Misses         14714       14691         -23     
+ Partials        1533        1530          -3     
Flag Coverage Δ
cctp-relayer 43.53414% <58.82353%> (+0.11950%) ⬆️
promexporter ?
rfq 29.09708% <0.00000%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added size/s and removed size/xs labels Apr 1, 2024
@trajan0x trajan0x merged commit 813de8e into master Apr 1, 2024
32 checks passed
@trajan0x trajan0x deleted the relayer/submitter branch April 1, 2024 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go Pull requests that update Go code size/s
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant