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

docs(x/distribution): updates #22148

Merged
merged 1 commit into from
Oct 7, 2024
Merged

Conversation

JulianToledano
Copy link
Contributor

@JulianToledano JulianToledano commented Oct 7, 2024

Description

Ref:
#21429


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 (see PR Targeting)
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • 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.

Please see Pull Request Reviewer section in the contributing guide for more information on how to review a pull request.

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

Summary by CodeRabbit

  • New Features
    • Introduced a new method for withdrawing delegation rewards.
  • Improvements
    • Enhanced clarity and accuracy of documentation in the README and various methods.
    • Updated comments for better understanding of existing methods and their functionalities.
  • Documentation
    • Refined sections in the README for clearer explanations of the distribution mechanism and withdrawal processes.

@JulianToledano JulianToledano requested review from alpe and a team as code owners October 7, 2024 11:23
Copy link
Contributor

coderabbitai bot commented Oct 7, 2024

📝 Walkthrough

Walkthrough

The changes in this pull request involve updates to documentation and code within the x/distribution module. The README.md file has been revised for clarity regarding reward distribution and withdrawal processes. In the keeper package, several methods have been documented more clearly, with a new method for withdrawing delegation rewards added. Additional adjustments include renaming methods for better understanding and updating comments to enhance code readability. Overall, these modifications focus on improving documentation without altering the underlying functionality.

Changes

File Path Change Summary
x/distribution/README.md Textual modifications for clarity; refined sections on reward distribution, withdrawal processes, shortcomings, staking effects, and parameters; updated examples in the client section.
x/distribution/keeper/delegation.go Updated comments for clarity; renamed methods for better understanding; added withdrawDelegationRewards method for reward withdrawal.
x/distribution/keeper/hooks.go Enhanced comments for clarity; updated method names and signatures, including removal of unused parameters.
x/distribution/keeper/keeper.go Updated comments for WithdrawDelegationRewards and WithdrawValidatorCommission methods for better clarity.

Possibly related PRs

  • docs: Update nft docs #22060: The changes in the README.md for the x/nft module enhance documentation clarity, similar to the improvements made in the x/distribution/README.md regarding reward withdrawal processes.
  • docs: Update upgrade docs #22105: The updates to the x/upgrade module documentation include new CLI commands and REST endpoints, paralleling the enhancements made in the x/distribution/keeper/delegation.go file for clearer functionality descriptions.
  • docs: Update slashing docs #22107: The modifications in the x/slashing module documentation introduce new commands and clarify existing ones, akin to the documentation updates in the x/distribution/keeper/hooks.go that improve clarity on method functionalities.
  • docs(x/consensus): fixes #22114: The fixes in the x/consensus module documentation focus on clarity and typographical corrections, similar to the documentation improvements in the x/distribution files aimed at enhancing user understanding.
  • docs: pre,begin,end block #22127: The updates to the module management documentation emphasize lifecycle methods, which aligns with the structural adjustments made in the x/distribution documentation to clarify processes and functionalities.

Suggested labels

backport/v0.52.x

Suggested reviewers

  • julienrbrt
  • tac0turtle
  • akhilkumarpilli

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

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.

@github-actions github-actions bot added the C:x/distribution distribution module related label Oct 7, 2024
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.

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (9)
x/distribution/README.md (7)

Line range hint 1-41: LGTM! Overview section improvements

The changes in the overview section enhance clarity and readability. The refined explanation of the distribution mechanism and the enhanced description of the withdrawal process provide a better understanding for readers.

Consider adding a brief mention of the global reward pool in the first paragraph to provide context for the later discussion of reward pooling.


Line range hint 64-80: LGTM! Clearer explanation of staking effects

The clarification of the relationship between commission charges and auto-bonding of Atom provisions improves the understanding of the staking mechanism's complexities.

Consider adding a brief explanation of why stakeholders might want to set up a script to periodically withdraw and rebond rewards, as mentioned in the last sentence.


Line range hint 97-102: LGTM! Enhanced clarity in Concepts section

The rewording of the reward calculation explanation and the clarification of conditions for updating rewards improve the overall understanding of the distribution mechanism.

Consider adding a brief example or diagram to illustrate the reward calculation process, which could further enhance reader comprehension.


Line range hint 104-166: LGTM! Improved state descriptions

The updates to the FeePool, ValidatorDistInfo, and DelegationDistInfo descriptions provide more accurate and detailed information about state management in the distribution module.

In the FeePool description, consider clarifying how often the decimal rewards are converted to sdk.Coins and sent to the community pool.


Line range hint 168-185: LGTM! Clearer parameter descriptions

The streamlined description of parameters and the clear notation of deprecated parameters enhance the understanding of the module's configuration options.

Consider adding a brief explanation of why baseproposerreward and bonusproposerreward were deprecated in v0.47, to provide context for the change.


Line range hint 272-442: LGTM! Enhanced message explanations

The updates to the explanations of various messages and the addition of code examples significantly improve the understanding of message handling in the distribution module.

Consider adding a brief explanation of the potential impact of the MsgUpdateParams message on the module's behavior, to help users understand the implications of parameter changes.


Line range hint 444-1037: LGTM! Improved client interaction documentation

The updates to the CLI commands and gRPC endpoints, along with clearer examples and refined explanations, significantly enhance the user's ability to interact with the distribution module.

Consider adding a brief troubleshooting section or common pitfalls to watch out for when using these commands and endpoints, to further assist users in their interactions with the module.

x/distribution/keeper/delegation.go (2)

Line range hint 88-199: Simplify error handling in the iterator callback function.

In CalculateDelegationRewards, the use of the iterErr variable to capture errors from the iterator callback can be simplified. Modifying the callback to return an error directly enhances readability and aligns with Go error-handling best practices.

