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

[TRA-111] add vault query #1273

Merged
merged 2 commits into from
Mar 28, 2024
Merged

[TRA-111] add vault query #1273

merged 2 commits into from
Mar 28, 2024

Conversation

tqin7
Copy link
Contributor

@tqin7 tqin7 commented Mar 28, 2024

Changelist

add vault query

Test Plan

unit tests

Author/Reviewer Checklist

  • If this PR has changes that result in a different app state given the same prior state and transaction list, manually add the state-breaking label.
  • If the PR has breaking postgres changes to the indexer add the indexer-postgres-breaking label.
  • If this PR isn't state-breaking but has changes that modify behavior in PrepareProposal or ProcessProposal, manually add the label proposal-breaking.
  • If this PR is one of many that implement a specific feature, manually label them all feature:[feature-name].
  • If you wish to for mergify-bot to automatically create a PR to backport your change to a release branch, manually add the label backport/[branch-name].
  • Manually add any of the following labels: refactor, chore, bug.

Copy link

linear bot commented Mar 28, 2024

Copy link
Contributor

coderabbitai bot commented Mar 28, 2024

Warning

Rate Limit Exceeded

@tqin7 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 51 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 a99616b and 3ceb80c.

Walkthrough

The update introduces a new functionality for querying specific vaults by type and number across several components of the dYdX protocol. It encompasses adding necessary imports, defining new message types for the request and response, and implementing the query logic in both the command-line interface and the keeper package. Additionally, tests are added to ensure the new querying capability behaves as expected, verifying the retrieval of detailed vault information including ownership shares and vault metrics.

Changes

File(s) Change Summary
proto/dydxprotocol/vault/query.proto Added imports, a new RPC method Vault, and defined QueryVaultRequest, QueryVaultResponse, and OwnerShares.
protocol/x/vault/client/cli/query.go Added CmdQueryVault() function for CLI command to query a vault by type and number.
protocol/x/vault/keeper/grpc_query_vault.go Introduced Vault function to retrieve vault information, including shares, equity, and inventory.
protocol/x/vault/keeper/grpc_query_vault_test.go Added tests for the new vault querying functionality, including setup and verification of responses.

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-tests 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 tests 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 tests.
    • @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.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 31a0fb7 and 7651d51.
Files ignored due to path filters (2)
  • protocol/x/vault/types/query.pb.go is excluded by !**/*.pb.go
  • protocol/x/vault/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
Files selected for processing (4)
  • proto/dydxprotocol/vault/query.proto (3 hunks)
  • protocol/x/vault/client/cli/query.go (3 hunks)
  • protocol/x/vault/keeper/grpc_query_vault.go (1 hunks)
  • protocol/x/vault/keeper/grpc_query_vault_test.go (1 hunks)
Path instructions used (4)
proto/dydxprotocol/vault/query.proto (1)

/
Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/vault/client/cli/query.go (1)

/
Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/vault/keeper/grpc_query_vault.go (1)

/
Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

protocol/x/vault/keeper/grpc_query_vault_test.go (1)

/
Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

Additional comments (6)
proto/dydxprotocol/vault/query.proto (3)
  • 6-8: The addition of imports for dydxprotocol/subaccounts/subaccount.proto and dydxprotocol/vault/vault.proto is appropriate for the new functionality being introduced. These imports are necessary for the new message types and RPC method that facilitate querying vaults by type and number.
  • 18-21: The new RPC method Vault within the Query service is well-defined, with a clear HTTP GET path specified. This method allows querying a vault by its type and number, which aligns with the PR's objective to enhance querying capabilities. Ensure that the specified path /dydxprotocol/v4/vault/vaults/{type}/{number} is correctly implemented in the server-side routing to handle these requests.
Verification successful

The verification process successfully identified the specified HTTP GET path /dydxprotocol/v4/vault/vaults/{type}/{number} within the proto/dydxprotocol/vault/query.proto file, as intended in the review comment. This confirms that the new RPC method Vault is correctly defined with the intended path in the proto file. No issues were found regarding the definition of the RPC method and its path in the server-side routing.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Verify the server-side routing for the new RPC method
rg --type proto "/dydxprotocol/v4/vault/vaults/{type}/{number}"

Length of output: 224



Script:

#!/bin/bash
# Verify the server-side routing for the new RPC method with corrected regex pattern
rg --type proto '/dydxprotocol/v4/vault/vaults/\{type\}/\{number\}'

Length of output: 99



Script:

#!/bin/bash
# Verify the server-side routing for the new RPC method without using the --type filter and specifying .proto extension
rg '/dydxprotocol/v4/vault/vaults/\{type\}/\{number\}' --glob '*.proto'

Length of output: 194

* 32-52: The new message types `QueryVaultRequest`, `QueryVaultResponse`, and `OwnerShares` are well-defined and align with the functionality required for querying vaults. These message types are crucial for the request-response cycle of the new `Vault` RPC method. It's important to ensure that these message types are used consistently across the implementation, particularly in the keeper and CLI command implementations.
protocol/x/vault/client/cli/query.go (1)
  • 55-98: The implementation of CmdQueryVault() is comprehensive, covering the parsing of command-line arguments for vault type and number, and the querying logic to interact with the protocol's querying service. A few points to consider:
  • The switch statement for parsing the vault type currently only supports the "clob" type. If the protocol plans to support more vault types in the future, consider making this parsing more extensible.
  • Error messages are clear and informative, which is good practice for CLI tools.
  • The use of strconv.ParseUint for parsing the vault number is appropriate. Ensure that the vault number's range is within acceptable limits for the protocol.

Overall, the command is well-implemented and aligns with the PR's objectives.

protocol/x/vault/keeper/grpc_query_vault.go (1)
  • 17-77: The Vault function in the keeper package is well-structured and covers several key aspects of vault querying, including total shares, owner shares, vault equity, and vault inventory. Points to consider:
  • The error handling is comprehensive, with clear error messages for different failure scenarios.
  • The use of storetypes.KVStorePrefixIterator for iterating over owner shares is appropriate. Ensure that the key format used for owner shares is consistent across the protocol.
  • Sorting owner shares by the number of shares is a useful feature for clients. Consider documenting this behavior in the API documentation.
  • The retrieval of vault inventory involves casting to a specific ClobPair metadata type. Ensure that this casting is safe and that the ClobPair structure is guaranteed to have the expected metadata format.

Overall, the function is well-implemented and aligns with the PR's objectives.

protocol/x/vault/keeper/grpc_query_vault_test.go (1)
  • 17-156: The test cases for the Vault function are comprehensive and cover various scenarios, including successful querying, querying a non-existent vault, and handling a nil request. Points to consider:
  • The setup for each test case is thorough, including setting total shares and owner shares. This ensures that the function is tested under realistic conditions.
  • The use of require.NoError and require.ErrorContains for assertions is appropriate and ensures that the function's error handling is correctly implemented.
  • The assertions for the expected response in successful cases are detailed, checking each field of the QueryVaultResponse. This thoroughness is commendable.

Overall, the test cases are well-implemented and provide good coverage for the new querying functionality.

uint64 equity = 3;
uint64 inventory = 4;
uint64 total_shares = 5;
repeated OwnerShares all_owner_shares = 6 [ (gogoproto.nullable) = false ];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Might be better to have a separate paginated query for this considering there may be many owners.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense. created a ticket to add a separate query for owner shares. let me remove owner shares for now

Copy link
Contributor

Choose a reason for hiding this comment

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

Non-blocking, I see that the owner shares are stored as only integers, and not a struct with both the owner + the shares so it won't be as simple as using query.Paginate on the store.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep will add a separate query for owner shares in phase 2

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 31a0fb7 and a99616b.
Files ignored due to path filters (2)
  • protocol/x/vault/types/query.pb.go is excluded by !**/*.pb.go
  • protocol/x/vault/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
