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

RFQ Relayer: configure chain confirmations #2967

Merged
merged 6 commits into from
Jul 31, 2024
Merged

Conversation

dwasse
Copy link
Collaborator

@dwasse dwasse commented Jul 30, 2024

Summary by CodeRabbit

  • New Features

    • Improved configurability for chain initialization with the introduction of a configuration parameter.
    • Enhanced error handling during chain setup, providing more informative failure messages.
  • Bug Fixes

    • Streamlined logic for retrieving RFQ addresses, reducing potential errors and improving performance.

Copy link
Contributor

coderabbitai bot commented Jul 30, 2024

Warning

Rate limit exceeded

@dwasse has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 5 minutes and 27 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 25c0fc3 and 2a6cd06.

Walkthrough

This update significantly enhances the NewChain function in the RFQ relayer by introducing a configuration parameter. It shifts from hardcoded values to a more dynamic approach, enabling better adaptability through external configuration settings. Error handling improvements are also made, enhancing overall robustness. Related functions have been updated to streamline the initialization process, reducing redundant calls and simplifying the control flow.

Changes

File Change Summary
services/rfq/relayer/chain/chain.go Modified NewChain to accept relconfig.Config, improving config handling and flexibility.
services/rfq/relayer/relapi/server.go Updated NewRelayerAPI to pass cfg instead of a specific RFQ address, streamlining configuration usage.
services/rfq/relayer/service/statushandler.go Simplified chainIDToChain by passing the configuration directly to chain.NewChain, enhancing performance.

Possibly related issues

  • Redundant ChainID Calls  #2959: This update addresses performance concerns by reducing redundant chainID RPC calls in the chain.NewChain function, potentially resolving the issue raised.

🐇 In the fields where daisies bloom,
A chain now weaves without a gloom.
With configs passed, we hop with glee,
No more hardcodes, just harmony!
Through every call, let speed be found,
In this code garden, joy abounds! 🌼


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.
    • @coderabbitai help me debug CodeRabbit configuration file.

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 an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • 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/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

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

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

The pull request introduces a new configuration parameter for chain confirmations, enhancing the flexibility and configurability of the RFQ relayer.

  • services/rfq/relayer/chain/chain.go: NewChain function now accepts relconfig.Config to retrieve RFQ address and confirmations.
  • services/rfq/relayer/relapi/server.go: Modified NewChain call to pass the entire configuration object (cfg).
  • services/rfq/relayer/service/statushandler.go: Refactored chainIDToChain to pass the configuration object directly to chain.NewChain.

Ensure thorough testing of new error handling paths and configuration validation to avoid runtime errors.

3 file(s) reviewed, 5 comment(s)
Edit PR Review Bot Settings