Apply this diff to streamline error handling:

 if endingHeight > startingHeight {
-    err = k.IterateValidatorSlashEventsBetween(ctx, valAddr, startingHeight, endingHeight,
-        func(height uint64, event types.ValidatorSlashEvent) (stop bool) {
+    err = k.IterateValidatorSlashEventsBetween(ctx, valAddr, startingHeight, endingHeight,
+        func(height uint64, event types.ValidatorSlashEvent) (stop bool, err error) {
             endingPeriod := event.ValidatorPeriod
             if endingPeriod > startingPeriod {
                 delRewards, err := k.calculateDelegationRewardsBetween(ctx, val, startingPeriod, endingPeriod, stake)
                 if err != nil {
-                    iterErr = err
-                    return true
+                    return true, err
                 }
                 rewards = rewards.Add(delRewards...)

                 // Note: It is necessary to truncate so we don't allow withdrawing
                 // more rewards than owed.
                 stake = stake.MulTruncate(math.LegacyOneDec().Sub(event.Fraction))
                 startingPeriod = endingPeriod
             }
-            return false
+            return false, nil
         },
     )
-    if iterErr != nil {
-        return sdk.DecCoins{}, iterErr
-    }
     if err != nil {
         return sdk.DecCoins{}, err
     }
 }

This change allows errors to be returned directly from the iterator function, eliminating the need for the iterErr variable and simplifying the control flow.


Line range hint 203-287: Add unit tests for withdrawDelegationRewards.

The new method withdrawDelegationRewards is a significant addition to the Keeper. To ensure its reliability and correctness, consider adding comprehensive unit tests that cover various scenarios, including:

  • Successful reward withdrawal.
  • Cases where the delegator has no rewards.
  • Error conditions, such as missing starting info or failure in sending coins.

Would you like assistance in creating these unit tests or opening a GitHub issue to track this task?

📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between cc25229 and 7ef7440.

📒 Files selected for processing (4)
  • x/distribution/README.md (2 hunks)
  • x/distribution/keeper/delegation.go (3 hunks)
  • x/distribution/keeper/hooks.go (4 hunks)
  • x/distribution/keeper/keeper.go (2 hunks)
✅ Files skipped from review due to trivial changes (1)
  • x/distribution/keeper/keeper.go
🧰 Additional context used
📓 Path-based instructions (3)
x/distribution/README.md (1)

Pattern **/*.md: "Assess the documentation for misspellings, grammatical errors, missing documentation and correctness"

x/distribution/keeper/delegation.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

x/distribution/keeper/hooks.go (1)

Pattern **/*.go: Review the Golang code for conformity with the Uber Golang style guide, highlighting any deviations.

🔇 Additional comments (9)
x/distribution/keeper/hooks.go (5)

23-26: LGTM: Improved method documentation

The updated comment for the Hooks method is more descriptive and follows the Golang convention of starting with the function name. This change enhances code readability without altering functionality.


Line range hint 28-35: LGTM: Enhanced method documentation

The updated comment for the AfterValidatorCreated method provides a clearer description of the method's purpose. This change improves code documentation and maintainability without affecting the underlying functionality.


Line range hint 143-160: LGTM: Improved method documentation

The updated comment for the BeforeDelegationSharesModified method provides a clearer description of the method's dual functionality (withdrawing delegation rewards and incrementing the period). This change enhances code readability and maintainability without affecting the underlying functionality.


162-170: LGTM: Enhanced method documentation

The updated comments for both AfterDelegationModified and BeforeValidatorSlashed methods provide clearer descriptions of their respective purposes. These changes improve code documentation and maintainability without affecting the underlying functionality.


Line range hint 132-140: Verify the removal of delAddr parameter usage

The updated comment for the BeforeDelegationCreated method is more concise and descriptive, which is good. However, the delAddr parameter has been replaced with an underscore, indicating it's no longer used within the method. Please verify if this is intentional and that the delAddr is not needed for any operations within this method or for maintaining consistency with other parts of the codebase.

To check for any other usages of delAddr in similar contexts, you can run:

x/distribution/README.md (3)

Line range hint 43-62: LGTM! Improved clarity in Shortcomings section

The rephrasing of the context around constant reward flows enhances readability while maintaining the essential information about the distribution mechanism's limitations.


Line range hint 82-95: LGTM! Updated table of contents

The table of contents has been appropriately updated to reflect the current structure of the document, improving navigation for readers.


Line range hint 187-270: LGTM! Improved BeginBlock and distribution scheme explanations

The refinements to the BeginBlock explanation and the updates to the distribution scheme provide a clearer understanding of the fee distribution process.

x/distribution/keeper/delegation.go (1)

Line range hint 49-72: Function calculateDelegationRewardsBetween is correctly implemented.

The function includes proper input validation and error handling, and it accurately calculates the rewards accrued between two periods for a delegation. The sanity checks help prevent invalid inputs, and the computations use appropriate methods to ensure correctness.

@julienrbrt julienrbrt added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Oct 7, 2024
@julienrbrt julienrbrt self-assigned this Oct 7, 2024
@tac0turtle tac0turtle added this pull request to the merge queue Oct 7, 2024
Merged via the queue into main with commit 6211be6 Oct 7, 2024
78 of 80 checks passed
@tac0turtle tac0turtle deleted the julian/readme-distribution-v0.52 branch October 7, 2024 13:21
mergify bot pushed a commit that referenced this pull request Oct 7, 2024
julienrbrt pushed a commit that referenced this pull request Oct 7, 2024
Co-authored-by: Julián Toledano <JulianToledano@users.noreply.github.com>
@educlerici-zondax educlerici-zondax added the S:zondax Squad: Zondax label Oct 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release C:x/distribution distribution module related S:zondax Squad: Zondax
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants