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-696] - Add query endpoint for x/rewards GetRewardShare. #673

Closed
wants to merge 2 commits into from

Conversation

clemire
Copy link
Contributor

@clemire clemire commented Oct 19, 2023

Changelist

Add query endpoint for x/rewards GetRewardShare

Test Plan

appropriate unit and 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.

@linear
Copy link

linear bot commented Oct 19, 2023

CORE-696 x/rewards gRPC query for GetRewardsShare

add GetAllRewardsShares?

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 19, 2023

Walkthrough

The changes introduce a new feature to query reward shares by address in the dydxprotocol. This includes updates to the protocol's proto definitions, client CLI commands, keeper functions, and tests. Additionally, the indexer package is updated to support this new feature, including new interfaces, functions, and types.

Changes

File(s) Summary
proto/dydxprotocol/rewards/query.proto Introduced a new message type QueryRewardShareRequest and a new RPC method RewardShare to the Query service.
protocol/x/rewards/client/cli/query_reward_share.go Added a new command CmdQueryRewardShare to query the reward share for a specified address.
protocol/x/rewards/keeper/grpc_query.go Added a new function RewardShare to retrieve the reward share using the GetRewardShare function.
protocol/x/rewards/client/cli/query_reward_share_test.go
protocol/x/rewards/keeper/grpc_query_test.go
Added new test functions TestQueryRewardShare to test the new CmdQueryRewardShare command and RewardShare function.
indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.*.ts Added new functions, interfaces, and types to support querying reward share information.

Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • Mention @coderabbitai in any review comment for bot assistance.
  • Note: Review comments are made on code diffs or files, not on the PR overview.

Pause Incremental Reviews

  • Insert @coderabbitai: ignore in the PR description to halt the bot's ongoing reviews. Remove the line to resume.
  • Additionally, enter @coderabbitai pause to halt the bot's ongoing reviews as any issue or review comment. To
    resume reviews, enter @coderabbitai resume as any issue or review comment.

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

Commits Files that changed from the base of the PR and between 1c285e7 and 58bff90.
Files ignored due to filter (2)
  • protocol/x/rewards/types/query.pb.go
  • protocol/x/rewards/types/query.pb.gw.go
Files selected for processing (5)
  • proto/dydxprotocol/rewards/query.proto (3 hunks)
  • protocol/x/rewards/client/cli/query_reward_share.go (1 hunks)
  • protocol/x/rewards/client/cli/query_reward_share_test.go (1 hunks)
  • protocol/x/rewards/keeper/grpc_query.go (1 hunks)
  • protocol/x/rewards/keeper/grpc_query_test.go (2 hunks)
Additional comments (Suppressed): 6
protocol/x/rewards/keeper/grpc_query_test.go (2)
  • 4-7: The import of github.com/dydxprotocol/v4-chain/protocol/dtypes is new in this hunk. Ensure that this import is necessary and used in the code. If it's not used, it should be removed to keep the code clean and maintainable.

  • 49-91: The new test TestQueryRewardShare is well-structured and covers the main success scenario and the case where the request is nil. It's good to see that the test checks both the error and the response object in each case. However, consider adding more test cases to cover other possible error scenarios, such as when the RewardShare for a given address does not exist in the store.

proto/dydxprotocol/rewards/query.proto (3)
  • 1-11: The new import statements for "cosmos_proto/cosmos.proto" and "dydxprotocol/rewards/reward_share.proto" are added to support the new RPC method RewardShare. Ensure that these files exist and are accessible from this location.

  • 15-22: A new RPC method RewardShare is added to the Query service. This method takes QueryRewardShareRequest as input and returns QueryRewardShareResponse. The HTTP GET path for this method is "/dydxprotocol/v4/rewards/shares/{address}". Ensure that this path does not conflict with any existing paths in your application.

  • 33-41: New message types QueryRewardShareRequest and QueryRewardShareResponse are added to support the RewardShare RPC method. QueryRewardShareRequest takes a string address as input, and QueryRewardShareResponse returns a RewardShare object. Ensure that the RewardShare object is correctly defined in "dydxprotocol/rewards/reward_share.proto".

protocol/x/rewards/keeper/grpc_query.go (1)
  • 23-35: The RewardShare function is well implemented. It correctly checks if the request is nil and returns an error if so. It also correctly unwraps the context and retrieves the reward share using the GetRewardShare function. However, it's important to ensure that the GetRewardShare function handles errors properly, as any errors that occur within it will not be caught in this function. If GetRewardShare can return an error, you should modify the function to return that error and handle it in RewardShare.

