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(accountplus): Add query for accountplus account state #2659

Merged
merged 3 commits into from
Dec 16, 2024

Conversation

teddyding
Copy link
Contributor

@teddyding teddyding commented Dec 16, 2024

Changelist

Add query for x/accountplus account state

Test Plan

Testing on localnet

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.

Summary by CodeRabbit

  • New Features

    • Introduced a new command to query account state via the CLI.
    • Added functionality to retrieve account state in the Keeper struct.
    • Implemented a new RPC method for account state queries in the protocol.
    • Enhanced LCDQueryClient with an asynchronous method to query account states.
    • Added new interfaces for account state requests and responses.
  • Bug Fixes

    • Improved error handling for account state requests.
  • Documentation

    • Updated documentation to reflect new methods and interfaces related to account state queries.

@teddyding teddyding marked this pull request as ready for review December 16, 2024 14:55
@teddyding teddyding requested a review from a team as a code owner December 16, 2024 14:55
Copy link
Contributor

coderabbitai bot commented Dec 16, 2024

Walkthrough

This pull request introduces a new accountState method across multiple components of the dYdX protocol, enabling querying of account states. The changes span from protocol buffers (proto) to the indexer, CLI, and keeper implementations. The new functionality allows retrieving account state information using an account address, with implementations added to the RPC, LCD query client, and CLI interfaces.

Changes

File Change Summary
indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.lcd.ts Added accountState method to LCDQueryClient, updated import statements to include AccountStateRequest and AccountStateResponseSDKType
indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.rpc.Query.ts Added accountState method to Query interface and QueryClientImpl, updated import statements for AccountStateRequest and AccountStateResponse
indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.ts Introduced new interfaces: AccountStateRequest, AccountStateResponse and their SDK types
proto/dydxprotocol/accountplus/query.proto Added new RPC method AccountState and corresponding request/response message types
protocol/x/accountplus/client/cli/query.go Added CmdQueryAccountState CLI command for querying account state
protocol/x/accountplus/keeper/query.go Implemented AccountState method in the keeper to return account state

Possibly related PRs

Poem

🐰 A rabbit's tale of state so bright,
Querying accounts with pure delight,
Address in hand, secrets unfurl,
Through proto and CLI, our code we twirl,
Account state dancing, clear and light! 🔍

Tip

CodeRabbit's docstrings feature is now available as part of our Early Access Program! Simply use the command @coderabbitai generate docstrings to have CodeRabbit automatically generate docstrings for your pull request.


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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

@@ -114,3 +114,30 @@ func CmdQueryGetAllAuthenticators() *cobra.Command {
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func CmdQueryAccountState() *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

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

think you need to add this to the GetQueryCmd above

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: 1

🧹 Nitpick comments (3)
proto/dydxprotocol/accountplus/query.proto (1)

40-45: Fix comment prefix in AccountStateResponse

The comment incorrectly uses "Get" prefix while the RPC method is named "AccountState".

-// AccountStateResponse is request type for the Query/AccountState RPC method.
+// AccountStateRequest is request type for the Query/AccountState RPC method.

-// GetAccountStateResponse is response type for the Query/GetAccountState RPC
+// AccountStateResponse is response type for the Query/AccountState RPC
// method.
protocol/x/accountplus/client/cli/query.go (1)

120-122: Fix typo in command description.

There's a typo in the Short description: "Geta account state" should be "Get account state".

-		Short: "Geta account state for an address",
+		Short: "Get account state for an address",
indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.ts (1)

6-41: Fix incorrect comment placement and content.

There are several issues with the comments:

  1. The comment above AccountStateRequest incorrectly states it's a response type
  2. The same incorrect comment is repeated multiple times
  3. Comments for AccountStateResponse mention "GetAccountState" instead of "AccountState"

Apply these documentation fixes:

-/** AccountStateResponse is request type for the Query/AccountState RPC method. */
+/** AccountStateRequest is request type for the Query/AccountState RPC method. */
 export interface AccountStateRequest {
-  /** AccountStateResponse is request type for the Query/AccountState RPC method. */
   address: string;
 }
-/** AccountStateResponse is request type for the Query/AccountState RPC method. */
+/** AccountStateRequestSDKType is the SDK type for AccountStateRequest */
 export interface AccountStateRequestSDKType {
-  /** AccountStateResponse is request type for the Query/AccountState RPC method. */
   address: string;
 }
 /**
- * GetAccountStateResponse is response type for the Query/GetAccountState RPC
+ * AccountStateResponse is response type for the Query/AccountState RPC
  * method.
  */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7117942 and a1b42e8.

⛔ Files ignored due to path filters (2)
  • protocol/x/accountplus/types/query.pb.go is excluded by !**/*.pb.go
  • protocol/x/accountplus/types/query.pb.gw.go is excluded by !**/*.pb.gw.go
📒 Files selected for processing (6)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.lcd.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.rpc.Query.ts (5 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.ts (2 hunks)
  • proto/dydxprotocol/accountplus/query.proto (2 hunks)
  • protocol/x/accountplus/client/cli/query.go (1 hunks)
  • protocol/x/accountplus/keeper/query.go (1 hunks)
🔇 Additional comments (6)
indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.lcd.ts (1)

2-2: LGTM! Implementation follows established patterns

The LCD client implementation for the account state query is consistent with existing patterns:

  • Proper type imports
  • Constructor binding
  • Endpoint construction matches proto definition

Also applies to: 15-15, 38-44

proto/dydxprotocol/accountplus/query.proto (1)

6-6: LGTM! RPC definition follows best practices

The AccountState RPC method is well-defined with:

  • Clear description
  • Proper HTTP mapping
  • Consistent path structure

Also applies to: 32-37

protocol/x/accountplus/keeper/query.go (1)

71-92: Verify handling of non-existent accounts

The implementation has two potential issues:

  1. Line 87: The found status from GetAccountState is ignored, which could be useful for distinguishing between non-existent accounts and accounts with empty state
  2. Line 90: Returning a pointer to accountState could result in nil if the account doesn't exist

Consider either:

  1. Including the found status in the response, or
  2. Returning a clear error for non-existent accounts
✅ Verification successful

Let me try a different search pattern to find the relevant usage of GetAccountState.


Let me try one more search to find the implementation of GetAccountState in the keeper.


Based on the implementation found, I can now provide a final response:

Current handling of non-existent accounts is appropriate

The implementation is correct as is, because:

  1. The underlying GetAccountState method in the keeper properly handles non-existent accounts by returning (AccountState{}, false)
  2. Returning a pointer to an empty AccountState in the query response is a valid pattern for representing non-existent accounts, as it's consistent with protobuf's handling of optional fields
  3. The found status can be safely ignored since an empty/zero-valued AccountState already indicates the account doesn't exist
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if GetAccountState is used elsewhere to understand standard error handling
ast-grep --pattern 'GetAccountState($_, $_)'

Length of output: 31298


Script:

#!/bin/bash
# Search for GetAccountState method definition and usage
ast-grep --pattern 'GetAccountState($_, $_)'
rg -A 5 'GetAccountState'

Length of output: 37870


Script:

#!/bin/bash
# Search for GetAccountState implementation
rg -A 10 "func.*GetAccountState"

Length of output: 1492

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

16-18: LGTM! Documentation and method signature are well-defined.

The new accountState method in the Query interface follows the established pattern and includes clear documentation.


49-53: LGTM! Implementation follows the standard RPC pattern.

The implementation correctly:

  • Encodes the request
  • Makes the RPC call
  • Decodes the response
indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.ts (1)

105-193: LGTM! Encoding and decoding implementation is correct.

The implementation follows the protobuf encoding/decoding pattern consistently:

  • Proper handling of optional fields
  • Correct wire format encoding
  • Proper error handling for unknown fields

Comment on lines 117 to 143

func CmdQueryAccountState() *cobra.Command {
cmd := &cobra.Command{
Use: "account-state [address]",
Short: "Geta account state for an address",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.AccountState(
context.Background(),
&types.AccountStateRequest{
Address: args[0],
},
)
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}
flags.AddQueryFlagsToCmd(cmd)
return cmd
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add command to the GetQueryCmd function.

The new command needs to be added to the command list in the GetQueryCmd function to make it available in the CLI.

Add the following line to the cmd.AddCommand call in GetQueryCmd:

 	cmd.AddCommand(
 		CmdQueryParam(),
 		CmdQueryGetAuthenticator(),
 		CmdQueryGetAllAuthenticators(),
+		CmdQueryAccountState(),
 	)

Committable suggestion skipped: line range outside the PR's diff.

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

🧹 Nitpick comments (5)
proto/dydxprotocol/accountplus/query.proto (2)

32-37: LGTM! Consider adding more detailed documentation.

The RPC method is well-defined with a proper REST endpoint mapping. Consider adding more detailed documentation about the expected behavior when the account doesn't exist.


40-45: Consider adding field validation for the address.

The message definitions are correct. Consider adding field validation for the address using protobuf field options (e.g., regex pattern for bech32 addresses).

-  string address = 1;
+  string address = 1 [(gogoproto.moretags) = "validate:\"bech32\""];
protocol/x/accountplus/keeper/query.go (2)

76-78: Consider using a more specific error message.

The error message could be more descriptive to help clients understand what was missing.

-		return nil, status.Error(codes.InvalidArgument, "empty request")
+		return nil, status.Error(codes.InvalidArgument, "account state request cannot be nil")

85-91: Consider documenting the behavior for non-existent accounts.

The code correctly handles non-existent accounts by returning an empty state, but this behavior should be documented in the comments.

-	// GetAccountState returns `empty, false` AccountState if the account does not exist.
+	// GetAccountState returns `empty, false` AccountState if the account does not exist.
+	// Note: We return the empty state to clients when the account doesn't exist instead of an error.
indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.ts (1)

8-41: Consider adding JSDoc comments for better documentation.

The type definitions are correct but would benefit from JSDoc comments describing the purpose and usage of each interface.

+/**
+ * Request type for querying an account's state by address.
+ * @property address - The bech32-encoded address of the account
+ */
 export interface AccountStateRequest {
   address: string;
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 81bb5f3 and 02c6cb5.

⛔ Files ignored due to path filters (1)
  • protocol/x/accountplus/types/query.pb.go is excluded by !**/*.pb.go
📒 Files selected for processing (4)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.ts (2 hunks)
  • proto/dydxprotocol/accountplus/query.proto (2 hunks)
  • protocol/x/accountplus/client/cli/query.go (2 hunks)
  • protocol/x/accountplus/keeper/query.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • protocol/x/accountplus/client/cli/query.go
🔇 Additional comments (4)
proto/dydxprotocol/accountplus/query.proto (1)

6-6: LGTM!

The import for accountplus.proto is correctly added to access the AccountState type.

protocol/x/accountplus/keeper/query.go (1)

80-83: LGTM!

The address validation is properly implemented with appropriate error handling.

indexer/packages/v4-protos/src/codegen/dydxprotocol/accountplus/query.ts (2)

105-109: LGTM!

The base object creation functions properly initialize default values for both request and response types.

Also applies to: 150-154


111-193: LGTM!

The encode/decode methods are correctly implemented with proper handling of optional fields and protobuf wire format.

@teddyding teddyding merged commit 5fd53fc into main Dec 16, 2024
38 checks passed
@teddyding teddyding deleted the td/query-accountplus-state branch December 16, 2024 15:59
@teddyding
Copy link
Contributor Author

@Mergifyio backport release/protocol/v8.x

@teddyding
Copy link
Contributor Author

@Mergifyio backport release/protocol/v7.x

Copy link
Contributor

mergify bot commented Dec 16, 2024

backport release/protocol/v8.x

✅ Backports have been created

Copy link
Contributor

mergify bot commented Dec 16, 2024

backport release/protocol/v7.x

✅ Backports have been created

mergify bot pushed a commit that referenced this pull request Dec 16, 2024
(cherry picked from commit 5fd53fc)

# Conflicts:
#	protocol/x/accountplus/client/cli/query.go
mergify bot pushed a commit that referenced this pull request Dec 16, 2024
teddyding added a commit that referenced this pull request Dec 16, 2024
@jayy04
Copy link
Contributor

jayy04 commented Dec 16, 2024

@Mergifyio backport jy/v8_upgrade_test

Copy link
Contributor

mergify bot commented Dec 16, 2024

backport jy/v8_upgrade_test

✅ Backports have been created

  • Backport to branch jy/v8_upgrade_test not needed, change already in branch jy/v8_upgrade_test

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.

3 participants