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-700] - P1 clob queries for existing StatefulOrder keeper methods #676

Closed
wants to merge 4 commits into from

Conversation

clemire
Copy link
Contributor

@clemire clemire commented Oct 20, 2023

Changelist

Add cli query commands, grpc endpoints for AllStatefulOrders, and StatefulOrderCount (by subaccount).

Test Plan

normal tests: query client method, gRPC query tests, cli 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.

…odegen via typescript due to nested fields in request message.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 20, 2023

Walkthrough

The changes introduce new functionality for querying stateful orders in the application. This includes new request and response types, commands for listing all stateful orders and getting the count of stateful orders for a specific subaccount, and corresponding tests. The command signature for showing a specific subaccount has also been updated to be more descriptive.

Changes

File Summary
.../v4-protos/src/codegen/dydxprotocol/clob/query.ts Added new request and response types for querying stateful orders.
protocol/x/clob/client/cli/query_stateful_orders.go Added two new commands: CmdListStatefulOrders and CmdGetStatefulOrderCount for interacting with stateful orders.
protocol/x/clob/keeper/grpc_query_stateful_orders.go Introduced two new functions: AllStatefulOrders and StatefulOrderCount for retrieving stateful order data.
protocol/x/clob/module_test.go Updated the length of cmd.Commands() and added two new commands.
protocol/x/subaccounts/client/cli/query_subaccount.go Updated the command signature for CmdShowSubaccount.
protocol/x/clob/client/cli/query_stateful_orders_test.go Added tests for the new commands CmdListStatefulOrders and CmdGetStatefulOrderCount.
proto/dydxprotocol/clob/query.proto Added new RPC methods and message types for querying stateful orders.

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.

CodeRabbit Commands

  • Enter @coderabbitai pause as a PR comment to pause the reviews on a PR.
  • Enter @coderabbitai resume as a PR comment to resume the paused reviews.
  • For on-demand reviews, enter @coderabbitai review as a PR comment to trigger a review. This is useful when reviews are automatic disabled at the repository level.
  • Enter @coderabbitai: ignore in the PR description to stop a specific PR from being reviewed.

Note these commands work only in the PR comment. For conversations with the bot, please use the review comments on code diffs or files.

}

// Queries the count of all stateful orders.
rpc StatefulOrderCount(QueryStatefulOrderCountRequest)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

no http transcoding here because the request is uniquely identified by the subaccount. when I added an http path that selected on the subaccount message, go proto-gen compiled without issues, but telescope barfed.

Copy link
Contributor

Choose a reason for hiding this comment

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

for my understanding - what will this endpoint be used for?

this is not something that is in the consensus state

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See Jonathan's comment here


