8000 fix(vesting): delegated on addGrant by GAtom22 · Pull Request #2880 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix(vesting): delegated on addGrant #2880

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

Merged
merged 13 commits into from
Sep 25, 2024
Merged

fix(vesting): delegated on addGrant #2880

merged 13 commits into from
Sep 25, 2024

Conversation

GAtom22
Copy link
Contributor
@GAtom22 GAtom22 commented Sep 24, 2024

Description

Closes: #XXXX


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

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the correct branch (see PR Targeting)

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

  • added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • confirmed all author checklist items have been addressed
  • confirmed that this PR does not change production code
  • reviewed content
  • tested instructions (if applicable)
  • confirmed all CI checks have passed

Summary by CodeRabbit

  • New Features

    • Improved calculation of free delegated amounts during vesting account creation and grant addition.
    • Introduced a new AddGrant method for merging clawback vesting grants into existing accounts.
    • Enhanced handling of pre-existing delegations in vesting account tests.
  • Bug Fixes

    • Corrected terminology in the ClawbackVestingAccount documentation for clarity on "free" tokens.
  • Tests

    • Expanded test cases for vesting accounts to include scenarios with pre-existing delegations.

Copy link
Contributor
coderabbitai bot commented Sep 24, 2024

Walkthrough

The pull request introduces updates to the Evmos project's vesting account functionality. Key changes include the removal of the addGrant method to simplify the code, the introduction of a new AddGrant method in the ClawbackVestingAccount struct, and enhancements to test cases that cover scenarios involving pre-existing delegations. Additionally, a comment clarification in the LockedCoins method refines the understanding of "free" tokens.

Changes

File Change Summary
CHANGELOG.md Update on the fix for calculating free delegated amounts in vesting accounts and updates to addGrant.
x/vesting/keeper/msg_server.go Modifications to CreateClawbackVestingAccount; removal of addGrant method; direct call to vestingAcc.AddGrant.
x/vesting/keeper/msg_server_test.go New test cases added for handling pre-existing delegations in vesting accounts; modifications to existing test structures.
x/vesting/types/clawback_vesting_account.go Introduction of AddGrant method; clarification in the comment of LockedCoins method regarding "free" tokens now described as "vested" tokens.

Possibly related PRs

  • fix(vesting): delegated on addGrant #2880: This PR directly addresses the calculation of the free delegated amount during the creation of a vesting account and updates the addGrant function, which is also mentioned in the main PR summary.

Suggested reviewers

  • hanchon
  • Vvaradinov
  • fedekunze
  • 0xstepit

Poem

In the garden where tokens play,
A rabbit hops, brightening the day.
With grants and vesting, all aligned,
Free coins now better defined!
Hooray for changes, let’s all cheer,
For a smoother path, the future is near! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 4a3e99a and 6814f78.

📒 Files selected for processing (2)
  • CHANGELOG.md (1 hunks)
  • x/vesting/keeper/msg_server_test.go (10 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • CHANGELOG.md
  • x/vesting/keeper/msg_server_test.go

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.

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.

@GAtom22 GAtom22 marked this pull request as ready for review September 24, 2024 17:30
@GAtom22 GAtom22 requested a review from a team as a code owner September 24, 2024 17:30
@GAtom22 GAtom22 requested review from MalteHerrmann and 0xstepit and removed request for a team September 24, 2024 17:30
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: 8

Outside diff range and nitpick comments (2)
x/vesting/keeper/msg_server.go (1)

493-496: Unnecessary Error Handling for BondDenom Function

The BondDenom method typically does not return an error; it returns the bond denomination string directly. The error handling around this call is unnecessary and can be removed to simplify the code.

Apply this diff to remove redundant error handling:

-	bondDenom, err := k.stakingKeeper.BondDenom(ctx)
-	if err != nil {
-		return nil, err
-	}
+	bondDenom := k.stakingKeeper.BondDenom(ctx)
x/vesting/keeper/msg_server_test.go (1)

113-113: Maintain consistency in test case names.

The test case names on lines 113 and 124 start with "true -" while other test cases use "pass -" or "fail -" for clarity. Consider changing "true -" to "pass -" to maintain consistency across your test case names.

Apply this diff to update the test case names:

-	name:                  "true - create vesting account with pre existing delegation",
+	name:                  "pass - create vesting account with pre existing delegation",

-	name:                  "true - fund existing vesting account with pre existing delegation",
+	name:                  "pass - fund existing vesting account with pre existing delegation",

Also applies to: 124-124

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 07b35b4 and bb0035e.

Files selected for processing (4)
  • CHANGELOG.md (1 hunks)
  • x/vesting/keeper/msg_server.go (3 hunks)
  • x/vesting/keeper/msg_server_test.go (9 hunks)
  • x/vesting/types/clawback_vesting_account.go (1 hunks)
Additional comments not posted (3)
CHANGELOG.md (3)

49-49: LGTM! Comprehensive changelog for the upcoming release.

The Unreleased section is well-structured and provides a clear overview of the upcoming changes. It properly categorizes the changes into State Machine Breaking, Improvements, and Bug Fixes, making it easy for users to understand the impact of the new version.


Line range hint 51-93: LGTM! Well-documented v15.0.0 release.

The v15.0.0 section provides a comprehensive overview of the changes in this major release. It clearly outlines the API Breaking and State Machine Breaking changes, along with numerous improvements and bug fixes. This level of detail is crucial for users upgrading to this version.


Line range hint 95-1037: LGTM! Excellent maintenance of the project's version history.

The CHANGELOG.md file maintains a consistent and detailed record of changes across all versions of the project. This comprehensive history is invaluable for users and developers to understand the project's evolution, breaking changes, and improvements over time. The consistent categorization of changes (e.g., State Machine Breaking, API Breaking, Improvements, Bug Fixes) across versions is particularly helpful.

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>
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: 2

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and betwee 8000 n 0852393 and a6f8b8b.

Files selected for processing (2)
  • x/vesting/keeper/msg_server.go (2 hunks)
  • x/vesting/types/clawback_vesting_account.go (3 hunks)
Additional comments not posted (3)
x/vesting/keeper/msg_server.go (3)

75-75: LGTM: Minor formatting improvement

The addition of a blank line improves code readability by separating logical blocks of code.


158-160: Reminder: Address potential issues with delegated tokens

While the current changes simplify the code, they don't directly address the potential issues mentioned in previous reviews. These issues include:

  1. Potential inclusion of unvested delegated tokens in DelegatedFree.
  2. Incorrect assignment of delegated tokens to DelegatedFree in the addGrant function (now removed).
  3. getDelegatedCoins not differentiating between vested and unvested tokens.

Please review these concerns and ensure that the new implementation correctly handles the assignment of vested and unvested delegated tokens to DelegatedFree and DelegatedVesting.

To investigate these issues, please run the following verification script:


158-160: Simplification of grant addition logic

The removal of the addGrant function and its replacement with a direct call to vestingAcc.AddGrant simplifies the code and streamlines the process of modifying vesting schedules. This change appears to maintain the core functionality while reducing complexity.

To ensure the new implementation maintains the same behavior as the previous one, please run the following verification script:

Verification successful

Grant addition logic successfully simplified

The removal of the addGrant function and its replacement with a direct call to vestingAcc.AddGrant has been successfully verified. No remaining references to the old addGrant function were found, ensuring the change maintains the intended functionality without introducing complexity.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of AddGrant in the ClawbackVestingAccount type

# Test: Check the implementation of AddGrant in ClawbackVestingAccount
ast-grep --lang go --pattern $'type ClawbackVestingAccount struct {
  $$$
}

func (cva *ClawbackVestingAccount) AddGrant($_) error {
  $$$
}'

# Test: Check for any remaining references to the old addGrant function
rg 'func.*addGrant'

Length of output: 696


Script:

#!/bin/bash
# Description: Verify the existence of ClawbackVestingAccount struct

# Test: Check the ClawbackVestingAccount struct definition
ast-grep --lang go --pattern $'type ClawbackVestingAccount struct {
  $$$
}'

# Description: Verify the implementation of AddGrant method in ClawbackVestingAccount

# Test: Check the AddGrant method implementation
ast-grep --lang go --pattern $'func (cva *ClawbackVestingAccount) AddGrant($_) error {
  $$$
}'

# Test: Check for any remaining references to the old addGrant function
rg 'func.*addGrant'

Length of output: 7990


Script:

#!/bin/bash
# Description: Identify the type of vestingAcc in msg_server.go

# Locate the declaration or assignment of vestingAcc and extract its type
rg 'vestingAcc\s*[:=]\s*New\w+\(' -- go:msg_server.go --replace '$1' | awk '{print $NF}' | head -n 1

# Description: Verify if the identified type implements the AddGrant method

# Assuming the type identified is stored in a variable TYPE, replace <TYPE> accordingly
# Replace <TYPE> with the actual type name obtained from the previous command
TYPE="<TYPE>"

ast-grep --lang go --pattern $"func (\\w+ *${TYPE}) AddGrant($_) error {
  $$$
}"

# Description: Search the codebase for all implementations of AddGrant method

# Find all AddGrant method implementations
ast-grep --lang go --pattern $'func (\\$_ *$_) AddGrant($_) error {
  $$$
}'

Length of output: 427


Script:

#!/bin/bash
# Description: Locate all instances of msg_server.go in the codebase

# Find all paths to msg_server.go
msg_server_paths=$(fd --type f --name "msg_server.go")

# Check if any msg_server.go files are found
if [ -z "$msg_server_paths" ]; then
  echo "No msg_server.go files found in the repository."
  exit 1
fi

echo "Found msg_server.go at the following locations:"
echo "$msg_server_paths"

# Iterate through each msg_server.go path to extract the type of vestingAcc and verify AddGrant
for path in $msg_server_paths; do
  echo "Processing $path..."

  # Extract the line where vestingAcc is initialized or assigned
  vestingAcc_line=$(rg 'vestingAcc\s*[:=]\s*New\w+\(' "$path" | head -n 1)

  if [ -z "$vestingAcc_line" ]; then
    echo "No initialization or assignment of vestingAcc found in $path."
    continue
  fi

  # Extract the type name from the vestingAcc initialization
  type_name=$(echo "$vestingAcc_line" | grep -oP 'New\K\w+')

  if [ -z "$type_name" ]; then
    echo "Could not determine the type of vestingAcc in $path."
    continue
  fi

  echo "Identified vestingAcc type: $type_name"

  # Verify if the identified type implements the AddGrant method
  ast-grep --lang go --pattern $'func (cva *'"$type_name"'") AddGrant($_) error {
    $$$
  }' "$path"

  # Search the codebase for all implementations of AddGrant method
  ast-grep --lang go --pattern $'func ($_ *$_) AddGrant($_) error {
    $$$
  }'
done

# Finally, check for any remaining references to the old addGrant function
rg 'func.*addGrant'

Length of output: 436


Script:

#!/bin/bash
# Description: Locate all instances of msg_server.go in the codebase using rg

# Find all paths to msg_server.go using ripgrep
msg_server_paths=$(rg --files --glob 'msg_server.go')

# Check if any msg_server.go files are found
if [ -z "$msg_server_paths" ]; then
  echo "No msg_server.go files found in the repository."
  exit 1
fi

echo "Found msg_server.go at the following locations:"
echo "$msg_server_paths"

# Iterate through each msg_server.go path to extract the type of vestingAcc and verify AddGrant
for path in $msg_server_paths; do
  echo "Processing $path..."

  # Extract the line where vestingAcc is initialized or assigned
  vestingAcc_line=$(rg 'vestingAcc\s*[:=]\s*New\w+\(' "$path" | head -n 1)

  if [ -z "$vestingAcc_line" ]; then
    echo "No initialization or assignment of vestingAcc found in $path."
    continue
  fi

  # Extract the type name from the vestingAcc initialization
  type_name=$(echo "$vestingAcc_line" | grep -oP 'New\K\w+')

  if [ -z "$type_name" ]; then
    echo "Could not determine the type of vestingAcc in $path."
    continue
  fi

  echo "Identified vestingAcc type: $type_name"

  # Verify if the identified type implements the AddGrant method
  ast-grep --lang go --pattern $'func (cva *'"$type_name"'") AddGrant($_) error {
    $$$
  }' "$path"

  # Search the codebase for all implementations of AddGrant method
  ast-grep --lang go --pattern $'func ($_ *$_) AddGrant($_) error {
    $$$
  }'
done

# Finally, check for any remaining references to the old addGrant function
rg 'func.*addGrant'

Length of output: 4215

@GAtom22 GAtom22 changed the title fix(vesting): delegated on creation and addGrant fix(vesting): delegated on addGrant Sep 24, 2024
Copy link
Contributor
@MalteHerrmann MalteHerrmann left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this @GAtom22! Only left some small suggestions for personal preference but feel free to ignore them

Copy link
Contributor
@0xstepit 0xstepit left a comment

Choose a reason for hiding this comment

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

Thanks for fixing it Tom! Left minor comments

@GAtom22
Copy link
Contributor Author
GAtom22 commented Sep 25, 2024

https://github.com/Mergifyio backport rama/release-v20

Copy link
Contributor
mergify bot commented Sep 25, 2024

backport rama/release-v20

✅ Backports have been created

@GAtom22 GAtom22 merged commit 1d66cbc into main Sep 25, 2024
49 of 51 checks passed
@GAtom22 GAtom22 deleted the GAtom22/fix-add-grant branch September 25, 2024 13:17
mergify bot pushed a commit that referenced this pull request Sep 25, 2024
* fix(vesting): delegated on creation and addGrant

* add changelog entry

* update comments

* update comments

* Update x/vesting/keeper/msg_server_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>

* Update x/vesting/keeper/msg_server_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>

* update comments

* remove init value for DelegatedFree

* move addGrant to clawback acc type

* update chlog

* address review comments

---------

Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
(cherry picked from commit 1d66cbc)

# Conflicts:
#	CHANGELOG.md
#	x/vesting/keeper/msg_server.go
#	x/vesting/keeper/msg_server_test.go
GAtom22 added a commit that referenced this pull request Sep 25, 2024
* fix(vesting): delegated on  addGrant (#2880)

* fix(vesting): delegated on creation and addGrant

* add changelog entry

* update comments

* update comments

* Update x/vesting/keeper/msg_server_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>

* Update x/vesting/keeper/msg_server_test.go

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>

* update comments

* remove init value for DelegatedFree

* move addGrant to clawback acc type

* update chlog

* address review comments

---------

Signed-off-by: Tom <54514587+GAtom22@users.noreply.github.com>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
(cherry picked from commit 1d66cbc)

# Conflicts:
#	CHANGELOG.md
#	x/vesting/keeper/msg_server.go
#	x/vesting/keeper/msg_server_test.go

* fix conflicts

* fix conflicts

* run make format

---------

Co-authored-by: Tom <54514587+GAtom22@users.noreply.github.com>
Co-authored-by: tom <tomasguerraalda@hotmail.com>
Co-authored-by: GAtom22 <GAtom22@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants
0