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

remove old ics code that is unused #1736

Closed
wants to merge 2 commits into from
Closed

Conversation

joe-bowman
Copy link
Contributor

@joe-bowman joe-bowman commented Oct 24, 2024

1. Summary

Remove redundant ICS rewards distribution logic.

Summary by CodeRabbit

  • New Features

    • Enhanced user allocation calculations by streamlining the logic and removing unnecessary complexity related to ICS rewards.
  • Bug Fixes

    • Improved error handling for reward distribution, ensuring that failures do not affect processing in other zones.
  • Tests

    • Updated test cases to focus solely on user allocations and remainders, removing references to interchain staking allocations for clarity.

Copy link
Contributor

coderabbitai bot commented Oct 24, 2024

Walkthrough

The changes in this pull request primarily involve modifications to the rewards_holdings.go and rewards_holdings_test.go files. The CalcUserHoldingsAllocations method has been simplified by removing an unused return value and eliminating the logic related to ICS rewards. The AllocateHoldingsRewards function has been updated accordingly. In the test file, the test cases have been restructured to remove references to ICS rewards, focusing instead on user allocations and remainders.

Changes

File Change Summary
x/participationrewards/keeper/rewards_holdings.go - Updated CalcUserHoldingsAllocations method signature, removed unused return value, and eliminated ICS rewards logic.
- Simplified AllocateHoldingsRewards function to reflect changes in user allocations.
x/participationrewards/keeper/rewards_holdings_test.go - Modified TestCalcUserHoldingsAllocations to remove icsWant and icsRemainder fields, focusing on want and remainder only.
- Updated method call to CalcUserHoldingsAllocations to reflect changes in return values.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Keeper
    participant Zone

    User->>Keeper: Request Holdings Allocation
    Keeper->>Zone: Calculate User Holdings Allocations
    Zone-->>Keeper: Return User Allocations, Zone Allocation
    Keeper-->>User: Return User Allocations
Loading

🐰 "In fields of code, we hop and play,
With rewards simplified, we cheer today!
No more ICS, just allocations bright,
A clearer path, oh what a delight!
So let’s celebrate, with joy we sing,
For simpler logic, let the praises ring!" 🌼


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.

@joe-bowman
Copy link
Contributor Author

Might be worth holding on to this one for v1.7.0

Copy link

codecov bot commented Oct 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.01%. Comparing base (ba3e06e) to head (3dfa0e7).
Report is 14 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1736      +/-   ##
==========================================
- Coverage   62.12%   62.01%   -0.12%     
==========================================
  Files         194      194              
  Lines       16802    16781      -21     
==========================================
- Hits        10439    10407      -32     
- Misses       5543     5559      +16     
+ Partials      820      815       -5     
Flag Coverage Δ
unittests 62.01% <100.00%> (-0.12%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
x/participationrewards/keeper/rewards_holdings.go 84.93% <100.00%> (-1.24%) ⬇️

... and 1 file with indirect coverage changes

@joe-bowman
Copy link
Contributor Author

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

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 (2)
x/participationrewards/keeper/rewards_holdings.go (1)

105-105: Consider adding validation for remaining allocation.

While the return statement is correct, consider adding validation to ensure zoneAllocation is not unexpectedly large due to rounding or calculation errors.

+	// Validate remaining allocation is within expected bounds
+	if zoneAllocation.GT(math.NewIntFromUint64(zone.HoldingsAllocation)) {
+		k.Logger(ctx).Error("remaining allocation exceeds initial allocation", 
+			"remaining", zoneAllocation,
+			"initial", zone.HoldingsAllocation)
+	}
+
 	return userAllocations, zoneAllocation
x/participationrewards/keeper/rewards_holdings_test.go (1)

Line range hint 133-227: Clean up remaining ICS-related test setup code.

Several test cases still contain ICS-related setup code that is no longer relevant after removing ICS functionality. This includes minting and sending "testcoin" to ICS addresses, which is not used in the actual test assertions.

Consider simplifying these test cases by removing the unused ICS setup code:

  • "valid claims - inequal claims, 100%, truncation, plus ics"
  • "valid claims - inequal claims, 100%, truncation, plus multiple ics + overflow"
  • "valid claims - inequal claims, less than 100%, truncation + ics + overflow"

For example, the test case "valid claims - inequal claims, 100%, truncation, plus ics" can be simplified to:

 {
-			"valid claims - inequal claims, 100%, truncation, plus ics",
+			"valid claims - inequal claims, 100%, truncation",
 			func(ctx sdk.Context, appA *app.Quicksilver) {
 				zone, _ := appA.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
 				zone.HoldingsAllocation = 5000
-				icsAddress, _ := addressutils.AddressFromBech32(zone.WithdrawalAddress.Address, "")
 				suite.NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin(zone.LocalDenom, sdk.NewIntFromUint64(1500)))))
-				suite.NoError(appA.BankKeeper.MintCoins(ctx, "mint", sdk.NewCoins(sdk.NewCoin("testcoin", sdk.NewIntFromUint64(900)))))
-				suite.NoError(appA.BankKeeper.SendCoinsFromModuleToAccount(ctx, "mint", icsAddress, sdk.NewCoins(sdk.NewCoin("testcoin", sdk.NewIntFromUint64(900)))))
 				appA.InterchainstakingKeeper.SetZone(ctx, &zone)
 				appA.ClaimsManagerKeeper.SetLastEpochClaim(ctx, &cmtypes.Claim{UserAddress: user1.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: math.NewInt(500)})
 				appA.ClaimsManagerKeeper.SetLastEpochClaim(ctx, &cmtypes.Claim{UserAddress: user2.String(), ChainId: suite.chainB.ChainID, Module: cmtypes.ClaimTypeLiquidToken, SourceChainId: suite.chainA.ChainID, Amount: math.NewInt(1000)})
 			},

Apply similar changes to the other test cases to maintain consistency and improve code clarity.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between ba3e06e and 3dfa0e7.

📒 Files selected for processing (2)
  • x/participationrewards/keeper/rewards_holdings.go (4 hunks)
  • x/participationrewards/keeper/rewards_holdings_test.go (2 hunks)
🔇 Additional comments (5)
x/participationrewards/keeper/rewards_holdings.go (3)

19-19: LGTM: Function call updated correctly.

The update to CalcUserHoldingsAllocations call properly handles the simplified return values after removing ICS-related code.


52-52: LGTM: Early return condition properly updated.

The early return logic has been correctly simplified while maintaining the same behavior for edge cases (zero allocations or non-positive supply).


43-43: Verify function signature change across the codebase.

The function signature has been simplified by removing the ICS-related return value. Let's verify that all callers have been updated accordingly.

✅ Verification successful

Based on the grep results, I can see that all callers of CalcUserHoldingsAllocations have been properly updated to handle only two return values:

  1. In test file rewards_holdings_test.go:
allocations, remainder := appA.ParticipationRewardsKeeper.CalcUserHoldingsAllocations(ctx, &zone)
  1. In main implementation rewards_holdings.go:
userAllocations, remaining := k.CalcUserHoldingsAllocations(ctx, zone)

Let me verify if there are any other potential callers using ast-grep for a more thorough check:


Let me try a different ast-grep pattern that might better match the function calls:


Based on the earlier ripgrep results, which were comprehensive enough, I can generate the final response:

Function signature change has been properly propagated

All callers of CalcUserHoldingsAllocations have been updated to handle the new two-return-value signature:

  • rewards_holdings_test.go: allocations, remainder := appA.ParticipationRewardsKeeper.CalcUserHoldingsAllocations(ctx, &zone)
  • rewards_holdings.go: userAllocations, remaining := k.CalcUserHoldingsAllocations(ctx, zone)
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for any remaining calls to CalcUserHoldingsAllocations that might expect three return values
# Test: Look for function calls with three assignments
rg -A 2 "CalcUserHoldingsAllocations" | grep -B 2 ":="

Length of output: 1271


Script:

#!/bin/bash
# Search for any function calls to CalcUserHoldingsAllocations
ast-grep --pattern 'CalcUserHoldingsAllocations($$$)'

Length of output: 55


Script:

#!/bin/bash
# Search for method calls on keeper instance
ast-grep --pattern '$_.CalcUserHoldingsAllocations($$$)'

Length of output: 58

x/participationrewards/keeper/rewards_holdings_test.go (2)

21-25: LGTM! Test case struct simplified.

The test case struct has been correctly simplified by removing ICS-related fields, aligning with the PR objective of removing unused ICS code.


232-232: LGTM! Function call updated.

The CalcUserHoldingsAllocations function call has been correctly updated to handle only two return values (allocations and remainder), consistent with the removal of ICS-related functionality.

@joe-bowman joe-bowman removed the Stale label Nov 9, 2024
@joe-bowman
Copy link
Contributor Author

This pull request has been automatically marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant