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: add total delegation balance of a delegator query #352

Merged
merged 2 commits into from
Feb 28, 2025

Conversation

beer-1
Copy link
Member

@beer-1 beer-1 commented Feb 28, 2025

Description

This PR introduces a query endpoint to return total staking balance of a delegator.

Also add this query endpoint to the whitelist of move contract query.


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the correct branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

@beer-1 beer-1 requested a review from a team as a code owner February 28, 2025 06:18
Copy link

coderabbitai bot commented Feb 28, 2025

Warning

Rate limit exceeded

@beer-1 has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 4 minutes and 39 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between cae2c53 and 742f9b2.

⛔ Files ignored due to path filters (3)
  • client/docs/swagger-ui/swagger.yaml is excluded by !**/*.yaml
  • x/mstaking/types/query.pb.go is excluded by !**/*.pb.go, !**/*.pb.go
  • x/mstaking/types/query.pb.gw.go is excluded by !**/*.pb.gw.go, !**/*.pb.gw.go
📒 Files selected for processing (4)
  • app/keepers/keepers.go (1 hunks)
  • proto/initia/mstaking/v1/query.proto (3 hunks)
  • x/mstaking/keeper/grpc_query.go (1 hunks)
  • x/mstaking/keeper/grpc_query_test.go (1 hunks)
📝 Walkthrough

Walkthrough

This pull request adds a new query functionality to the staking module. A new route is introduced in the query whitelist to handle requests for the total delegation balances of a specific delegator. The changes include the addition of a corresponding RPC method in the proto file, its implementation in the gRPC query handler, and unit tests to verify the functionality.

Changes

File(s) Change Summary
app/keepers/keepers.go Added a new query whitelist entry for the route /initia.mstaking.v1.Query/DelegatorSumDelegationBalances with designated request and response types.
proto/initia/mstaking/v1/query.proto Introduced the DelegatorSumDelegationBalances RPC method along with new request and response message definitions, including an import for coin.proto.
x/mstaking/keeper/grpc_query.go
x/mstaking/.../grpc_query_test.go
Implemented the new gRPC query method DelegatorSumDelegationBalances in the Querier and added a test to ensure correct aggregation of delegation balances.

Sequence Diagram(s)

sequenceDiagram
    participant C as Client
    participant Q as Querier
    participant K as Keeper
    participant DB as Delegations Database

    C->>Q: DelegatorSumDelegationBalances Request
    Q->>K: GetAllDelegatorDelegations(delegator_addr)
    K->>DB: Query delegations for delegator_addr
    DB-->>K: Return list of delegations
    K-->>Q: Return aggregated delegation responses
    Q->>C: QueryDelegatorSumDelegationBalancesResponse (total balance)
Loading

Possibly related PRs

Suggested reviewers

  • Vritra4

Poem

I'm a rabbit, hopping with glee,
New queries blossom like springtime trees.
Delegations add up, neat and bright,
Code and carrots, all set just right.
Bounce along, bugs take flight! 🐇

CodeRabbit Inc. cheers this insight!


🪧 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.
  • @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.

Copy link

github-actions bot commented Feb 28, 2025

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

OpenSSF Scorecard

PackageVersionScoreDetails

Scanned Files

@beer-1 beer-1 changed the title feat: add sum-delegation-balances query feat: add total delegation balance of a delegator query Feb 28, 2025
Copy link

codecov bot commented Feb 28, 2025

Codecov Report

Attention: Patch coverage is 46.42857% with 15 lines in your changes missing coverage. Please review.

Project coverage is 41.18%. Comparing base (e74fb02) to head (742f9b2).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
x/mstaking/keeper/grpc_query.go 37.50% 10 Missing and 5 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #352      +/-   ##
==========================================
+ Coverage   41.15%   41.18%   +0.03%     
==========================================
  Files         269      269              
  Lines       25741    25769      +28     
==========================================
+ Hits        10593    10613      +20     
- Misses      13504    13507       +3     
- Partials     1644     1649       +5     
Files with missing lines Coverage Δ
app/keepers/keepers.go 98.48% <100.00%> (+0.01%) ⬆️
x/mstaking/keeper/grpc_query.go 42.46% <37.50%> (-0.29%) ⬇️

... and 1 file with indirect coverage changes

Copy link
Contributor

@sh-cha sh-cha left a comment

Choose a reason for hiding this comment

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

LGTM

@beer-1 beer-1 merged commit 8188d3f into main Feb 28, 2025
12 checks passed
@beer-1 beer-1 deleted the feat/delegator-sum-balances-query branch February 28, 2025 06:59
@coderabbitai coderabbitai bot mentioned this pull request Mar 5, 2025
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants