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

fix: validators query to use power index at bonded validator query #194

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

beer-1
Copy link
Contributor

@beer-1 beer-1 commented Jun 1, 2024

No description provided.

@beer-1 beer-1 requested a review from a team as a code owner June 1, 2024 12:58
Copy link

coderabbitai bot commented Jun 1, 2024

Walkthrough

Walkthrough

The Validators method in the Querier struct has been updated to handle the Bonded status separately from other statuses. This change involves restructuring the logic to improve the querying process for validators based on their status, ensuring more accurate and efficient handling of the Bonded status.

Changes

File Path Change Summary
x/mstaking/keeper/grpc_query.go Updated Validators method to handle Bonded status separately, refactored logic for querying validators, and restructured assignment logic.

Sequence Diagram(s) (Beta)

sequenceDiagram
    participant Client
    participant Querier
    participant ValidatorStore

    Client->>Querier: QueryValidatorsRequest(status)
    Querier->>ValidatorStore: Fetch validators based on status
    alt Status is Bonded
        ValidatorStore-->>Querier: Bonded validators
    else Other statuses
        ValidatorStore-->>Querier: Validators based on status
    end
    Querier-->>Client: QueryValidatorsResponse(validators)
Loading

Poem

In the code where queries dwell,
Validators' tales we now tell.
Bonded ones, a special case,
Handled with a touch of grace.
Logic restructured, neat and clear,
For a system we hold dear.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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 as 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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@beer-1 beer-1 requested a review from sh-cha June 1, 2024 12:58
Copy link

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

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 85707ca and 02140f3.

Files selected for processing (1)
  • x/mstaking/keeper/grpc_query.go (1 hunks)
Additional comments not posted (1)
x/mstaking/keeper/grpc_query.go (1)

51-51: Ensure comprehensive error handling for new query paths.

The addition of separate handling for the 'Bonded' status introduces new paths in the code. It's important to ensure that all error scenarios are covered adequately. Consider adding more specific error messages or handling for cases where the new query logic might fail.

Comment on lines +36 to +51
var validators []types.Validator
var pageRes *query.PageResponse
var err error

if req.Status == types.Bonded.String() {
validators, pageRes, err = query.CollectionPaginate(ctx, q.Keeper.ValidatorsByConsPowerIndex, req.Pagination, func(key collections.Pair[int64, []byte], _ bool) (types.Validator, error) {
valAddr := key.K2()
return q.Keeper.Validators.Get(ctx, valAddr)
})
} else {
validators, pageRes, err = query.CollectionFilteredPaginate(ctx, q.Keeper.Validators, req.Pagination, func(valAddr []byte, val types.Validator) (include bool, err error) {
return (req.Status == "" || strings.EqualFold(val.GetStatus().String(), req.Status)), nil
}, func(valAddr []byte, val types.Validator) (types.Validator, error) {
return val, nil
})
}
Copy link

Choose a reason for hiding this comment

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

Refactor the handling of bonded validators to optimize query performance.

The separation of the 'Bonded' status handling is a good approach to optimize the performance for specific queries. However, consider abstracting the querying logic into separate methods to improve readability and maintainability. Additionally, ensure that the new querying logic is covered by unit tests to prevent regressions.

Copy link

codecov bot commented Jun 1, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 6 lines in your changes are missing coverage. Please review.

Project coverage is 37.81%. Comparing base (85707ca) to head (02140f3).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #194   +/-   ##
=======================================
  Coverage   37.81%   37.81%           
=======================================
  Files         251      251           
  Lines       24115    24125   +10     
=======================================
+ Hits         9119     9123    +4     
- Misses      13523    13529    +6     
  Partials     1473     1473           
Files Coverage Δ
x/mstaking/keeper/grpc_query.go 42.75% <60.00%> (-0.07%) ⬇️

@beer-1 beer-1 merged commit 9e37292 into main Jun 1, 2024
7 checks passed
@beer-1 beer-1 deleted the fix/bonded-validators-query branch June 1, 2024 13:10
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.

1 participant