-
Notifications
You must be signed in to change notification settings - Fork 117
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
Conversation
WalkthroughThe 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
TipsChat with CodeRabbit Bot (
|
There was a problem hiding this 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
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 asTestPremiumVotes
and also covers the case of a nil request and a valid request. The error handling and response checking are correctly implemented. As withTestPremiumVotes
, 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 theQueryClient
to make the request and handles any errors that might occur. The response is then printed usingPrintProto
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 toCmdQueryPremiumSamples
and is also well implemented. It creates a new cobra command to query premium votes. It uses theQueryClient
to make the request and handles any errors that might occur. The response is then printed usingPrintProto
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 inparams.proto
are used in the new RPC methods.24-40: Three new RPC methods are added:
PremiumVotes
,PremiumSamples
, andParams
. Ensure that these methods are implemented on the server side and that the routes specified in thegoogle.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
andParams
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
, andget-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
, andparams
methods are being bound to thethis
context in the constructor. This is a standard practice in JavaScript to ensure that the methods have the correctthis
context when they are invoked.43-63: New methods
premiumVotes
,premiumSamples
, andparams
have been added to theLCDQueryClient
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 theQueryClientImpl
class.30-32: The
this
context for the new methodspremiumVotes
,premiumSamples
, andparams
is being bound in the constructor ofQueryClientImpl
. This is a standard practice in JavaScript to ensure that the methods have the correctthis
context when they are invoked.49-65: Implementation of the new methods
premiumVotes
,premiumSamples
, andparams
in theQueryClientImpl
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
, andparams
are being added to thecreateRpcQueryExtension
function. This function creates an extension to the baseQueryClient
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
, andParamsSDKType
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.
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 | ||
} |
There was a problem hiding this comment.
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),
@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 |
There was a problem hiding this 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
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
Yes, looks like I swapped two digits in the ticket number in the title, sorry about that. This work is unrelated. |
Could you fill out PR template? |
There was a problem hiding this 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
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 theRunE
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 thequeryClient.PremiumSamples()
function fails. The result is then printed usingclientCtx.PrintProto(res)
. The function also correctly adds query flags to the command usingflags.AddQueryFlagsToCmd(cmd)
.34-55: The function
CmdQueryPremiumVotes()
is similar toCmdQueryPremiumSamples()
, 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 usingclientCtx.PrintProto(res)
, and query flags are added to the command usingflags.AddQueryFlagsToCmd(cmd)
.
(cherry picked from commit 32e52a5)
Changelist
Add gRPC and cli query commands to access perpetuals state.
Test Plan
Added cli, qRPC tests.
Author/Reviewer Checklist
state-breaking
label.PrepareProposal
orProcessProposal
, manually add the labelproposal-breaking
.feature:[feature-name]
.backport/[branch-name]
.refactor
,chore
,bug
.