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: withdrawal bugfix #219

Merged
merged 1 commit into from
Jul 3, 2024
Merged

fix: withdrawal bugfix #219

merged 1 commit into from
Jul 3, 2024

Conversation

beer-1
Copy link
Contributor

@beer-1 beer-1 commented Jul 3, 2024

The bug comes from the setting the outstanding rewards with wrong key.

- err = k.ValidatorOutstandingRewards.Set(ctx, delAddr, customtypes.ValidatorOutstandingRewards{Rewards: outstanding.Sub(rewards)})
+ err = k.ValidatorOutstandingRewards.Set(ctx, valAddr, customtypes.ValidatorOutstandingRewards{Rewards: outstanding.Sub(rewards)})

@beer-1 beer-1 requested a review from a team as a code owner July 3, 2024 08:22
@beer-1 beer-1 self-assigned this Jul 3, 2024
Copy link

coderabbitai bot commented Jul 3, 2024

Walkthrough

Walkthrough

The recent updates primarily focus on simplifying code within the distribution keeper of the project. The calculateDelegationRewardsBetween and withdrawDelegationRewards methods in delegation.go have been streamlined. In validator.go, the changes involve replacing the usage of collections.Join with direct method calls for managing historical rewards and slash events, aiming to make the codebase more maintainable and straightforward.

Changes

Files Change Summary
x/distribution/keeper/delegation.go Simplified calculateDelegationRewardsBetween with collections.Join, and changed withdrawDelegationRewards to update ValidatorOutstandingRewards with valAddr instead of delAddr.
x/distribution/keeper/validator.go Replaced collections.Join with direct function calls/method invocations for managing historical rewards and slash events.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Keeper
    participant ValidatorHistoricalRewards
    participant ValidatorOutstandingRewards

    User->>Keeper: withdrawDelegationRewards(valAddr, ... )
    Keeper->>+ValidatorOutstandingRewards: Update(valAddr, rewards)
    ValidatorOutstandingRewards-->>-Keeper: Acknowledgment
    Keeper-->>User: Rewards Withdrawn

    User->>Keeper: incrementValidatorPeriod(valAddr, rewards)
    Keeper->>+ValidatorHistoricalRewards: Get(valAddr, rewards.Period-1)
    ValidatorHistoricalRewards-->>Keeper: Historical Rewards
    Keeper->>+ValidatorHistoricalRewards: Set(valAddr, rewards.Period)
    ValidatorHistoricalRewards-->>Keeper: Acknowledgment
    Keeper-->>User: Period Incremented
Loading

Poem

In the code, a change so bright,
Simplify, and keep it light.
Rewards are counted with great care,
Validators, you’re so fair! 🌟
A join replaced, efficiency found,
In the simplified lines, our joy is bound. 🎉

Tip

AI model upgrade

gpt-4o model for reviews and chat is now live

OpenAI claims that this model is better at understanding and generating code than the previous models. Please join our Discord Community to provide any feedback or to report any issues.


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 July 3, 2024 08:25
Copy link

codecov bot commented Jul 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 40.22%. Comparing base (dce66e2) to head (b15ff30).

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #219   +/-   ##
=======================================
  Coverage   40.22%   40.22%           
=======================================
  Files         258      258           
  Lines       24617    24617           
=======================================
  Hits         9903     9903           
  Misses      13183    13183           
  Partials     1531     1531           
Files Coverage Δ
x/distribution/keeper/delegation.go 42.66% <100.00%> (ø)
x/distribution/keeper/validator.go 43.38% <100.00%> (ø)

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dce66e2 and b15ff30.

Files selected for processing (2)
  • x/distribution/keeper/delegation.go (2 hunks)
  • x/distribution/keeper/validator.go (7 hunks)
Additional comments not posted (12)
x/distribution/keeper/validator.go (9)

146-146: LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join with valAddr.Bytes() are correct and consistent.


158-158: LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join with valAddr.Bytes() are correct and consistent.

Verification successful

Verified the usage of collections.Join with valAddr.Bytes().

The broader search confirmed that all occurrences of collections.Join(valAddr.Bytes(), period) are consistent and correct within x/distribution/keeper/validator.go.

  • x/distribution/keeper/validator.go:
    • Line 158: return k.ValidatorHistoricalRewards.Set(ctx, collections.Join(valAddr.Bytes(), period), historical)
    • Other instances in the same file follow the same pattern.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go $'collections.Join(valAddr.Bytes()'

Length of output: 149



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Corrected regex pattern to search for function usage.
rg --type go 'collections\.Join\(valAddr\.Bytes\(\)\)'

Length of output: 56



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()` in various forms.

# Broader search pattern to include possible variations.
rg --type go 'collections\.Join\(.*valAddr\.Bytes\(\).*\)'

Length of output: 733


115-115: LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join with valAddr.Bytes() are correct and consistent.

Verification successful

LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

  • x/distribution/keeper/validator.go: Verified instances of collections.Join(valAddr.Bytes(), period) and collections.Join(valAddr.Bytes(), height, newPeriod) are correct and consistent.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go $'collections.Join(valAddr.Bytes()'

Length of output: 149



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go 'collections.Join\(valAddr\.Bytes\(\)\)'

Length of output: 55



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join`.

# Test: Search for the function usage. Expect: Review all instances of the usage.
rg --type go 'collections.Join'

Length of output: 12953


191-191: LGTM! Verify the usage of collections.Join3 with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join3 with valAddr.Bytes() are correct and consistent.

Verification successful

The usage of collections.Join3 with valAddr.Bytes() is consistent and correct.

  • The codebase shows consistent patterns of using collections.Join3 with various address and byte slice combinations.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join3` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go $'collections.Join3(valAddr.Bytes()'

Length of output: 152



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join3` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go 'collections.Join3(valAddr.Bytes())'

Length of output: 51



Script:

#!/bin/bash
# Description: Search for all calls to `collections.Join3` in the codebase.

# Test: Search for the function usage. Expect: Occurrences of the function usage to verify consistency.
rg --type go 'collections.Join3'

Length of output: 2279


141-141: LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join with valAddr.Bytes() are correct and consistent.

Verification successful

Verification Successful: Consistent Usage of collections.Join with valAddr.Bytes()

The usage of collections.Join with valAddr.Bytes() in x/distribution/keeper/validator.go is correct and consistent. There are no other occurrences in the codebase that conflict with this usage.

  • x/distribution/keeper/validator.go: Verified instances of collections.Join(valAddr.Bytes(), period)
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go $'collections.Join(valAddr.Bytes()'

Length of output: 149



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go 'collections.Join(valAddr.Bytes())'

Length of output: 50



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` in the codebase.

# Test: Search for all occurrences of `collections.Join`.
rg --type go 'collections.Join'

Length of output: 12953


25-25: LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join with valAddr.Bytes() are correct and consistent.


131-131: LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join with valAddr.Bytes() are correct and consistent.

Verification successful

LGTM! The usage of collections.Join with valAddr.Bytes() is correct and consistent.

  • Verified the specific pattern collections.Join(valAddr.Bytes(), period) in the file x/distribution/keeper/validator.go.
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go $'collections.Join(valAddr.Bytes()'

Length of output: 149



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go 'collections.Join\(valAddr\.Bytes\(\)\)'

Length of output: 55



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join`.

# Test: Search for the function usage. Expect: Occurrences of `collections.Join`.
rg --type go 'collections.Join'

Length of output: 12953


156-156: LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join with valAddr.Bytes() are correct and consistent.

Verification successful

Usage of collections.Join with valAddr.Bytes() is consistent and correct.

The search results show multiple instances of collections.Join used with valAddr.Bytes() in x/distribution/keeper/validator.go. This confirms that the usage in the provided snippet is consistent with other parts of the codebase.

  • x/distribution/keeper/validator.go: Multiple occurrences found using collections.Join(valAddr.Bytes(), period).
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go $'collections.Join(valAddr.Bytes()'

Length of output: 149



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go 'collections.Join(valAddr.Bytes()'

Length of output: 149



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go 'collections\.Join\(valAddr\.Bytes\(\)\)'

Length of output: 56



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` and manually inspect for usage with `valAddr.Bytes()`.

# Test: Search for the function usage. Expect: Occurrences of `collections.Join` to manually check for `valAddr.Bytes()`.
rg --type go 'collections\.Join'

Length of output: 12956


103-103: LGTM! Verify the usage of collections.Join with valAddr.Bytes().

The code changes are approved.

Ensure that all calls to collections.Join with valAddr.Bytes() are correct and consistent.

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

70-70: LGTM! Verify the usage of collections.Join with valAddr.

The code changes are approved.

Ensure that all calls to collections.Join with valAddr are correct and consistent.

Verification successful

Verification Successful!

The usage of collections.Join with valAddr has been verified across the codebase and is consistent and correct.

  • x/distribution/keeper/delegation.go
  • x/distribution/keeper/validator.go
  • x/distribution/keeper/genesis.go
  • x/mstaking/keeper/delegation.go
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr`.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go $'collections.Join(valAddr'

Length of output: 133



Script:

#!/bin/bash
# Description: Verify all calls to `collections.Join` with `valAddr`.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go 'collections.Join\(valAddr'

Length of output: 2700


74-74: LGTM! Verify the usage of collections.Join with valAddr.

The code changes are approved.

Ensure that all calls to collections.Join with valAddr are correct and consistent.


281-281: Bugfix LGTM! Verify the usage of the correct key for setting outstanding rewards.

The code changes are approved.

Ensure that the correct key valAddr is used consistently for setting outstanding rewards.

Verification successful

Bugfix LGTM! Verified the usage of the correct key for setting outstanding rewards.

The code changes are approved.

  • x/distribution/keeper/validator.go
  • x/distribution/keeper/keeper.go
  • x/distribution/keeper/keeper_test.go
  • x/distribution/keeper/genesis.go
  • x/distribution/keeper/delegation.go
  • x/distribution/keeper/allocation.go
Scripts executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of the correct key `valAddr` for setting outstanding rewards.

# Test: Search for the function usage. Expect: Only occurances of the new usage.
rg --type go $'ValidatorOutstandingRewards.Set(ctx, valAddr'

Length of output: 188



Script:

#!/bin/bash
# Description: Verify the usage of the correct key `valAddr` for setting outstanding rewards.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go 'ValidatorOutstandingRewards.Set(ctx, valAddr'

Length of output: 188



Script:

#!/bin/bash
# Description: Verify the usage of the correct key `valAddr` for setting outstanding rewards.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go "ValidatorOutstandingRewards.Set(ctx, valAddr"

Length of output: 188



Script:

#!/bin/bash
# Description: Verify the usage of the correct key `valAddr` for setting outstanding rewards.

# Test: Search for the function usage. Expect: Only occurrences of the new usage.
rg --type go 'ValidatorOutstandingRewards.Set(ctx, valAddr)'

Length of output: 62



Script:

#!/bin/bash
# Description: Verify the usage of the correct key for setting outstanding rewards.

# Test: Search for all occurrences of ValidatorOutstandingRewards.Set
rg --type go 'ValidatorOutstandingRewards.Set'

Length of output: 1503

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

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between dce66e2 and b15ff30.

Files selected for processing (2)
  • x/distribution/keeper/delegation.go (2 hunks)
  • x/distribution/keeper/validator.go (7 hunks)
Additional comments not posted (12)
x/distribution/keeper/validator.go (9)

25-25: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


103-103: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


115-115: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


131-131: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


141-141: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


146-146: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


156-156: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


158-158: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


191-191: LGTM! The usage of collections.Join3 simplifies the key concatenation.

The modification enhances readability and consistency.

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

70-70: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


74-74: LGTM! The usage of collections.Join simplifies the key concatenation.

The modification enhances readability and consistency.


281-281: Bugfix approved! Correct key used for ValidatorOutstandingRewards.

The modification fixes the bug by using valAddr instead of delAddr.

@beer-1 beer-1 merged commit 314bcc1 into main Jul 3, 2024
7 checks passed
@beer-1 beer-1 deleted the fix/reward-withdrawal branch July 3, 2024 08:54
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