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

[CORE-695] - add queries for x/perpetuals state #686

Merged
merged 5 commits into from
Oct 26, 2023

Conversation

clemire
Copy link
Contributor

@clemire clemire commented Oct 23, 2023

Changelist

Add gRPC and cli query commands to access perpetuals state.

Test Plan

Added cli, qRPC 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 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.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 23, 2023

Walkthrough

The changes introduce new functionalities to query premium votes, premium samples, and perpetual parameters in the dydxprotocol. These functionalities are implemented across different layers of the application, including the gRPC layer, the CLI layer, and the keeper layer. The changes also include corresponding tests for the new functionalities.

Changes

File(s) Summary
.../v4-protos/src/codegen/dydxprotocol/perpetuals/query.* Added new functions to the LCDQueryClient and QueryClientImpl classes for querying premium votes, premium samples, and perpetual params. Also, added corresponding interfaces and functions.
proto/dydxprotocol/perpetuals/query.proto Introduced new RPC methods for querying premium votes, premium samples, and perpetual params.
protocol/x/perpetuals/client/cli/query_*.go Added new commands to the CLI for querying premium votes, premium samples, and perpetual params.
protocol/x/perpetuals/client/cli/query_*_test.go Added tests for the new CLI commands.
protocol/x/perpetuals/keeper/grpc_query_*.go Introduced new functions in the keeper package for handling queries related to premium votes, premium samples, and perpetual params.
protocol/x/perpetuals/keeper/grpc_query_*_test.go Added tests for the new keeper functions.
protocol/x/perpetuals/module_test.go Modified the GetQueryCmd function in the AppModuleBasic struct to update the expected number of commands and their names.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

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 help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

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.json

@clemire clemire marked this pull request as ready for review October 23, 2023 22:03
@clemire clemire changed the title [CORE-659] - add queries for x/perpetuls state [CORE-659] - add queries for x/perpetuals state Oct 23, 2023
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: 1

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between cba238d and c72cbf7.
Files ignored due to filter (2)
  • protocol/x/perpetuals/types/query.pb.go
  • protocol/x/perpetuals/types/query.pb.gw.go
Files selected for processing (14)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/query.lcd.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/query.rpc.Query.ts (5 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/query.ts (3 hunks)
  • proto/dydxprotocol/perpetuals/query.proto (3 hunks)
  • protocol/x/perpetuals/client/cli/query.go (1 hunks)
  • protocol/x/perpetuals/client/cli/query_params.go (1 hunks)
  • protocol/x/perpetuals/client/cli/query_params_test.go (1 hunks)
  • protocol/x/perpetuals/client/cli/query_premiums.go (1 hunks)
  • protocol/x/perpetuals/client/cli/query_premiums_test.go (1 hunks)
  • protocol/x/perpetuals/keeper/grpc_query_params.go (1 hunks)
  • protocol/x/perpetuals/keeper/grpc_query_params_test.go (1 hunks)
  • protocol/x/perpetuals/keeper/grpc_query_premiums.go (1 hunks)
  • protocol/x/perpetuals/keeper/grpc_query_premiums_test.go (1 hunks)
  • protocol/x/perpetuals/module_test.go (1 hunks)
Files skipped from review due to trivial changes (6)
  • protocol/x/perpetuals/client/cli/query.go
  • protocol/x/perpetuals/client/cli/query_params_test.go
  • protocol/x/perpetuals/client/cli/query_premiums_test.go
  • protocol/x/perpetuals/keeper/grpc_query_params.go
  • protocol/x/perpetuals/keeper/grpc_query_params_test.go
  • protocol/x/perpetuals/keeper/grpc_query_premiums.go
Additional comments: 19
protocol/x/perpetuals/keeper/grpc_query_premiums_test.go (2)
  • 13-44: The test TestPremiumVotes is well structured and covers both the case of a nil request and a valid request. The error handling and response checking are correctly implemented. However, it would be beneficial to add more test cases to cover different scenarios, such as invalid requests or edge cases.

  • 46-77: The test TestPremiumSamples follows the same structure as TestPremiumVotes and also covers the case of a nil request and a valid request. The error handling and response checking are correctly implemented. As with TestPremiumVotes, it would be beneficial to add more test cases to cover different scenarios, such as invalid requests or edge cases.

protocol/x/perpetuals/client/cli/query_premiums.go (2)
  • 11-32: The function CmdQueryPremiumSamples is well implemented. It creates a new cobra command to query premium samples. It uses the QueryClient to make the request and handles any errors that might occur. The response is then printed using PrintProto method. The function also adds query flags to the command. This is a good practice as it allows users to customize their queries.

  • 34-55: The function CmdQueryPremiumVotes is similar to CmdQueryPremiumSamples and is also well implemented. It creates a new cobra command to query premium votes. It uses the QueryClient to make the request and handles any errors that might occur. The response is then printed using PrintProto method. The function also adds query flags to the command. This is a good practice as it allows users to customize their queries.

proto/dydxprotocol/perpetuals/query.proto (3)
  • 7-7: The import of params.proto is new. Ensure that this file exists and is accessible from the current path. Also, verify that the definitions in params.proto are used in the new RPC methods.

  • 24-40: Three new RPC methods are added: PremiumVotes, PremiumSamples, and Params. Ensure that these methods are implemented on the server side and that the routes specified in the google.api.http options are correctly set up in the server's routing configuration.

  • 62-87: New message types are defined for the request and response of each new RPC method. Ensure that these message types are used correctly in the implementation of the RPC methods. Also, verify that the PremiumStore and Params types are defined elsewhere in the codebase.

protocol/x/perpetuals/module_test.go (1)
  • 247-252: The number of commands in the cmd object has increased from 2 to 5, and three new commands have been added: get-params, get-premium-samples, and get-premium-votes. Ensure that these new commands are implemented correctly and that they are working as expected. Also, verify that these new commands are documented and that their usage is clear to the end-users.
indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/query.lcd.ts (3)
  • 3-3: The import statement has been updated to include new types related to premium votes, premium samples, and perpetual parameters. Ensure that these new types are defined correctly and are being used appropriately in the new methods.

  • 15-17: The premiumVotes, premiumSamples, and params methods are being bound to the this context in the constructor. This is a standard practice in JavaScript to ensure that the methods have the correct this context when they are invoked.

  • 43-63: New methods premiumVotes, premiumSamples, and params have been added to the LCDQueryClient class. These methods are used to query premium votes, premium samples, and perpetual parameters respectively. They construct the appropriate endpoint URL and send a GET request to the LCD client to retrieve the data. Each method returns a promise that resolves to the corresponding response type. Ensure that these new methods are being used correctly in the application and that the endpoints they are hitting are set up properly.

indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/query.rpc.Query.ts (5)
  • 4-4: The import statement has been updated to include new request and response types related to premium votes, premium samples, and perpetual parameters. Ensure that these new types are defined correctly and are being used appropriately in the new functions.

  • 13-21: New methods have been added to the Query interface for querying premium votes, premium samples, and perpetual parameters. Ensure that these methods are implemented correctly in the QueryClientImpl class.

  • 30-32: The this context for the new methods premiumVotes, premiumSamples, and params is being bound in the constructor of QueryClientImpl. This is a standard practice in JavaScript to ensure that the methods have the correct this context when they are invoked.

  • 49-65: Implementation of the new methods premiumVotes, premiumSamples, and params in the QueryClientImpl class. These methods encode the request, make the RPC request, and then decode the response. Ensure that the RPC request is being made to the correct service and method, and that the request and response are being encoded and decoded correctly.

  • 78-89: The new methods premiumVotes, premiumSamples, and params are being added to the createRpcQueryExtension function. This function creates an extension to the base QueryClient with the query functions. Ensure that these new methods are being added correctly and that they work as expected.

indexer/packages/v4-protos/src/codegen/dydxprotocol/perpetuals/query.ts (3)
  • 2-3: The new imports PremiumStore, PremiumStoreSDKType, Params, and ParamsSDKType are added to support the new functionalities for querying premium votes, premium samples, and perpetual parameters. Ensure these new imports are used correctly throughout the code.

  • 50-115: New interfaces QueryPremiumVotesRequest, QueryPremiumVotesRequestSDKType, QueryPremiumVotesResponse, QueryPremiumVotesResponseSDKType, QueryPremiumSamplesRequest, QueryPremiumSamplesRequestSDKType, QueryPremiumSamplesResponse, QueryPremiumSamplesResponseSDKType, QueryParamsRequest, QueryParamsRequestSDKType, QueryParamsResponse, QueryParamsResponseSDKType are added to handle the new RPC methods for querying premium votes, premium samples, and perpetual parameters. Make sure these interfaces are correctly implemented in the corresponding RPC methods.

  • 305-541: New functions createBaseQueryPremiumVotesRequest, createBaseQueryPremiumVotesResponse, createBaseQueryPremiumSamplesRequest, createBaseQueryPremiumSamplesResponse, createBaseQueryParamsRequest, createBaseQueryParamsResponse are added to create base request and response objects for the new RPC methods. Also, encoding, decoding, and partial object creation functions are added for these new request and response types. Ensure these functions are correctly used in the corresponding RPC methods.

Comment on lines +11 to +32
func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "get-params",
Short: "get the Params",
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
queryClient := types.NewQueryClient(clientCtx)
res, err := queryClient.Params(
context.Background(),
&types.QueryParamsRequest{},
)
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.

The function CmdQueryParams is well implemented. It creates a new cobra command that queries the Params from the x/perpetuals module. The error handling is also done correctly. However, it would be better to use a specific context with a timeout instead of context.Background(). This is to prevent potential blocking of the program if the queryClient.Params call takes too long.

- context.Background(),
+ context.WithTimeout(context.Background(), 5*time.Second),

@ttl33
Copy link
Contributor

ttl33 commented Oct 24, 2023

@clemire can you link this PR to a different linear ticket and close out the "audit" ticket? I think we should track this work 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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between c72cbf7 and 1d815a8.
Files selected for processing (1)
  • protocol/x/perpetuals/client/cli/query_premiums_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/perpetuals/client/cli/query_premiums_test.go

@clemire clemire changed the title [CORE-659] - add queries for x/perpetuals state [CORE-695] - add queries for x/perpetuals state Oct 24, 2023
@dydxprotocol dydxprotocol deleted a comment from linear bot Oct 24, 2023
@clemire
Copy link
Contributor Author

clemire commented Oct 24, 2023

@clemire clemire changed the title [CORE-695] - add queries for x/perpetuals state - add queries for x/perpetuals state Oct 24, 2023
@clemire clemire changed the title - add queries for x/perpetuals state [CORE-695] - add queries for x/perpetuals state Oct 24, 2023
@clemire
Copy link
Contributor Author

clemire commented Oct 24, 2023

@clemire can you link this PR to a different linear ticket and close out the "audit" ticket? I think we should track this work separately

Yes, looks like I swapped two digits in the ticket number in the title, sorry about that. This work is unrelated.

@teddyding
Copy link
Contributor

Could you fill out PR template?

@clemire clemire added the backport/protocol/v1.x Backport v1.x label Oct 26, 2023
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 1d815a8 and a85b94b.
Files selected for processing (1)
  • protocol/x/perpetuals/client/cli/query_premiums.go (1} hunks)
Additional comments: 2
protocol/x/perpetuals/client/cli/query_premiums.go (2)
  • 11-32: The function CmdQueryPremiumSamples() is well written and follows the best practices for creating a Cobra command. It uses the RunE field to define the command's action, which is to query premium samples from the current funding-tick epoch. The error handling is also done correctly, where it returns the error if the queryClient.PremiumSamples() function fails. The result is then printed using clientCtx.PrintProto(res). The function also correctly adds query flags to the command using flags.AddQueryFlagsToCmd(cmd).

  • 34-55: The function CmdQueryPremiumVotes() is similar to CmdQueryPremiumSamples(), but it queries premium votes from the current funding-sample epoch. The structure and error handling are done correctly, similar to the previous function. The result is printed using clientCtx.PrintProto(res), and query flags are added to the command using flags.AddQueryFlagsToCmd(cmd).

@clemire clemire merged commit 32e52a5 into main Oct 26, 2023
31 checks passed
@clemire clemire deleted the crystal/CORE-695-perpetuals branch October 26, 2023 20:20
mergify bot pushed a commit that referenced this pull request Oct 26, 2023
clemire added a commit that referenced this pull request Oct 26, 2023
Co-authored-by: Crystal Lemire <crystal.lemire@gmail.com>
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