// Expect no stateful orders.
require.Equal(t, types.QueryAllStatefulOrdersResponse{
StatefulOrders: []types.Order{},
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Asking about how to populate clob with stateful orders via a network test here.

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

Commits Files that changed from the base of the PR and between 07b6102 and 76babe7.
Files ignored due to filter (2)
  • protocol/x/clob/types/query.pb.go
  • protocol/x/clob/types/query.pb.gw.go
Files selected for processing (12)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.lcd.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.rpc.Query.ts (5 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts (3 hunks)
  • proto/dydxprotocol/clob/query.proto (3 hunks)
  • protocol/mocks/QueryClient.go (2 hunks)
  • protocol/x/clob/client/cli/query.go (1 hunks)
  • protocol/x/clob/client/cli/query_stateful_orders.go (1 hunks)
  • protocol/x/clob/client/cli/query_stateful_orders_test.go (1 hunks)
  • protocol/x/clob/keeper/grpc_query_stateful_orders.go (1 hunks)
  • protocol/x/clob/keeper/grpc_query_stateful_orders_test.go (1 hunks)
  • protocol/x/clob/module_test.go (1 hunks)
  • protocol/x/subaccounts/client/cli/query_subaccount.go (1 hunks)
Files not summarized due to errors (7)
  • protocol/x/clob/keeper/grpc_query_stateful_orders_test.go: Error: Server error
  • protocol/x/clob/client/cli/query.go: Error: Server error
  • protocol/mocks/QueryClient.go: Error: Server error
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.lcd.ts: Error: Server error
  • proto/dydxprotocol/clob/query.proto: Error: Server error
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.rpc.Query.ts: Error: Server error
  • protocol/x/clob/client/cli/query_stateful_orders_test.go: Error: Server error
Files skipped from review due to trivial changes (1)
  • protocol/x/clob/keeper/grpc_query_stateful_orders.go
Additional comments (Suppressed): 25
protocol/x/clob/client/cli/query.go (1)
  • 26-27: The addition of CmdListStatefulOrders() and CmdGetStatefulOrderCount() commands to the cmd object is a good way to extend the functionality of the CLI. Ensure that these new commands are properly documented and tested. Also, verify that these commands are working as expected in the CLI after the changes.
protocol/x/clob/client/cli/query_stateful_orders_test.go (2)
  • 16-35: The test TestCmdListStatefulOrders is well written and covers the basic functionality of the CmdListStatefulOrders command. It checks that the command executes without errors and that it returns an empty list of stateful orders, which is the expected behavior in this test setup.

  • 37-58: The test TestCmdGetStatefulOrderCount is also well written and covers the basic functionality of the CmdGetStatefulOrderCount command. It checks that the command executes without errors and that it returns a count of 0 for stateful orders, which is the expected behavior in this test setup.

protocol/x/clob/keeper/grpc_query_stateful_orders_test.go (5)
  • 16-43: The populateStatefulOrders function is a helper function that sets up the test environment by adding stateful orders to the keeper. It adds a long-term order, a triggered conditional order, and an untriggered conditional order. This function is used in both TestAllStatefulOrders and TestStatefulOrderCount to ensure a consistent test environment.

  • 45-82: The TestAllStatefulOrders function tests the AllStatefulOrders function of the ClobKeeper. It checks for two scenarios: when the request is nil and when the request is successful. In the nil request scenario, it expects an error. In the successful request scenario, it expects a response containing all the stateful orders that were added in the populateStatefulOrders function.

  • 84-118: The TestStatefulOrderCount function tests the StatefulOrderCount function of the ClobKeeper. It checks for two scenarios: when the request is nil and when the request is successful. In the nil request scenario, it expects an error. In the successful request scenario, it expects a response containing the count of stateful orders for a specific subaccount.

  • 57-70: The test case "Nil request returns an error" checks if the function correctly handles a nil request and returns an error. The test case "Success" checks if the function correctly returns all stateful orders when the request is valid. The expected orders are the ones added in the populateStatefulOrders function.

  • 96-106: The test case "Nil request returns an error" checks if the function correctly handles a nil request and returns an error. The test case "Success" checks if the function correctly returns the count of stateful orders for a specific subaccount when the request is valid. The expected count is 3, which is the number of orders added in the populateStatefulOrders function.

protocol/x/clob/client/cli/query_stateful_orders.go (1)
  • 13-44: The CmdListStatefulOrders function looks good. It correctly sets up a new cobra command, reads the page request, makes a query to the AllStatefulOrders function, and handles errors appropriately. The pagination flags are also correctly added to the command.
protocol/x/subaccounts/client/cli/query_subaccount.go (1)
  • 48-48: The command usage has been updated from show-subaccount [index] to show-subaccount [owner] [account-number]. Ensure that all calls to this command throughout the codebase have been updated to match the new usage.
protocol/x/clob/module_test.go (1)
  • 274-281: The test has been updated to reflect the addition of two new commands: list-stateful-orders and show-stateful-order-count. Ensure that these commands are implemented correctly and that they return the expected results when invoked.
proto/dydxprotocol/clob/query.proto (3)
  • 7-13: The import statement for "dydxprotocol/clob/order.proto" has been added. Ensure that the file "order.proto" exists in the specified path and that it contains the necessary definitions for handling stateful orders.

  • 42-54: Two new RPC methods, AllStatefulOrders and StatefulOrderCount, have been added to the Query service. These methods are used to query all stateful orders and the count of all stateful orders respectively. The HTTP GET paths for these methods are "/dydxprotocol/clob/orders/stateful" and "/dydxprotocol/clob/orders/stateful/count" respectively. Ensure that these paths are correctly configured in the server routing and that they do not conflict with any existing paths.

  • 127-150: New message definitions have been added for the request and response types of the new RPC methods. QueryAllStatefulOrdersRequest and QueryAllStatefulOrderCountRequest are the request messages for AllStatefulOrders and StatefulOrderCount respectively. QueryAllStatefulOrdersResponse and QueryStatefulOrderCountResponse are the corresponding response messages. Ensure that these message definitions match the expected request and response formats for the new RPC methods.

protocol/mocks/QueryClient.go (2)
  • 119-147: The new mock function AllStatefulOrders has been added correctly. It follows the same pattern as the other mock functions in the file, taking in a context, a request object, and a variable number of gRPC call options. It then uses the Called method from the mock package to simulate a function call and return the expected results. This function will be useful for testing the AllStatefulOrders gRPC endpoint.

  • 389-417: The new mock function StatefulOrderCount has been added correctly. It follows the same pattern as the other mock functions in the file, taking in a context, a request object, and a variable number of gRPC call options. It then uses the Called method from the mock package to simulate a function call and return the expected results. This function will be useful for testing the StatefulOrderCount gRPC endpoint.

indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.rpc.Query.ts (5)
  • 4-4: The import statement has been updated to include the new request and response types for the stateful orders queries. This is necessary for the new query methods that have been added to the Query interface and the QueryClientImpl class.

  • 19-28: Two new query methods have been added to the Query interface: allStatefulOrders and statefulOrderCount. These methods return promises that resolve to the responses of the corresponding gRPC queries. The allStatefulOrders method takes an optional QueryAllStatefulOrdersRequest parameter, while the statefulOrderCount method requires a QueryStatefulOrderCountRequest parameter.

  • 36-40: The allStatefulOrders and statefulOrderCount methods have been bound to the QueryClientImpl instance in the constructor. This ensures that the methods can be called with the correct context.

  • 75-87: The allStatefulOrders and statefulOrderCount methods have been implemented in the QueryClientImpl class. These methods encode the request parameters, make the gRPC request, and decode the response data. The allStatefulOrders method provides a default value for the request parameter, setting pagination to undefined if no request object is provided.

  • 109-120: The allStatefulOrders and statefulOrderCount methods have been added to the Query extension returned by the createRpcQueryExtension function. This allows the methods to be called on the extended QueryClient instance.

indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.lcd.ts (3)
  • 1-6: The import statement on line 3 has been extended to include QueryAllStatefulOrdersRequest and QueryAllStatefulOrdersResponseSDKType. This is in line with the PR summary which mentions the addition of new query commands for handling stateful orders. The changes look good and are in line with the intended functionality.

  • 13-16: The allStatefulOrders method is now bound to the LCDQueryClient class instance. This is a necessary step to ensure that the method can be called correctly on an instance of the class.

  • 46-65: A new method allStatefulOrders has been added to the LCDQueryClient class. This method takes an optional QueryAllStatefulOrdersRequest object as a parameter, which may contain a pagination property. If pagination is provided, it is used to set pagination parameters for the API request. The method constructs the API endpoint for querying all stateful orders and makes a GET request to that endpoint using the req object. It returns a promise that resolves to a QueryAllStatefulOrdersResponseSDKType object. This is in line with the PR summary which mentions the addition of new query commands for handling stateful orders. The changes look good and are in line with the intended functionality.

indexer/packages/v4-protos/src/codegen/dydxprotocol/clob/query.ts (1)
  • 188-252: The new hunk introduces interfaces and functions for querying all stateful orders and getting the count of stateful orders for a specific subaccount. Ensure that these new features are properly integrated with the rest of the system and that they do not introduce any breaking changes. Also, make sure that the new features are covered by tests.

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

Commits Files that changed from the base of the PR and between 76babe7 and c6095cb.
Files selected for processing (2)
  • protocol/x/clob/client/cli/query_stateful_orders.go (1 hunks)
  • protocol/x/clob/client/cli/query_stateful_orders_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/clob/client/cli/query_stateful_orders_test.go
Additional comments (Suppressed): 1
protocol/x/clob/client/cli/query_stateful_orders.go (1)
  • 1-48: The CmdListStatefulOrders function looks good. It correctly sets up a new cobra command to list all stateful orders. It also handles pagination and error checking properly.

protocol/x/clob/client/cli/query_stateful_orders.go Outdated Show resolved Hide resolved
@clemire clemire changed the title [CORE-691] - P1 clob queries for existing StatefulOrder keeper methods [CORE-700] - P1 clob queries for existing StatefulOrder keeper methods Oct 20, 2023
@linear
Copy link

linear bot commented Oct 20, 2023

@dydxprotocol dydxprotocol deleted a comment from linear bot Oct 20, 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

Commits Files that changed from the base of the PR and between c6095cb and 2973c33.
Files selected for processing (1)
  • proto/dydxprotocol/clob/query.proto (3 hunks)
Additional comments (Suppressed): 3
proto/dydxprotocol/clob/query.proto (3)
  • 10-10: The import statement for "order.proto" is new. Ensure that the file exists and is accessible from the current path. Also, verify that the definitions in "order.proto" are used correctly in the new RPC methods and message types.

  • 42-54: Two new RPC methods, AllStatefulOrders and StatefulOrderCount, have been added. Ensure that these methods are implemented on the server side and that they return the expected results. Also, verify that the HTTP GET paths are correctly configured and do not conflict with existing paths.

  • 127-150: New message types QueryAllStatefulOrdersRequest, QueryAllStatefulOrdersResponse, QueryStatefulOrderCountRequest, and QueryStatefulOrderCountResponse have been added. Ensure that these message types are used correctly in the new RPC methods. Also, verify that the fields in these message types are appropriate for their intended use. For example, QueryAllStatefulOrdersRequest includes a pagination field for paginated results, and QueryStatefulOrderCountRequest includes a subaccount_id field to specify a subaccount.

… think this is necessary, it doesn't save much and this does not cause an error.
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

Commits Files that changed from the base of the PR and between 2973c33 and 3d4c70d.
Files selected for processing (2)
  • protocol/x/clob/client/cli/query_stateful_orders.go (1 hunks)
  • protocol/x/clob/client/cli/query_stateful_orders_test.go (1 hunks)
Files skipped from review due to trivial changes (1)
  • protocol/x/clob/client/cli/query_stateful_orders_test.go
Additional comments (Suppressed): 2
protocol/x/clob/client/cli/query_stateful_orders.go (2)
  • 13-44: The CmdListStatefulOrders function is well implemented. It correctly sets up a new cobra command, reads the pagination flags, makes a query to the AllStatefulOrders function, and handles errors appropriately. The pagination and query flags are also correctly added to the command. No changes are needed here.

  • 46-81: The CmdGetStatefulOrderCount function is well implemented. It correctly sets up a new cobra command, reads the arguments, makes a query to the StatefulOrderCount function, and handles errors appropriately. The query flags are also correctly added to the command. However, it would be better to validate the owner argument to ensure it's a valid address before making the query. This can help prevent unnecessary calls to the server with invalid data.

			argOwner := args[0]
			var argNumber uint32
			if argNumber, err = cast.ToUint32E(args[1]); err != nil {
				return err
			}
+           if _, err := sdk.AccAddressFromBech32(argOwner); err != nil {
+               return fmt.Errorf("invalid owner address %s: %w", argOwner, err)
+           }

			params := &types.QueryStatefulOrderCountRequest{

Comment on lines +22 to +25
ctx := sdk.UnwrapSDKContext(c)

statefulOrders := k.GetAllStatefulOrders(ctx)

Copy link
Contributor

Choose a reason for hiding this comment

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

this query is supposed to be paginated, right?

@clemire clemire closed this Oct 23, 2023
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