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

refactor(x/protocolpool): Improve claiming funds logic #20154

Merged
merged 21 commits into from May 8, 2024

Conversation

likhita-809
Copy link
Contributor

@likhita-809 likhita-809 commented Apr 23, 2024

Description

Closes: #XXXX

  • Keep only tranches_left to prevent state mismatch when tranches_left > tranches.
  • Use last_claimed_at to replace start_time and remove next_claim_from.
  • Use a constant field budget_per_tranche
  • cap periodsPassed with tranchesLeft
  • update NextClaimFrom correctly

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

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
    • Enhanced budget management by updating the logic for calculating and claiming funds, focusing on more accurate tracking of budget usage over time.
  • Bug Fixes
    • Corrected budget initialization and validation processes to ensure consistency and reliability in budget handling.
  • Tests
    • Improved test coverage for budget claims, including adjustments for new budget calculation logic and additional test scenarios to verify functionality after extended periods.

Copy link
Contributor

coderabbitai bot commented Apr 23, 2024

Walkthrough

Walkthrough

The recent updates focus on enhancing the budget management logic throughout the codebase. Changes involve transitioning from using StartTime to LastClaimedAt for more precise budget claim tracking. Additionally, adjustments were made to improve the calculation of TranchesLeft and BudgetPerTranche, ensuring better distribution and monitoring of budgets. These modifications span various keeper functions, initialization processes, and testing scenarios to maintain consistency and reliability in budget management.

Changes

File Path Changes Summary
.../keeper/keeper.go Updated functions to use LastClaimedAt, adjust TranchesLeft, and recalibrate BudgetPerTranche.
.../keeper/genesis.go Revised logic in InitGenesis and ExportGenesis to utilize LastClaimedAt and refine budget validation.
.../keeper/msg_server_test.go Enhanced TestMsgClaimBudget with LastClaimedAt and TranchesLeft, introduced BudgetPerTranche, and added a new test case for extended time claims. Updated test setup and naming conventions.

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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@likhita-809 likhita-809 marked this pull request as ready for review April 23, 2024 11:37
@likhita-809 likhita-809 requested a review from a team as a code owner April 23, 2024 11:37
x/protocolpool/keeper/genesis.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Outdated Show resolved Hide resolved
x/protocolpool/keeper/keeper.go Show resolved Hide resolved
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: 1

Out of diff range and nitpick comments (1)
x/protocolpool/keeper/msg_server_test.go (1)

173-173: The startTime variable is redeclared here, which might lead to confusion. Consider renaming it to avoid shadowing the outer startTime.

x/protocolpool/keeper/msg_server_test.go Show resolved Hide resolved
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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 3100806 and d99ba32.
Files selected for processing (2)
  • x/protocolpool/keeper/genesis.go (2 hunks)
  • x/protocolpool/keeper/msg_server_test.go (8 hunks)
Files skipped from review as they are similar to previous changes (2)
  • x/protocolpool/keeper/genesis.go
  • x/protocolpool/keeper/msg_server_test.go

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

Review Details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits Files that changed from the base of the PR and between d99ba32 and 42f6fe3.
Files selected for processing (3)
  • api/cosmos/protocolpool/v1/query.pulsar.go (24 hunks)
  • api/cosmos/protocolpool/v1/tx.pulsar.go (17 hunks)
  • api/cosmos/protocolpool/v1/types.pulsar.go (22 hunks)
Files not summarized due to errors (3)
  • api/cosmos/protocolpool/v1/query.pulsar.go: Error: Message exceeds token limit
  • api/cosmos/protocolpool/v1/tx.pulsar.go: Error: Message exceeds token limit
  • api/cosmos/protocolpool/v1/types.pulsar.go: Error: Message exceeds token limit
Additional Context Used
Path-based Instructions (3)
api/cosmos/protocolpool/v1/types.pulsar.go (1)

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

api/cosmos/protocolpool/v1/query.pulsar.go (1)

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

api/cosmos/protocolpool/v1/tx.pulsar.go (1)

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

Additional comments not posted (40)
api/cosmos/protocolpool/v1/types.pulsar.go (17)

24-24: Addition of fd_Budget_last_claimed_at field descriptor.

This change aligns with the PR's objective to replace start_time with last_claimed_at.


25-25: Addition of fd_Budget_tranches_left field descriptor.

This change supports the simplification of state management by focusing on the tranches_left field.


26-26: Addition of fd_Budget_budget_per_tranche field descriptor.

This supports the standardization of the budget per tranche, enhancing predictability and consistency in fund distribution.


118-120: Proper handling of last_claimed_at in the Range method.

This ensures that the new last_claimed_at field is correctly processed during message reflection.


130-134: Proper handling of budget_per_tranche in the Range method.

This ensures that the new budget_per_tranche field is correctly processed during message reflection.


161-162: Proper handling of last_claimed_at in the Has method.

This ensures that the presence of the last_claimed_at field is correctly reported.


165-166: Proper handling of budget_per_tranche in the Has method.

This ensures that the presence of the budget_per_tranche field is correctly reported.


189-190: Proper handling of last_claimed_at in the Clear method.

This ensures that the last_claimed_at field can be correctly cleared.


193-194: Proper handling of budget_per_tranche in the Clear method.

This ensures that the budget_per_tranche field can be correctly cleared.


219-220: Proper handling of last_claimed_at in the Get method.

This ensures that the last_claimed_at field can be correctly retrieved.


225-227: Proper handling of budget_per_tranche in the Get method.

This ensures that the budget_per_tranche field can be correctly retrieved.


255-256: Proper handling of last_claimed_at in the Set method.

This ensures that the last_claimed_at field can be correctly set.


259-260: Proper handling of budget_per_tranche in the Set method.

This ensures that the budget_per_tranche field can be correctly set.


288-292: Proper handling of last_claimed_at in the Mutable method.

This ensures that a mutable reference to the last_claimed_at field can be obtained.


293-297: Proper handling of budget_per_tranche in the Mutable method.

This ensures that a mutable reference to the budget_per_tranche field can be obtained.


325-325: Proper handling of last_claimed_at in the NewField method.

This ensures that a new instance of the last_claimed_at field can be created.


330-332: Proper handling of budget_per_tranche in the NewField method.

This ensures that a new instance of the budget_per_tranche field can be created.

api/cosmos/protocolpool/v1/query.pulsar.go (7)

Line range hint 1-1: Ensure the file has the correct package declaration and imports.


2136-2136: Ensure the claimed_amount field in QueryUnclaimedBudgetResponse is correctly documented and matches the protobuf definition.


2138-2138: Ensure the unclaimed_amount field in QueryUnclaimedBudgetResponse is correctly documented and matches the protobuf definition.


2141-2141: Ensure the next_claim_from field in QueryUnclaimedBudgetResponse is correctly documented and matches the protobuf definition.


2143-2143: Ensure the period field in QueryUnclaimedBudgetResponse is correctly documented and matches the protobuf definition.


2145-2145: Ensure the tranches_left field in QueryUnclaimedBudgetResponse is correctly documented and matches the protobuf definition.


2322-2326: Review the protobuf service definitions to ensure they are correctly defined and match the intended functionality.

api/cosmos/protocolpool/v1/tx.pulsar.go (16)

1914-1920: Ensure that the field descriptors are correctly defined and match the protobuf message structure.


2011-2013: Check the logic for handling BudgetPerTranche to ensure it correctly reflects the protobuf structure and handles null cases appropriately.

Verification successful

The review comment suggests verifying the handling of BudgetPerTranche in the protobuf structure, particularly focusing on the correct handling of null cases and the overall structure.

From the output of the script, we can observe several key points:

  1. Protobuf Definition and Accessors: BudgetPerTranche is defined as a pointer to a types.Coin structure in various protobuf files (types.pb.go, tx.pb.go). This allows for the field to be nil, representing a null case.

  2. Null Handling in Code: There are multiple checks for nil across different files (types.pb.go, tx.pb.go, types.pulsar.go, tx.pulsar.go). When BudgetPerTranche is nil, new instances of types.Coin are often created, indicating robust handling of null cases.

  3. Usage in Business Logic: The field is used in calculations and logic, such as in the keeper.go file where it's used to calculate budget amounts left to distribute. This suggests that the field is integral to the business logic and is handled appropriately.

  4. Tests: The msg_server_test.go file includes tests where BudgetPerTranche is set to various values, including valid and invalid coins, which shows that the system is tested for both normal and edge cases.

Given this information, it appears that the handling of BudgetPerTranche in the protobuf structure, including null cases, is implemented correctly and thoroughly throughout the codebase. The checks for nil and the initialization of new instances when needed are consistent with good programming practices for handling optional fields in protobufs.

Based on the evidence from the script output and the analysis of how BudgetPerTranche is used and tested across the codebase, the handling of this field seems to be correct and robust.

Final Response:

The handling of BudgetPerTranche in the protobuf structure, including the management of null cases, has been verified and found to be implemented correctly across the codebase. The field is appropriately checked for null values, and there are sufficient tests covering various scenarios.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the handling of BudgetPerTranche in the protobuf structure.

# Test: Search for the handling of BudgetPerTranche. Expect: Correct handling of null cases and structure.
rg --type go $'BudgetPerTranche'

Length of output: 8903


2054-2055: Ensure that the check for BudgetPerTranche being non-null is consistent with the expected behavior in the system.


2082-2083: Review the logic for setting BudgetPerTranche to nil, ensuring it aligns with the intended use cases and system requirements.


2112-2113: Check the return value for BudgetPerTranche to ensure it correctly uses the protobuf reflection.


2148-2149: Ensure that the assignment of BudgetPerTranche from a protobuf message is handled correctly and safely.


2176-2180: Review the logic in the Mutable method for BudgetPerTranche to ensure it correctly initializes and returns the expected value.


2214-2214: Check the creation of a new BudgetPerTranche instance to ensure it is correctly initialized and returned.


2302-2303: Ensure that the size calculation for BudgetPerTranche is accurate and aligns with the protobuf structure.


2379-2380: Review the marshaling logic for BudgetPerTranche to ensure it handles errors appropriately and follows best practices.


2522-2522: Ensure that the error handling for the wrong wire type for BudgetPerTranche is robust and provides clear error messages.


2549-2552: Review the unmarshaling logic for BudgetPerTranche to ensure it correctly handles errors and initializes the field properly.


7019-7024: Ensure that the protobuf definition for BudgetPerTranche is correctly annotated and matches the expected data types and structure.


7066-7068: Check the getter method for BudgetPerTranche to ensure it correctly handles nil cases and returns the expected type.


Line range hint 7521-7536: Review the protobuf encoding for MsgSubmitBudgetProposal to ensure it correctly handles the BudgetPerTranche field and aligns with the protobuf standards.


7741-7741: Ensure that the type references for budget_per_tranche in the protobuf file are correct and match the expected types.

Copy link
Member

@facundomedica facundomedica left a comment

Choose a reason for hiding this comment

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

LGTM, we might be able to do further simplification on stuff like ClaimedAmount, but that would require more analysis that we can do later

Copy link
Member

@julienrbrt julienrbrt left a comment

Choose a reason for hiding this comment

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

utACK!

@julienrbrt julienrbrt added this pull request to the merge queue May 8, 2024
Merged via the queue into main with commit 03d70aa May 8, 2024
66 checks passed
@julienrbrt julienrbrt deleted the likhita/fix-protocolpool branch May 8, 2024 12:50
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.

None yet

3 participants