Comment on lines +35 to +37
chainID, err := chainClient.ChainID(ctx)
if err != nil {
return nil, fmt.Errorf("could not get chain id: %w", err)
Copy link

Choose a reason for hiding this comment

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

logic: Consider caching the chain ID to avoid repeated calls to chainClient.ChainID(ctx).

Comment on lines +39 to +41
addr, err := cfg.GetRFQAddress(int(chainID.Int64()))
if err != nil {
return nil, fmt.Errorf("could not get rfq address: %w", err)
Copy link

Choose a reason for hiding this comment

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

style: Ensure cfg.GetRFQAddress handles all possible edge cases for chain ID mappings.

Comment on lines +47 to +49
confirmations, err := cfg.GetConfirmations(int(chainID.Int64()))
if err != nil {
return nil, fmt.Errorf("could not get chain id: %w", err)
return nil, fmt.Errorf("could not get confirmations: %w", err)
Copy link

Choose a reason for hiding this comment

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

check: Validate that cfg.GetConfirmations returns a reasonable default if the value is not set.

@@ -80,7 +80,7 @@ func NewRelayerAPI(
if err != nil {
return nil, fmt.Errorf("could not get chain listener: %w", err)
}
chains[uint32(chainID)], err = chain.NewChain(ctx, chainClient, common.HexToAddress(chainCfg.RFQAddress), chainListener, submitter)
chains[uint32(chainID)], err = chain.NewChain(ctx, cfg, chainClient, chainListener, submitter)
Copy link

Choose a reason for hiding this comment

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

style: Ensure NewChain handles the entire configuration object correctly to avoid potential issues.

return nil, fmt.Errorf("could not get rfq address: %w", err)
}
chain, err := chain.NewChain(ctx, chainClient, common.HexToAddress(rfqAddr), r.chainListeners[id], r.submitter)
chain, err := chain.NewChain(ctx, r.cfg, chainClient, r.chainListeners[id], r.submitter)
Copy link

Choose a reason for hiding this comment

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

style: Ensure the configuration object includes all necessary parameters previously fetched separately.

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 details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 93aa8e4 and 25c0fc3.

Files selected for processing (3)
  • services/rfq/relayer/chain/chain.go (2 hunks)
  • services/rfq/relayer/relapi/server.go (1 hunks)
  • services/rfq/relayer/service/statushandler.go (1 hunks)
Additional comments not posted (8)
services/rfq/relayer/chain/chain.go (6)

17-17: Import statement for relconfig looks good.

The new import statement is necessary for the changes in the NewChain function.


34-34: Function signature change looks good.

The new parameter cfg enhances the flexibility and configurability of the function.


35-38: Error handling for chainID retrieval looks good.

The error message is clear and provides context.


39-42: Error handling for RFQ address retrieval looks good.

The error message is clear and provides context.


47-49: Error handling for confirmations retrieval looks good.

The error message is clear and provides context.


52-55: Return statement looks good.

The function returns a properly initialized Chain object.

services/rfq/relayer/relapi/server.go (1)

83-83: Simplified configuration handling looks good.

The new implementation uses the configuration object directly, eliminating the intermediate step of fetching the RFQ address.

Verify that the new configuration object is correctly utilized in the codebase.

Verification successful

Simplified configuration handling looks good.

The new implementation uses the configuration object directly, eliminating the intermediate step of fetching the RFQ address. The cfg parameter is correctly utilized in the NewChain function to fetch necessary configuration details such as the RFQ address and confirmations.

  • services/rfq/relayer/chain/chain.go: The cfg parameter is used to get the RFQ address and confirmations.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of the new configuration object in the codebase.

# Test: Search for the usage of the `NewChain` function. Expect: Only occurrences of the new signature.
rg --type go -A 5 $'NewChain'

Length of output: 73189


Script:

#!/bin/bash
# Description: Extract the implementation of the `NewChain` function to verify how the `cfg` parameter is utilized.

# Extract the `NewChain` function implementation from the `chain` package.
ast-grep --lang go --pattern $'func NewChain(ctx context.Context, cfg $_, chainClient $_, chainListener $_, ts $_) (*Chain, error) {
  $$$
}' --json

Length of output: 2517

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

203-203: Simplified configuration handling looks good.

The new implementation uses the configuration object directly, eliminating the intermediate step of fetching the RFQ address.

Verify that the new configuration object is correctly utilized in the codebase.

Copy link

cloudflare-workers-and-pages bot commented Jul 30, 2024

Deploying sanguine-fe with  Cloudflare Pages  Cloudflare Pages

Latest commit: c411078
Status: ✅  Deploy successful!
Preview URL: https://f59138d1.sanguine-fe.pages.dev
Branch Preview URL: https://feat-configure-confs.sanguine-fe.pages.dev

View logs

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The pull request enhances the configurability and error handling of the RFQ relayer service, focusing on chain initialization and address retrieval.

  • services/rfq/relayer/relapi/server.go: Improved chain initialization with a new configuration parameter.
  • services/rfq/relayer/relapi/server.go: Enhanced error handling during chain setup for better failure messages.
  • services/rfq/relayer/relapi/server.go: Streamlined logic for retrieving RFQ addresses, reducing errors and improving performance.

Ensure thorough testing of the new configuration paths and error handling to prevent runtime issues.

1 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings

@@ -59,7 +59,7 @@ func NewRelayerAPI(
}

chains := make(map[uint32]*chain.Chain)
for chainID, chainCfg := range cfg.Chains {
for chainID := range cfg.Chains {
Copy link

Choose a reason for hiding this comment

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

check: Consider validating the chain configuration before iterating over it to catch potential misconfigurations early.

@@ -59,7 +59,7 @@ func NewRelayerAPI(
}

chains := make(map[uint32]*chain.Chain)
for chainID, chainCfg := range cfg.Chains {
for chainID := range cfg.Chains {
chainClient, err := omniRPCClient.GetChainClient(ctx, chainID)
Copy link

Choose a reason for hiding this comment

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

style: Check if chainClient is nil before proceeding to avoid dereferencing a nil pointer.

@@ -80,7 +80,7 @@ func NewRelayerAPI(
if err != nil {
return nil, fmt.Errorf("could not get chain listener: %w", err)
}
chains[uint32(chainID)], err = chain.NewChain(ctx, chainClient, common.HexToAddress(chainCfg.RFQAddress), chainListener, submitter)
chains[uint32(chainID)], err = chain.NewChain(ctx, cfg, chainClient, chainListener, submitter)
Copy link

Choose a reason for hiding this comment

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

style: Ensure NewChain handles the entire configuration object correctly to avoid potential issues.

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

The pull request enhances the configurability and error handling of the RFQ relayer service, focusing on chain initialization and address retrieval.

  • services/rfq/relayer/relapi/server.go: Improved chain initialization with a new configuration parameter.
  • services/rfq/relayer/relapi/server.go: Enhanced error handling during chain setup for better failure messages.
  • services/rfq/relayer/relapi/server.go: Streamlined logic for retrieving RFQ addresses, reducing errors and improving performance.

No major changes found since the last review.

No file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

(updates since last review)

Enhanced configurability and error handling for RFQ relayer service, focusing on chain initialization and address retrieval.

  • packages/explorer-ui/components/BridgeTransaction/BridgeTransactionTable.tsx: Replaced formattedValue with value for IconAndAmount component, simplifying data handling.
  • packages/explorer-ui/components/misc/IconAndAmount.tsx: Introduced formatBigIntToString utility, improving token amount formatting.
  • packages/explorer-ui/patch.ts: Added method to serialize BigInt to JSON, enhancing large integer handling.
  • packages/explorer-ui/tsconfig.json: Updated TypeScript target to ES2020, leveraging modern JS features.
  • packages/explorer-ui/utils/formatBigIntToString.ts: Added utility function for robust BigInt to string conversion, crucial for financial calculations.

8 file(s) reviewed, no comment(s)
Edit PR Review Bot Settings

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 25.70179%. Comparing base (8851088) to head (2a6cd06).
Report is 4 commits behind head on master.

Additional details and impacted files
@@                 Coverage Diff                 @@
##              master       #2967         +/-   ##
===================================================
- Coverage   25.70725%   25.70179%   -0.00546%     
===================================================
  Files            771         771                 
  Lines          55603       55572         -31     
  Branches          80          80                 
===================================================
- Hits           14294       14283         -11     
+ Misses         39823       39804         -19     
+ Partials        1486        1485          -1     
Flag Coverage Δ
packages 90.48563% <ø> (ø)

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.

Copy link

codecov bot commented Jul 30, 2024

Bundle Report

Changes will decrease total bundle size by 3.22MB ⬇️

Bundle name Size Change
widget-cjs-esm 273.3kB 0 bytes
synapse-interface-server-cjs 1.38MB 1 bytes ⬇️
sdk-router-@synapsecns/sdk-router-esm 252.32kB 0 bytes
sdk-router-@synapsecns/sdk-router-cjs 117.01kB 0 bytes
synapse-interface-edge-server-array-push 83 bytes 0 bytes
explorer-ui-server-cjs (removed) 892.71kB ⬇️
explorer-ui-edge-server-array-push (removed) 83 bytes ⬇️
explorer-ui-client-array-push (removed) 2.33MB ⬇️

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/xs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant