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: add query interface BridgeCallQuoteByNonce and BridgeCallsByFeeReceiver #818

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

zakir-code
Copy link
Contributor

@zakir-code zakir-code commented Dec 2, 2024

Summary by CodeRabbit

  • New Features

    • Introduced new API endpoints for querying bridge call quotes and bridge calls by fee receiver, enhancing cross-chain functionality.
    • Added new response definitions to improve data structure for bridge call queries.
  • Bug Fixes

    • Updated pagination parameters in several endpoints for improved data retrieval.
  • Tests

    • Added a new test case for validating bridge calls filtered by fee receiver, enhancing test coverage.
  • Documentation

    • Updated API definitions in the Swagger documentation to reflect new endpoints and response structures.

Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

The pull request introduces significant updates to the API definitions in the swagger.yaml file, including renaming and restructuring several endpoints related to cross-chain bridge calls. New RPC methods are added to the Query service in the query.proto file, along with corresponding request and response message types. The grpc_query.go and grpc_query_router.go files receive new methods to handle the added functionalities, while the test suite is enhanced with a new test for querying bridge calls by fee receiver. Overall, these changes streamline the API and improve the querying capabilities for bridge call data.

Changes

File Path Change Summary
docs/swagger-ui/swagger.yaml - Renamed endpoints and updated operation IDs:
/fx/crosschain/v1/bridge_calls/fx/crosschain/v1/bridge_call_quote_by_nonce
/fx/crosschain/v1/bridge_chain_list/fx/crosschain/v1/bridge_calls
/fx/crosschain/v1/bridge_coin_by_denom/fx/crosschain/v1/bridge_calls_by_fee_receiver
- Updated response schemas to include new properties and pagination parameters.
- Added new response definitions for bridge call queries.
proto/fx/gravity/crosschain/v1/query.proto - Added two RPC methods: BridgeCallQuoteByNonce and BridgeCallsByFeeReceiver with corresponding request and response message types.
x/crosschain/keeper/grpc_query.go - Introduced methods for BridgeCallQuoteByNonce and BridgeCallsByFeeReceiver in QueryServer struct, including error handling and data retrieval logic.
x/crosschain/keeper/grpc_query_router.go - Added methods for BridgeCallQuoteByNonce and BridgeCallsByFeeReceiver in RouterKeeper struct, utilizing existing error handling patterns.
x/crosschain/keeper/grpc_query_test.go - Introduced TestQueryServer_BridgeCallsByFeeReceiver to test querying bridge calls by fee receiver, validating the functionality and expected results.
docs/swagger_test.go - Updated assertion in TestSwaggerConfig to reflect the new expected number of GET routes.

Possibly related PRs

🐇 "In the meadow where bridges flow,
New paths for quotes begin to grow.
With calls and fees all in a line,
Our API dances, oh so fine!
Hopping through changes, we celebrate,
A world of bridges, oh, it’s great!" 🌼


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>, please review it.
    • 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 gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @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 using 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.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

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.

Copy link

@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: 2

🧹 Outside diff range and nitpick comments (4)
docs/swagger-ui/swagger.yaml (2)

42573-42659: Enhance response type documentation

While the response types are well-structured, consider adding more descriptive documentation for the following fields:

  • QuoteInfo.fee: Specify the fee format and units
  • QuoteInfo.gas_limit: Explain how this value is determined
  • QuoteInfo.expiry: Document when and how the expiry is calculated

Also applies to: 43494-43511


Line range hint 6529-9446: Consider adding filtering capabilities to bridge call endpoints

The current API design could be enhanced by adding filtering options to improve query flexibility. Consider adding the following query parameters:

  • status: Filter bridge calls by their current status (e.g., pending, completed, failed)
  • time_range: Allow filtering by creation time or block height range
  • token_type: Filter by specific token types

This would improve the API's usability for clients needing to fetch specific subsets of bridge calls.

x/crosschain/keeper/grpc_query_test.go (1)

46-87: Enhance test coverage

While the basic test cases are implemented, consider adding:

  1. Tests for invalid fee receiver address
  2. Validation of the actual returned bridge call data
  3. Test cases for empty results
  4. Error cases (e.g., invalid chain name)
x/crosschain/keeper/grpc_query.go (1)

457-486: Consider optimizing the pagination filter

The current implementation might be inefficient when many records don't match the fee receiver criteria, as it processes and skips them during pagination. Consider:

  1. Using a dedicated index for fee receiver lookups
  2. Or storing bridge calls in a separate collection indexed by fee receiver

Would you like me to propose a specific implementation for either approach?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 5660e53 and a030e36.

⛔ Files ignored due to path filters (3)
  • api/fx/gravity/crosschain/v1/query_grpc.pb.go is excluded by !**/*.pb.go
  • x/crosschain/types/query.pb.go is excluded by !**/*.pb.go
  • x/crosschain/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
📒 Files selected for processing (6)
  • docs/swagger-ui/swagger.yaml (13 hunks)
  • docs/swagger_test.go (1 hunks)
  • proto/fx/gravity/crosschain/v1/query.proto (2 hunks)
  • x/crosschain/keeper/grpc_query.go (2 hunks)
  • x/crosschain/keeper/grpc_query_router.go (1 hunks)
  • x/crosschain/keeper/grpc_query_test.go (1 hunks)
🔇 Additional comments (7)
docs/swagger-ui/swagger.yaml (1)

7095-7170: LGTM! Well-structured endpoint with proper pagination

The endpoint is well-designed with:

  • Comprehensive bridge call response structure
  • Standard pagination implementation
  • Clear parameter definitions
x/crosschain/keeper/grpc_query_router.go (1)

270-276: Implementation follows established patterns

The new query methods are well-implemented and consistent with the existing codebase:

  • Proper error handling through getQueryServerByChainName
  • Clean forwarding to chain-specific implementations
  • Consistent method signatures

Also applies to: 278-284

docs/swagger_test.go (1)

61-61: LGTM: Handler count updated correctly

The assertion update correctly reflects the addition of two new GET endpoints for bridge call queries.

proto/fx/gravity/crosschain/v1/query.proto (3)

147-156: LGTM: New RPC methods are well-defined

The new RPC methods follow the existing patterns and conventions, with appropriate HTTP endpoint mappings.


365-370: LGTM: Message definitions are clear and focused

The request and response messages for BridgeCallQuoteByNonce are well-structured with appropriate field types.


372-382: LGTM: Paginated query messages are well-defined

The request and response messages for BridgeCallsByFeeReceiver properly implement pagination following Cosmos SDK patterns.

x/crosschain/keeper/grpc_query.go (1)

446-455: LGTM: Implementation handles errors appropriately

The BridgeCallQuoteByNonce implementation follows best practices:

  • Validates input
  • Uses appropriate gRPC status codes
  • Properly wraps/unwraps SDK context

Comment on lines +6529 to +6553
/fx/crosschain/v1/bridge_call_quote_by_nonce:
get:
operationId: BridgeCalls
operationId: BridgeCallQuoteByNonce
responses:
'200':
description: A successful response.
schema:
type: object
properties:
bridge_calls:
type: array
items:
type: object
properties:
sender:
type: string
refund:
type: string
tokens:
type: array
items:
type: object
properties:
contract:
type: string
amount:
type: string
description: >-
ERC20Token unique identifier for an Ethereum ERC20
token.
to:
type: string
data:
type: string
memo:
type: string
nonce:
type: string
format: uint64
timeout:
type: string
format: uint64
block_height:
type: string
format: uint64
event_nonce:
type: string
format: uint64
pagination:
quote:
type: object
properties:
next_key:
id:
type: string
format: byte
description: |-
next_key is the key to be passed to PageRequest.key to
query the next page most efficiently. It will be empty if
there are no more results.
total:
format: uint64
token:
type: string
fee:
type: string
oracle:
type: string
gas_limit:
type: string
format: uint64
expiry:
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add missing nonce parameter to the endpoint

The endpoint /bridge_call_quote_by_nonce is missing the required nonce query parameter, which is necessary to fetch the quote for a specific bridge call.

Add the following parameter definition:

  /fx/crosschain/v1/bridge_call_quote_by_nonce:
    get:
      operationId: BridgeCallQuoteByNonce
+     parameters:
+       - name: nonce
+         in: query
+         required: true
+         type: string
+         format: uint64
+         description: The nonce of the bridge call to fetch the quote for
      responses:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/fx/crosschain/v1/bridge_call_quote_by_nonce:
get:
operationId: BridgeCalls
operationId: BridgeCallQuoteByNonce
responses:
'200':
description: A successful response.
schema:
type: object
properties:
bridge_calls:
type: array
items:
type: object
properties:
sender:
type: string
refund:
type: string
tokens:
type: array
items:
type: object
properties:
contract:
type: string
amount:
type: string
description: >-
ERC20Token unique identifier for an Ethereum ERC20
token.
to:
type: string
data:
type: string
memo:
type: string
nonce:
type: string
format: uint64
timeout:
type: string
format: uint64
block_height:
type: string
format: uint64
event_nonce:
type: string
format: uint64
pagination:
quote:
type: object
properties:
next_key:
id:
type: string
format: byte
description: |-
next_key is the key to be passed to PageRequest.key to
query the next page most efficiently. It will be empty if
there are no more results.
total:
format: uint64
token:
type: string
fee:
type: string
oracle:
type: string
gas_limit:
type: string
format: uint64
expiry:
/fx/crosschain/v1/bridge_call_quote_by_nonce:
get:
operationId: BridgeCallQuoteByNonce
parameters:
- name: nonce
in: query
required: true
type: string
format: uint64
description: The nonce of the bridge call to fetch the quote for
responses:

x/crosschain/keeper/grpc_query_test.go Show resolved Hide resolved
@fx0x55 fx0x55 merged commit a9a65cb into main Dec 3, 2024
12 checks passed
@fx0x55 fx0x55 deleted the todd/bridge-call-quote branch December 3, 2024 00:57
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.

3 participants