Here's a potential modification if GetRewardShare can return an error:

	return &types.QueryRewardShareResponse{
-		RewardShare: k.GetRewardShare(ctx, req.Address),
+		RewardShare, err := k.GetRewardShare(ctx, req.Address),
	}, nil
+	if err != nil {
+		return nil, status.Error(codes.Internal, "failed to get reward share")
+	}
+	return &types.QueryRewardShareResponse{RewardShare: RewardShare}, nil
}

@clemire clemire added the backport/protocol/v1.x Backport v1.x label Oct 19, 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

Commits Files that changed from the base of the PR and between 58bff90 and 8d7c7e1.
Files selected for processing (3)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.lcd.ts (3 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.rpc.Query.ts (2 hunks)
  • indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.ts (3 hunks)
Additional comments (Suppressed): 10
indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.lcd.ts (3)
  • 2-2: The import statement has been updated to include QueryRewardShareRequest and QueryRewardShareResponseSDKType from ./query. Ensure that these types are correctly defined in the ./query file.

  • 13-13: The rewardShare method is being bound to the this context of the LCDQueryClient class. This is a standard practice in JavaScript to ensure that the method has the correct context when called.

  • 25-28: A new method rewardShare has been added to the LCDQueryClient class. This method takes a QueryRewardShareRequest object as a parameter and returns a Promise that resolves to a QueryRewardShareResponseSDKType object. The method constructs an endpoint URL using the address property of the request object and sends a GET request to this endpoint. Ensure that the server-side endpoint is correctly set up to handle these requests and return the expected data.

indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.rpc.Query.ts (5)
  • 4-4: The import statement has been updated to include QueryRewardShareRequest and QueryRewardShareResponse from ./query. This is necessary for the new rewardShare function.

  • 12-12: A new function rewardShare has been added to the Query interface. This function takes a QueryRewardShareRequest and returns a Promise<QueryRewardShareResponse>.

  • 20-20: The rewardShare function is bound to this in the QueryClientImpl constructor. This ensures that the function can be called with the correct context.

  • 29-33: The rewardShare function is implemented in the QueryClientImpl class. It encodes the request, sends it to the dydxprotocol.rewards.Query service with the RewardShare method, and decodes the response.

  • 44-45: The rewardShare function is added to the return object of createRpcQueryExtension. This allows it to be called on the extended QueryClient.

indexer/packages/v4-protos/src/codegen/dydxprotocol/rewards/query.ts (2)
  • 1-5: The import statement for RewardShare and RewardShareSDKType has been added. This is necessary for the new QueryRewardShareRequest and QueryRewardShareResponse interfaces that have been introduced.

  • 116-209: New functions createBaseQueryRewardShareRequest, QueryRewardShareRequest.encode, QueryRewardShareRequest.decode, QueryRewardShareRequest.fromPartial, createBaseQueryRewardShareResponse, QueryRewardShareResponse.encode, QueryRewardShareResponse.decode, and QueryRewardShareResponse.fromPartial have been added. These functions are used for creating, encoding, decoding, and creating from partial objects for QueryRewardShareRequest and QueryRewardShareResponse. The createBaseQueryRewardShareRequest function initializes the address property to an empty string, and the createBaseQueryRewardShareResponse function initializes the rewardShare property to undefined.

Comment on lines 18 to +40
export interface QueryParamsResponseSDKType {
params?: ParamsSDKType;
}
/** QueryRewardShareRequest is a request type for the RewardShare RPC method. */

export interface QueryRewardShareRequest {
address: string;
}
/** QueryRewardShareRequest is a request type for the RewardShare RPC method. */

export interface QueryRewardShareRequestSDKType {
address: string;
}
/** QueryRewardShareResponse is a response type for the RewardsShare RPC method. */

export interface QueryRewardShareResponse {
rewardShare?: RewardShare;
}
/** QueryRewardShareResponse is a response type for the RewardsShare RPC method. */

export interface QueryRewardShareResponseSDKType {
reward_share?: RewardShareSDKType;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

New interfaces QueryRewardShareRequest, QueryRewardShareRequestSDKType, QueryRewardShareResponse, and QueryRewardShareResponseSDKType have been added. These interfaces are used for the new RewardShare RPC method. The QueryRewardShareRequest and QueryRewardShareRequestSDKType interfaces have an address property, and the QueryRewardShareResponse and QueryRewardShareResponseSDKType interfaces have a rewardShare property. The rewardShare property in QueryRewardShareResponseSDKType should be rewardShare to maintain consistency with the other interfaces.

-  reward_share?: RewardShareSDKType;
+  rewardShare?: RewardShareSDKType;

@clemire clemire closed this Oct 19, 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.

1 participant