Files selected for processing (7)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.lcd.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.rpc.Query.ts (2 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (3 hunks)
  • proto/dydxprotocol/vault/query.proto (3 hunks)
  • protocol/x/vault/client/cli/query.go (3 hunks)
  • protocol/x/vault/keeper/grpc_query_vault.go (1 hunks)
  • protocol/x/vault/keeper/grpc_query_vault_test.go (1 hunks)
Path instructions used (3)
indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.lcd.ts (1)

/
Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.rpc.Query.ts (1)

/
Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (1)

/
Do not include a walkthrough. For all comments on line changes that are longer than 15 lines, add a prefix to the comment of what lines you are commenting on (for example: "The changes from lines 100 to 200...". Add your comment to be on the last 15 lines of the chunk rather than adding your comment to the entire chunk.

Files skipped from review as they are similar to previous changes (4)
  • proto/dydxprotocol/vault/query.proto
  • protocol/x/vault/client/cli/query.go
  • protocol/x/vault/keeper/grpc_query_vault.go
  • protocol/x/vault/keeper/grpc_query_vault_test.go
Additional comments (7)
indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.lcd.ts (1)
  • 25-27: The implementation of the vault method in the LCDQueryClient class looks good. It correctly constructs the endpoint URL dynamically and uses the req.get method to perform the query.

However, consider adding a comment about error handling practices for this method, especially if there are specific expectations for how errors should be managed by the calling code or if there's any fallback mechanism within req.get.

indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.rpc.Query.ts (3)
  • 10-12: The addition of the vault method to the Query interface is correctly implemented, with appropriate request and response types specified.
  • 29-33: The implementation of the vault method in the QueryClientImpl class follows the established pattern for RPC calls, correctly using encode and decode for handling the request and response.

Consider adding a comment about error handling practices for this method, especially regarding how errors from the RPC request are expected to be managed.

  • 44-45: The update to the createRpcQueryExtension function to include the vault method is correctly implemented, aligning with the design of extending the querying capabilities of the protocol.
indexer/packages/v4-protos/src/codegen/dydxprotocol/vault/query.ts (3)
  • 1-3: The new imports for VaultType, VaultId, and SubaccountId are correctly referenced and necessary for the types used in the updated and new interfaces.
  • 22-65: The updates to the QueryVaultRequest and QueryVaultResponse interfaces, along with the addition of the OwnerShares interface, are correctly implemented. These changes are logically structured and use appropriate types for the new fields.

Consider adding comments to the new fields in these interfaces for better clarity and documentation, especially for fields like equity, inventory, and allOwnerShares in the QueryVaultResponse interface.

  • 146-348: The encoding and decoding functions for QueryVaultRequest, QueryVaultResponse, and OwnerShares are correctly implemented, following the established pattern for handling protobuf data. They correctly manage the new fields and are consistent with the usage of protobufjs.

@tqin7 tqin7 merged commit 56761ac into main Mar 28, 2024
32 checks passed
@tqin7 tqin7 deleted the tq/tra-111 branch March 28, 2024 19:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants