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

feat(x/protocolpool,x/distribution)!: remove dependency + fix continuous fund bug #20790

Merged
merged 46 commits into from
Jul 24, 2024

Conversation

facundomedica
Copy link
Member

@facundomedica facundomedica commented Jun 26, 2024

Description

This PR is a proposal to remove the dependency that exists between x/distribution and x/protocolpool.

Main changes:

  • x/distribution does not require x/protocolpool anymore, it sends a simple bank send to a predefined x/protocolpool account. This is an "intermediary" account, that its only purpose is to hold this tokens until they get distributed by x/protocolpool (otherwise it's difficult to know how many tokens were added to be distributed).

  • x/protocolpool now has its own BeginBlocker where it takes the funds from the intermediary account and sends them to community pool and the stream account.

  • x/distribution uses the bank module to interact with x/protocolpool (there are a couple of instances in which it does a send "impersonating" x/protocolpool, but those are deprecated endpoints).

  • fixes bug that was causing expired continuous funds from withdrawing if they didn't withdraw at every height.

Before: x/distr would make a bank send to the community pool and also call SetToDistribute (because we needed to know how many tokens there were to distribute).

graph TD
    A[ABCI BeginBlock] --> B[x/distr Module]
    B --> C[x/bank Send to x/protocolpool]
    C --> D[x/protocolpool SetToDistribute]
    D --> E[End]
Loading

After this PR: x/distribution does a simple bank send to an intermediary account held by protocol pool (pool_distr), which then in its own BeginBlock x/protocolpool will distribute accordingly. x/distribution knows nothing other than the name of the intermediary account.

graph TD
    A[ABCI BeginBlock] --> B[x/distribution's BeginBlock]
    B --> C[Bank Send to <b>pool_distr</b> Intermediary Account]
    
    A --> D[x/protocolpool's BeginBlock]
    D --> E[Distribute Funds from <b>pool_distr</b>]
    E --> G[Community Pool]
    E --> H[Stream Account]
Loading

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 Distribution data structure to manage distributions with timestamp and amount.
    • Enhanced account management by integrating the ProtocolPoolDistrAccount into the application.
  • Bug Fixes

    • Fixed distribution settings during genesis initialization to ensure accurate account balances.
  • Documentation

    • Updated comments for UnbondingDelegation and Redelegation messages for better readability.
  • Refactor

    • Modified initialization logic to set default values for LastBalance and Distributions.
    • Improved the module management structure for better clarity and maintainability.

Copy link
Contributor

coderabbitai bot commented Jun 26, 2024

Walkthrough

Walkthrough

The recent updates involve significant modifications to the distribution handling in the InitGenesis and ExportGenesis functions, transitioning from ToDistribute to a new Distributions structure. This includes improvements in the genesis state initialization, updates to the protocol buffer definitions, and enhancements to test cases to accommodate the new distribution logic.

Changes

File Change Summary
x/protocolpool/keeper/genesis.go, x/protocolpool/keeper/genesis_test.go Updated genesis functions to use Distributions, enhanced test logic to verify new distribution handling.
x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto Introduced Distribution message and updated imports for google/protobuf/timestamp.proto.
x/protocolpool/types/genesis.go Adjusted NewGenesisState to initialize LastBalance and Distributions.
x/staking/proto/cosmos/staking/v1beta1/staking.proto Made minor adjustments to comment spacing in UnbondingDelegation and Redelegation messages.
simapp/app.go, simapp/app_config.go Expanded module account permissions and improved ModuleManager initialization for better clarity.

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

@github-actions github-actions bot added C:x/distribution distribution module related C:x/protocolpool labels Jun 26, 2024
@facundomedica facundomedica changed the title feat(x/protocolpool,x/distribution)!: remove dependency feat(x/protocolpool,x/distribution)!: remove dependency (proposal) Jun 26, 2024
x/protocolpool/keeper/keeper.go Dismissed Show dismissed Hide dismissed
x/protocolpool/module.go Dismissed Show dismissed Hide dismissed
@facundomedica facundomedica changed the base branch from main to facu/protopool-imp June 27, 2024 14:47
@facundomedica facundomedica marked this pull request as ready for review July 10, 2024 13:29
@facundomedica facundomedica requested a review from a team as a code owner July 10, 2024 13:29
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

Outside diff range, codebase verification and nitpick comments (2)
simapp/v2/app_config.go (1)

80-80: Add a comment to explain the purpose of ProtocolPoolDistrAccount.

While the addition of pooltypes.ProtocolPoolDistrAccount is clear, adding a comment explaining its role would improve code readability and maintainability.

		{Account: pooltypes.StreamAccount},
+		// Account for protocol pool distribution
		{Account: pooltypes.ProtocolPoolDistrAccount},
simapp/app_config.go (1)

82-82: Add a comment to explain the purpose of ProtocolPoolDistrAccount.

While the addition of pooltypes.ProtocolPoolDistrAccount is clear, adding a comment explaining its role would improve code readability and maintainability.

		{Account: pooltypes.StreamAccount},
+		// Account for protocol pool distribution
		{Account: pooltypes.ProtocolPoolDistrAccount},
Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 5d66cf9 and c1deb95.

Files ignored due to path filters (1)
  • x/distribution/go.sum is excluded by !**/*.sum
Files selected for processing (39)
  • scripts/mockgen.sh (1 hunks)
  • simapp/app.go (4 hunks)
  • simapp/app_config.go (2 hunks)
  • simapp/v2/app_config.go (2 hunks)
  • tests/integration/distribution/keeper/msg_server_test.go (2 hunks)
  • tests/integration/gov/keeper/keeper_test.go (1 hunks)
  • tests/integration/protocolpool/module_test.go (2 hunks)
  • testutil/configurator/configurator.go (2 hunks)
  • x/distribution/CHANGELOG.md (2 hunks)
  • x/distribution/depinject.go (2 hunks)
  • x/distribution/go.mod (1 hunks)
  • x/distribution/keeper/allocation.go (2 hunks)
  • x/distribution/keeper/allocation_test.go (8 hunks)
  • x/distribution/keeper/delegation_test.go (18 hunks)
  • x/distribution/keeper/grpc_query.go (1 hunks)
  • x/distribution/keeper/grpc_query_test.go (2 hunks)
  • x/distribution/keeper/keeper.go (3 hunks)
  • x/distribution/keeper/keeper_test.go (4 hunks)
  • x/distribution/keeper/migrations.go (1 hunks)
  • x/distribution/keeper/msg_server.go (2 hunks)
  • x/distribution/keeper/msg_server_test.go (2 hunks)
  • x/distribution/migrations/v4/migrate_funds_test.go (2 hunks)
  • x/distribution/module.go (1 hunks)
  • x/distribution/testutil/expected_keepers_mocks.go (1 hunks)
  • x/distribution/types/expected_keepers.go (1 hunks)
  • x/distribution/types/keys.go (1 hunks)
  • x/gov/testutil/expected_keepers.go (1 hunks)
  • x/gov/testutil/expected_keepers_mocks.go (1 hunks)
  • x/gov/types/expected_keepers.go (1 hunks)
  • x/protocolpool/CHANGELOG.md (1 hunks)
  • x/protocolpool/keeper/genesis.go (2 hunks)
  • x/protocolpool/keeper/genesis_test.go (1 hunks)
  • x/protocolpool/keeper/keeper.go (7 hunks)
  • x/protocolpool/keeper/keeper_test.go (5 hunks)
  • x/protocolpool/keeper/msg_server.go (3 hunks)
  • x/protocolpool/keeper/msg_server_test.go (12 hunks)
  • x/protocolpool/module.go (2 hunks)
  • x/protocolpool/types/errors.go (1 hunks)
  • x/protocolpool/types/keys.go (2 hunks)
Files skipped from review due to trivial changes (8)
  • scripts/mockgen.sh
  • tests/integration/protocolpool/module_test.go
  • x/distribution/go.mod
  • x/distribution/keeper/delegation_test.go
  • x/distribution/migrations/v4/migrate_funds_test.go
  • x/distribution/module.go
  • x/distribution/testutil/expected_keepers_mocks.go
  • x/protocolpool/types/errors.go
Additional context used
Path-based instructions (31)
x/protocolpool/CHANGELOG.md (1)

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

x/protocolpool/types/keys.go (1)

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

x/protocolpool/keeper/genesis_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

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

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

x/distribution/depinject.go (1)

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

x/gov/testutil/expected_keepers.go (1)

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

x/distribution/types/expected_keepers.go (1)

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

x/gov/types/expected_keepers.go (1)

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

x/protocolpool/keeper/genesis.go (1)

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

x/protocolpool/module.go (1)

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

x/distribution/types/keys.go (1)

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

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

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

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

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

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

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/distribution/CHANGELOG.md (1)

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

tests/integration/gov/keeper/keeper_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/protocolpool/keeper/keeper_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

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

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

x/protocolpool/keeper/msg_server.go (1)

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

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

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

simapp/v2/app_config.go (1)

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

simapp/app_config.go (1)

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

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

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

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

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

testutil/configurator/configurator.go (1)

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

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

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/gov/testutil/expected_keepers_mocks.go (1)

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

x/protocolpool/keeper/keeper.go (1)

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

simapp/app.go (1)

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

tests/integration/distribution/keeper/msg_server_test.go (3)

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


Pattern tests/**/*: "Assess the integration and e2e test code assessing sufficient code coverage for the changes associated in the pull request"


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/protocolpool/keeper/msg_server_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

Learnings (3)
x/protocolpool/keeper/genesis_test.go (1)
Learnt from: likhita-809
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
x/protocolpool/keeper/genesis.go (1)
Learnt from: likhita-809
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
x/distribution/keeper/allocation.go (1)
Learnt from: julienrbrt
PR: cosmos/cosmos-sdk#18539
File: x/distribution/keeper/allocation.go:26-42
Timestamp: 2023-11-22T14:50:39.724Z
Learning: User clarified that the addition of fees to the DecimalPool is handled in a different part of the code when `totalPreviousPower` is zero.
GitHub Check: CodeQL
x/protocolpool/module.go

[warning] 118-118: Panic in BeginBock or EndBlock consensus methods
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call

x/protocolpool/keeper/keeper.go

[warning] 481-481: Panic in BeginBock or EndBlock consensus methods
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call

Additional comments not posted (68)
x/protocolpool/CHANGELOG.md (1)

28-30: Changelog entry is clear and follows the guidelines.

The entry correctly mentions the improvement and provides a reference to the GitHub pull request.

x/protocolpool/types/keys.go (1)

32-33: New constants are correctly defined.

The new constants DistributionsKey and LastBalanceKey follow the naming conventions and are properly defined.

x/protocolpool/keeper/genesis_test.go (1)

34-35: Mocks are correctly set up for testing.

The mocks for GetModuleAccount and GetAllBalances are correctly set up to simulate the expected behavior.

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

45-45: Ensure proper error handling during fund migration.

The function correctly retrieves the module account and migrates the funds, but ensure that error handling is thorough and covers all edge cases.

x/distribution/depinject.go (1)

77-77: Refactored to remove PoolKeeper dependency.

The ProvideModule function has been correctly refactored to remove the PoolKeeper dependency and update the NewAppModule call.

x/gov/testutil/expected_keepers.go (1)

46-46: Removed PoolKeeper interface.

The PoolKeeper interface has been correctly removed in alignment with the PR objectives.

x/gov/types/expected_keepers.go (1)

54-54: Removed PoolKeeper interface.

The PoolKeeper interface has been correctly removed in alignment with the PR objectives.

x/protocolpool/keeper/genesis.go (2)

52-52: LGTM! Code changes approved.

The addition of setting distributions in the genesis state is correct.


99-108: LGTM! Code changes approved.

The addition of exporting balances and setting the amount to distribute is correct.

x/protocolpool/module.go (2)

Line range hint 87-95: LGTM! Code changes approved.

The InitGenesis method correctly initializes the genesis state using the keeper.


116-119: Verify potential panic calls in BeginBlocker.

Static analysis tools indicate potential panic calls within the BeginBlocker method. Ensure that the BeginBlocker method handles errors gracefully and does not cause a panic.

Verification successful

No panic calls found in BeginBlocker methods.

The BeginBlocker methods in x/slashing/abci.go and x/authz/module/abci.go do not contain any panic calls, indicating that they handle errors gracefully.

  • x/slashing/abci.go
  • x/authz/module/abci.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify potential panic calls within the BeginBlocker method.

# Test: Search for panic calls within BeginBlocker. Expect: No panic calls.
rg --type go -A 5 $'func BeginBlocker'

Length of output: 907


Script:

#!/bin/bash
# Description: Verify potential panic calls within the full body of the BeginBlocker methods.

# Search for panic calls within the BeginBlocker method in x/slashing/abci.go
rg --type go -A 50 'func BeginBlocker' x/slashing/abci.go | rg 'panic'

# Search for panic calls within the BeginBlocker method in x/authz/module/abci.go
rg --type go -A 50 'func BeginBlocker' x/authz/module/abci.go | rg 'panic'

Length of output: 145

Tools
GitHub Check: CodeQL

[warning] 118-118: Panic in BeginBock or EndBlock consensus methods
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call

x/distribution/types/keys.go (2)

27-30: LGTM! Code changes approved.

The addition of the ProtocolPoolDistrAccount constant and its documentation is correct.


31-32: LGTM! Code changes approved.

The addition of the ProtocolPoolModuleName constant and its documentation is correct.

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

82-82: LGTM! Code changes approved.

The addition of sending tokens to the ProtocolPoolDistrAccount is correct.


168-168: LGTM! Code changes approved.

The addition of sending tokens to the ProtocolPoolDistrAccount is correct.

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

151-155: LGTM!

The changes correctly mock the necessary methods to test the community pool query.

x/distribution/CHANGELOG.md (2)

34-35: LGTM!

The improvement is correctly documented.


Line range hint 38-59:
LGTM!

The breaking changes are correctly documented.

Tools
LanguageTool

[style] ~39-~39: Consider a shorter alternative to avoid wordiness.
Context: ...x/distribution now takes cometService in order to get consensus related information. * [#...

(IN_ORDER_TO_PREMIUM)

Markdownlint

41-41: Expected: 2; Actual: 4
Unordered list indentation

(MD007, ul-indent)

tests/integration/gov/keeper/keeper_test.go (1)

70-76: LGTM!

The changes correctly add the new account to the permissions map.

x/protocolpool/keeper/keeper_test.go (4)

30-32: Correct initialization of ProtocolPoolDistrAccount.

The initialization of ProtocolPoolDistrAccount as a module account looks correct.


61-61: Correct setup of mock expectations for ProtocolPoolDistrAccount.

The mock expectations for ProtocolPoolDistrAccount are correctly added.


107-114: Correct setup of mock expectations in mockStreamFunds.

The mock expectations for ProtocolPoolDistrAccount in the mockStreamFunds function are correctly added.


125-129: Correct setup of mock expectations in TestIterateAndUpdateFundsDistribution.

The mock expectations for ProtocolPoolDistrAccount in the TestIterateAndUpdateFundsDistribution function are correctly added.

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

117-117: Correct update of FundCommunityPool method call.

The method call in the FundCommunityPool function is correctly updated to use ProtocolPoolModuleName.


161-161: Correct update of CommunityPoolSpend method call.

The method call in the CommunityPoolSpend function is correctly updated to use ProtocolPoolModuleName.

x/protocolpool/keeper/msg_server.go (3)

142-146: Correct distribution of funds before creating continuous funds.

The code correctly distributes funds before creating continuous funds to avoid giving the new fund more than it should get.


169-178: Correct distribution of funds before withdrawing continuous funds.

The code correctly distributes funds before withdrawing continuous funds to ensure accurate fund allocation.


201-202: Correct distribution of funds before canceling continuous funds.

The code correctly distributes funds before canceling continuous funds to ensure accurate fund allocation.

simapp/v2/app_config.go (1)

119-119: Ensure BeginBlockers are ordered correctly.

The addition of pooltypes.ModuleName to the BeginBlockers list is correct. Ensure the order aligns with the intended execution sequence.

simapp/app_config.go (1)

121-121: Ensure BeginBlockers are ordered correctly.

The addition of pooltypes.ModuleName to the BeginBlockers list is correct. Ensure the order aligns with the intended execution sequence.

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

184-185: Verify the correctness of the SendCoinsFromAccountToModule call.

The expectation for SendCoinsFromAccountToModule aligns with the new interaction model. Ensure that the method call and parameters are correct.


292-293: Verify the correctness of the SendCoinsFromModuleToAccount call.

The expectation for SendCoinsFromModuleToAccount aligns with the new interaction model. Ensure that the method call and parameters are correct.

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

376-382: Ensure the ProtocolPoolModuleName is correctly defined and used.

The changes correctly replace poolKeeper with authKeeper and bankKeeper. Verify that types.ProtocolPoolModuleName is defined and used consistently.

testutil/configurator/configurator.go (2)

53-53: Addition of ProtocolPoolModuleName to BeginBlockersOrder

The addition of testutil.ProtocolPoolModuleName to the BeginBlockersOrder ensures that the ProtocolPool module's BeginBlock operations are executed. This aligns with the PR objective of making the x/protocolpool module independent and capable of handling its own fund distribution.


168-168: Addition of protocolpool_distr module account

The addition of the protocolpool_distr module account is necessary for the new intermediary account setup described in the PR objectives. This change supports the new fund distribution mechanism.

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

199-199: Update in TestAllocateTokensToManyValidators to use ProtocolPoolDistrAccount

The change ensures that the distribution logic now correctly sends community pool coins to the new intermediary account (disttypes.ProtocolPoolDistrAccount). This update is in line with the PR objective to decouple x/distribution from x/protocolpool.

However, ensure that the new intermediary account logic is thoroughly tested.

Verification successful

We need to verify the context in which ProtocolPoolDistrAccount is being tested in the relevant test files. Specifically, let's look at the tests in x/protocolpool/keeper/keeper_test.go and x/distribution/keeper/allocation_test.go.


Verification Successful: Thorough Testing of ProtocolPoolDistrAccount

The intermediary account logic for ProtocolPoolDistrAccount is thoroughly tested in the codebase. The extracted test contexts from x/protocolpool/keeper/keeper_test.go and x/distribution/keeper/allocation_test.go confirm that various interactions involving ProtocolPoolDistrAccount are covered.

  • x/protocolpool/keeper/keeper_test.go: Tests interactions with account keeper and bank keeper.
  • x/distribution/keeper/allocation_test.go: Tests token allocation involving this account.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the intermediary account logic is thoroughly tested.

# Test: Search for test cases using `disttypes.ProtocolPoolDistrAccount`.
rg --type go 'ProtocolPoolDistrAccount'

Length of output: 3504


Script:

#!/bin/bash
# Extract lines around the references to ProtocolPoolDistrAccount in test files for deeper context.

# Extracting from keeper_test.go
rg --type go --context 10 'ProtocolPoolDistrAccount' x/protocolpool/keeper/keeper_test.go

# Extracting from allocation_test.go
rg --type go --context 10 'ProtocolPoolDistrAccount' x/distribution/keeper/allocation_test.go

Length of output: 6391


350-350: Update in TestAllocateTokensTruncation to use ProtocolPoolDistrAccount

This line ensures that the allocation logic for truncation tests now correctly sends coins to the new intermediary account (disttypes.ProtocolPoolDistrAccount). This update aligns with the decoupling of x/distribution from x/protocolpool.

Ensure that the truncation logic is thoroughly tested with the new intermediary account.

Verification successful

Verification Successful: Truncation Logic Tested with ProtocolPoolDistrAccount

The test case TestAllocateTokensTruncation in x/distribution/keeper/allocation_test.go correctly includes the usage of ProtocolPoolDistrAccount, ensuring that the truncation logic is thoroughly tested with the new intermediary account.

  • x/distribution/keeper/allocation_test.go: TestAllocateTokensTruncation
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the truncation logic with the intermediary account is thoroughly tested.

# Test: Search for test cases using `disttypes.ProtocolPoolDistrAccount`.
rg --type go 'ProtocolPoolDistrAccount'

Length of output: 3504


Script:

#!/bin/bash
# Description: Verify the truncation logic in TestAllocateTokensTruncation with the intermediary account.

# Test: Search for the specific test case `TestAllocateTokensTruncation` and inspect its usage of `ProtocolPoolDistrAccount`.
rg --type go 'TestAllocateTokensTruncation' -A 20

Length of output: 2078


Script:

#!/bin/bash
# Description: Verify the truncation logic in TestAllocateTokensTruncation with the intermediary account.

# Test: Search for the specific test case `TestAllocateTokensTruncation` and inspect its usage of `ProtocolPoolDistrAccount` with more context.
rg --type go 'TestAllocateTokensTruncation' -A 100

Length of output: 8709


Script:

#!/bin/bash
# Description: Verify the truncation logic in TestAllocateTokensTruncation with the intermediary account.

# Test: Search for the specific test case `TestAllocateTokensTruncation` and inspect its usage of `ProtocolPoolDistrAccount` with a larger context.
rg --type go 'TestAllocateTokensTruncation' -A 200

Length of output: 11162

x/gov/testutil/expected_keepers_mocks.go (1)

293-293: Removal of FundCommunityPool method from MockPoolKeeper

The removal of the FundCommunityPool method from the MockPoolKeeper aligns with the PR's objective to decouple x/distribution from x/protocolpool. This change ensures that the distribution module no longer relies on the pool keeper for community pool funding.

x/protocolpool/keeper/keeper.go (6)

38-39: Addition of Distributions and LastBalance collections

The addition of these collections is essential for tracking distributions and the last balance in the protocol pool module. This change supports the new fund distribution mechanism described in the PR objectives.


52-55: Ensure module accounts are set

The additional checks ensure that the module accounts for types.ModuleName, types.StreamAccount, and types.ProtocolPoolDistrAccount are set. This is crucial for the proper functioning of the protocol pool module.


69-70: Initialization of Distributions and LastBalance collections

The initialization of these collections ensures they are properly set up in the keeper. This is necessary for the new distribution logic to function correctly.


143-181: Implementation of SetToDistribute method

The SetToDistribute method calculates the amount to be distributed among recipients and updates the last balance. This method is crucial for the new fund distribution mechanism described in the PR objectives.


185-300: Implementation of IterateAndUpdateFundsDistribution method

The IterateAndUpdateFundsDistribution method iterates over continuous funds and distributions, calculates each recipient's share, and updates the recipient fund distribution. This method is essential for the new continuous fund distribution logic described in the PR objectives.


480-482: Implementation of BeginBlocker method

The BeginBlocker method calls SetToDistribute to set the amount to be distributed at the beginning of each block. This aligns with the new fund distribution mechanism described in the PR objectives.

However, ensure that the BeginBlocker method does not lead to any panics, as indicated by the CodeQL warning.

Tools
GitHub Check: CodeQL

[warning] 481-481: Panic in BeginBock or EndBlock consensus methods
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call
path flow from Begin/EndBlock to a panic call

simapp/app.go (4)

126-135: Addition of protocolpool related accounts in maccPerms

These lines add the ProtocolPoolDistrAccount along with other necessary accounts to the maccPerms map. This ensures that the module accounts are correctly set up with the required permissions.


357-357: Update DistrKeeper initialization

This line removes the PoolKeeper from the DistrKeeper initialization, reflecting the decoupling of the x/distribution module from the x/protocolpool module. The change appears correct and aligns with the PR objective.


450-450: Update module manager with DistrKeeper

This line updates the module manager to reflect the new DistrKeeper initialization without the PoolKeeper. This change aligns with the decoupling objective.


476-476: Update SetOrderBeginBlockers with pooltypes.ModuleName

This line ensures that the BeginBlocker for the protocolpool module is correctly set in the module manager. This is necessary for the protocolpool module to function independently.

tests/integration/distribution/keeper/msg_server_test.go (3)

89-94: Addition of protocolpool related accounts in maccPerms

These lines add ProtocolPoolDistrAccount along with other necessary accounts to the maccPerms map in the test setup. This ensures that the module accounts are correctly set up with the required permissions for testing.


141-141: Update distrKeeper initialization

This line removes the PoolKeeper from the distrKeeper initialization in the test setup, reflecting the decoupling of the x/distribution module from the x/protocolpool module. The change appears correct and aligns with the PR objective.


147-147: Update module manager with DistrKeeper

This line updates the module manager to reflect the new distrKeeper initialization without the PoolKeeper. This change aligns with the decoupling objective and ensures the tests are set up correctly.

x/protocolpool/keeper/msg_server_test.go (17)

6-7: LGTM! Ensure test cases are comprehensive.

The new imports are valid and necessary for the added functionality.


408-408: LGTM! Ensure test cases are comprehensive.

The test case for "recipient with no continuous fund" is valid.


446-446: LGTM! Ensure test cases are comprehensive.

The test case for setting distributions is valid.


453-453: LGTM! Ensure test cases are comprehensive.

The test case for expired funds with no funds left to withdraw is valid.


488-490: LGTM! Ensure test cases are comprehensive.

The test case for valid withdrawal with zero distribution amount is valid.


510-511: LGTM! Ensure test cases are comprehensive.

The test case for valid withdrawal with non-zero distribution amount is valid.


535-536: LGTM! Ensure test cases are comprehensive.

The test case for valid withdrawal with multiple continuous funds is valid.


592-593: LGTM! Ensure test cases are comprehensive.

The test case for setting distributions with multiple continuous funds is valid.


851-852: LGTM! Ensure test cases are comprehensive.

The test case for setting distributions is valid.


957-958: LGTM! Ensure test cases are comprehensive.

The test case for streaming funds is valid.


969-973: LGTM! Ensure test cases are comprehensive.

The test case for repeated withdrawal attempts after expiration is valid.


978-979: LGTM! Ensure test cases are comprehensive.

The test case for setting distributions after multiple withdrawals is valid.


987-992: LGTM! Ensure test cases are comprehensive.

The test case for canceling a continuous fund is valid.


994-1000: LGTM! Ensure test cases are comprehensive.

The test case for canceling an expired continuous fund is valid.


1001-1008: LGTM! Ensure test cases are comprehensive.

The test case for repeated cancellation attempts of the same continuous fund is valid.


1010-1024: LGTM! Ensure test case is comprehensive.

The test case for funding the community pool is valid.


1026-1040: LGTM! Ensure test case is comprehensive.

The test case for spending from the community pool is valid.

@@ -78,7 +75,7 @@ func initFixture(t *testing.T) (sdk.Context, []sdk.AccAddress, keeper.Keeper, de
params := types.DefaultParams()
require.NoError(t, distrKeeper.Params.Set(ctx, params))

return ctx, addrs, distrKeeper, dep{bankKeeper, stakingKeeper, accountKeeper, poolKeeper}
return ctx, addrs, distrKeeper, dep{bankKeeper, stakingKeeper, accountKeeper}
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing distrAcc dependency.

The distrAcc variable is not defined, causing the GetModuleAddress call to fail.

- accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress())
+ distrAcc := authtypes.NewEmptyModuleAccount("distribution")
+ accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress())
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
return ctx, addrs, distrKeeper, dep{bankKeeper, stakingKeeper, accountKeeper}
distrAcc := authtypes.NewEmptyModuleAccount("distribution")
accountKeeper.EXPECT().GetModuleAddress("distribution").Return(distrAcc.GetAddress())
return ctx, addrs, distrKeeper, dep{bankKeeper, stakingKeeper, accountKeeper}

"context"
"errors"
"fmt"
"sort"
Copy link
Contributor

Choose a reason for hiding this comment

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

Ensure proper error wrapping

The errors package is imported but not used in the provided code. Ensure that all errors are wrapped correctly using errorsmod.Wrapf or similar functions for consistent error handling.

- import (
-	"errors"
- )
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
"sort"
"sort"

Copy link
Contributor

@akhilkumarpilli akhilkumarpilli left a comment

Choose a reason for hiding this comment

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

lgtm

if err != nil {
return nil, err
}

genState.ToDistribute = balances.AmountOf(bondDenom)

// TODO: fix export by adding all the funds to be distributed
Copy link
Member

Choose a reason for hiding this comment

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

will this be completed in a follow up pr?

Copy link
Member Author

Choose a reason for hiding this comment

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

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, codebase verification and nitpick comments (2)
api/cosmos/staking/v1beta1/staking.pulsar.go (2)

15064-15064: Deprecated function needs documentation on alternatives.

The function GetHistoricalEntries is marked as deprecated. It would be beneficial to provide information on what should be used instead, if applicable.

// Deprecated: Do not use. Use [alternative method] instead.
func (x *Params) GetHistoricalEntries() uint32 {
	if x != nil {
		return x.HistoricalEntries
	}
}

15011-15012: Clarify the deprecation of HistoricalEntries and provide migration guidance.

The HistoricalEntries field is marked as deprecated, but there is no documentation or comments regarding the migration plans or alternatives. It is essential to provide clear guidance to developers on how to handle this deprecation to avoid potential issues.

  • File: x/staking/types/staking.pb.go
  • Line: 4
  • Code: HistoricalEntries uint32 protobuf:"varint,4,opt,name=historical_entries,json=historicalEntries,proto3" json:"historical_entries,omitempty" // Deprecated: Do not use.

Please add documentation or comments to clarify the deprecation and provide migration guidance.

Analysis chain

Clarify the use of the HistoricalEntries field.

The HistoricalEntries field is marked as deprecated but still present in the protobuf definition. It's important to ensure that deprecating this does not affect existing systems that might rely on this field.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for usage of `HistoricalEntries` to ensure it's not actively used in critical paths.
rg --type go "HistoricalEntries"

Length of output: 4405


Script:

#!/bin/bash
# Description: Search for any comments or documentation regarding the deprecation and migration plans for `HistoricalEntries`.
rg --type go "HistoricalEntries" -A 5 | grep -i "deprecat\|migrat\|alternat"

Length of output: 275

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c1deb95 and 4dc77b1.

Files ignored due to path filters (2)
  • x/protocolpool/types/genesis.pb.go is excluded by !**/*.pb.go
  • x/staking/types/staking.pb.go is excluded by !**/*.pb.go
Files selected for processing (7)
  • api/cosmos/protocolpool/v1/genesis.pulsar.go (15 hunks)
  • api/cosmos/staking/v1beta1/staking.pulsar.go (4 hunks)
  • x/protocolpool/keeper/genesis.go (3 hunks)
  • x/protocolpool/keeper/genesis_test.go (1 hunks)
  • x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto (2 hunks)
  • x/protocolpool/types/genesis.go (1 hunks)
  • x/staking/proto/cosmos/staking/v1beta1/staking.proto (2 hunks)
Files not summarized due to errors (2)
  • api/cosmos/protocolpool/v1/genesis.pulsar.go: Error: Message exceeds token limit
  • api/cosmos/staking/v1beta1/staking.pulsar.go: Error: Message exceeds token limit
Files skipped from review due to trivial changes (1)
  • x/staking/proto/cosmos/staking/v1beta1/staking.proto
Additional context used
Path-based instructions (5)
x/protocolpool/keeper/genesis_test.go (2)

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


Pattern **/*_test.go: "Assess the unit test code assessing sufficient code coverage for the changes associated in the pull request"

x/protocolpool/types/genesis.go (1)

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

x/protocolpool/keeper/genesis.go (1)

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

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

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

api/cosmos/staking/v1beta1/staking.pulsar.go (1)

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

Learnings (2)
x/protocolpool/keeper/genesis_test.go (1)
Learnt from: likhita-809
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
x/protocolpool/keeper/genesis.go (1)
Learnt from: likhita-809
PR: cosmos/cosmos-sdk#18471
File: x/protocolpool/keeper/genesis.go:12-51
Timestamp: 2023-11-22T12:32:39.368Z
Learning: - The user `likhita-809` has confirmed the changes suggested in the previous interaction.
- The file in question is `x/protocolpool/keeper/genesis.go` from a Cosmos SDK module.
- The changes involve optimizing the `InitGenesis` function by removing redundant code and ensuring proper handling of start times for budget proposals.
Additional comments not posted (16)
x/protocolpool/proto/cosmos/protocolpool/v1/genesis.proto (2)

9-9: Approved addition of import.

The import of google/protobuf/timestamp.proto is necessary for using the Timestamp type in the new Distribution message. This is a standard practice when dealing with time-related data in protobuf.


32-40: Approved new message type Distribution.

The new message type Distribution is correctly defined with appropriate fields and protobuf options. This change aligns with the PR's objective to handle distributions more explicitly.

x/protocolpool/keeper/genesis_test.go (3)

34-37: Approved addition of distribution setting in tests.

The addition of distribution setting in the TestInitGenesis function is correct and necessary to test the new functionality introduced in the genesis state handling.


40-41: Error handling check approved.

The error handling for the condition "total to be distributed is greater than the last balance" is crucial and properly implemented in the test. This ensures that the system behaves as expected under erroneous conditions.


52-52: Approved verification of exported genesis state values.

Verifying the exported genesis state values in the test is essential for ensuring that the state is correctly managed and exported. This change is well-implemented.

x/protocolpool/types/genesis.go (1)

16-17: Approved initialization of new fields in NewGenesisState.

The initialization of LastBalance to zero and Distributions to an empty slice is appropriate and aligns with the changes in the genesis structure. This ensures that the genesis state starts with a consistent and expected state.

x/protocolpool/keeper/genesis.go (2)

54-68: Approved changes in distribution setting and error handling in InitGenesis.

The modifications to set distributions and the added error handling for distribution totals exceeding the last balance are correctly implemented. This ensures that the system maintains integrity and prevents incorrect state mutations.


114-126: Approved changes in ExportGenesis function.

The changes to calculate the ToDistribute state based on account balances and to walk through distributions are correct. This ensures that the exported genesis state is accurate and reflects the current state of the system.

api/cosmos/protocolpool/v1/genesis.pulsar.go (6)

265-270: Confirm handling of LastBalance field.

The handling of the LastBalance field should be checked to ensure it correctly reflects the state of funds yet to be distributed. This is crucial for the correct operation of the module following the PR changes.

Verification successful

Handling of LastBalance field is correct.

The LastBalance field is consistently checked, set, retrieved, encoded, and decoded throughout the code. It correctly reflects the state of undistributed funds as specified in the struct definition.

  • The field is checked for non-empty values before processing.
  • It is properly set and retrieved using appropriate methods.
  • Encoding and decoding logic is correctly implemented.
  • The struct definition clearly states its purpose.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check handling of LastBalance field to ensure it correctly reflects the state of undistributed funds.
rg --type go 'LastBalance' -A 5 -B 5 api/cosmos/protocolpool/v1/genesis.pulsar.go

Length of output: 4996


271-273: Review usage of Distributions list in Range method.

The Range method's handling of the Distributions list should be scrutinized to ensure it correctly processes each distribution, particularly given the new structure of the list.

Verification successful

The Range method correctly processes the Distributions list.

The method checks if the Distributions list is non-empty and processes it appropriately, similar to other fields.

  • The Distributions list is handled correctly within the Range method.
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Review the Range method's handling of the Distributions list to ensure correct processing.
rg --type go 'func \(x \*fastReflection_GenesisState\) Range' -A 10 -B 10 api/cosmos/protocolpool/v1/genesis.pulsar.go

Length of output: 1000


Script:

#!/bin/bash
# Review the complete implementation of the Range method in the genesis.pulsar.go file.
rg --type go 'func \(x \*fastReflection_GenesisState\) Range' -A 50 -B 10 api/cosmos/protocolpool/v1/genesis.pulsar.go

Length of output: 2523


320-323: Ensure proper clearing of distributions field.

The Clear method must properly handle the distributions field to ensure that it can be reset correctly without leaving residual data that could affect application state.

Verification successful

The Clear method properly handles the distributions field.

The Clear method includes a case for "cosmos.protocolpool.v1.GenesisState.distributions" where it sets x.Distributions to nil, ensuring the field is correctly reset.

  • api/cosmos/protocolpool/v1/genesis.pulsar.go, lines 320-323
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Ensure the Clear method properly handles the distributions field.
rg --type go 'func \(x \*fastReflection_GenesisState\) Clear' -A 5 -B 5 api/cosmos/protocolpool/v1/genesis.pulsar.go

Length of output: 561


Script:

#!/bin/bash
# Ensure the Clear method properly handles the distributions field by retrieving the complete method implementation.
rg --type go 'func \(x \*fastReflection_GenesisState\) Clear' -A 20 -B 5 api/cosmos/protocolpool/v1/genesis.pulsar.go

Length of output: 1095


175-185: Check field descriptors for new distributions field.

The field descriptor setup for the new distributions field appears correct. Ensure that these descriptors are consistently used across the application to maintain data integrity and avoid serialization issues.


120-165: Ensure proper initialization and validation of new Distribution list.

The introduction of the _GenesisState_4_list to handle Distributions is aligned with the PR's objectives. However, ensure that the list is properly initialized and validated in all relevant methods to prevent runtime issues.


852-863: Validate new message descriptor for Distribution.

The setup for the Distribution message descriptor is crucial for the correct serialization and deserialization of this type. Ensure that this setup is robust and error-free.

Verification successful

The setup for the Distribution message descriptor is robust and error-free.

  • The file_cosmos_protocolpool_v1_genesis_proto_init function initializes the proto file correctly.
  • The md_Distribution message descriptor is correctly set using File_cosmos_protocolpool_v1_genesis_proto.Messages().ByName("Distribution").
  • The field descriptors fd_Distribution_amount and fd_Distribution_time are correctly assigned from md_Distribution.Fields().ByName("amount") and md_Distribution.Fields().ByName("time").
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/binash
# Validate the setup for the Distribution message descriptor.
rg --type go 'md_Distribution' -A 3 -B 3 api/cosmos/protocolpool/v1/genesis.pulsar.go

Length of output: 1082


Script:

#!/bin/bash
# Search for the definition of file_cosmos_protocolpool_v1_genesis_proto_init
rg --type go 'func file_cosmos_protocolpool_v1_genesis_proto_init' -A 10

# Verify the message descriptor File_cosmos_protocolpool_v1_genesis_proto.Messages().ByName("Distribution")
rg --type go 'File_cosmos_protocolpool_v1_genesis_proto.Messages().ByName("Distribution")' -A 3 -B 3

# Verify the field descriptors fd_Distribution_amount and fd_Distribution_time
rg --type go 'fd_Distribution_amount' -A 3 -B 3
rg --type go 'fd_Distribution_time' -A 3 -B 3

Length of output: 4423

api/cosmos/staking/v1beta1/staking.pulsar.go (2)

15704-15704: Review serialized protobuf data.

This hunk seems to represent serialized protobuf data. It's crucial to verify that these changes are consistent with the protobuf schema and that they don't introduce any serialization/deserialization issues.


15714-15714: Check for consistency in protobuf field definitions.

The protobuf field definitions should be checked for consistency and alignment with the overall schema, especially given the presence of deprecated fields.

api/cosmos/protocolpool/v1/genesis.pulsar.go Dismissed Show dismissed Hide dismissed
api/cosmos/protocolpool/v1/genesis.pulsar.go Dismissed Show dismissed Hide dismissed
totalToBeDistributed := math.ZeroInt()
for _, distribution := range data.Distributions {
totalToBeDistributed = totalToBeDistributed.Add(distribution.Amount)
if err := k.Distributions.Set(ctx, *distribution.Time, distribution.Amount); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to keep track of when the distribution is done?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because a continuous fund could expire in between, so we keep track of distributions received at t, t+1, t+n..., so when we distribute to the continuous funds, a fund expiring at t+2 will receive the distributions made until that point, and not more

Copy link
Member Author

Choose a reason for hiding this comment

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

@facundomedica facundomedica added the backport/v0.52.x PR scheduled for inclusion in the v0.52's next stable release label Jul 24, 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

Review details

Configuration used: .coderabbit.yml
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 4dc77b1 and d34617a.

Files selected for processing (2)
  • simapp/app.go (5 hunks)
  • simapp/app_config.go (2 hunks)
Additional context used
Path-based instructions (2)
simapp/app_config.go (1)

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

simapp/app.go (1)

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

Additional comments not posted (4)
simapp/app_config.go (2)

123-123: Verify the correct initialization and usage of pooltypes.ModuleName in BeginBlockers.

Ensure that the BeginBlocker for the protocolpool module is correctly initialized and used.

Verification successful

Verify the correct initialization and usage of pooltypes.ModuleName in BeginBlockers.

  • Ensure that the BeginBlocker for the protocolpool module is correctly implemented in x/protocolpool/module.go and x/protocolpool/keeper/keeper.go.
  • Verify that pooltypes.ModuleName is correctly added to the BeginBlockers list in the application configuration files (simapp/app_config.go and simapp/app.go).
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the initialization and usage of `pooltypes.ModuleName` in `BeginBlockers`.

# Test: Search for the initialization and usage of the `BeginBlocker`. Expect: Correct initialization and usage.
rg --type go 'BeginBlocker' -A 5

Length of output: 52085


84-84: Verify the correct usage of pooltypes.ProtocolPoolDistrAccount.

Ensure that the new account is correctly integrated and used in the application.

simapp/app.go (2)

440-461: LGTM! The changes improve readability and maintainability.

The modification to use a variadic function call for ModuleManager instantiation is approved.


130-130: Verify the correct usage of pooltypes.ProtocolPoolDistrAccount in maccPerms.

Ensure that the new account is correctly integrated and used in the application.

Verification successful

The new account pooltypes.ProtocolPoolDistrAccount is correctly integrated and used in the application.

The integration is consistent across test files and configuration files:

  • tests/integration/distribution/keeper/msg_server_test.go
  • tests/integration/gov/keeper/keeper_test.go
  • simapp/app_config.go
  • simapp/v2/app_config.go
Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the usage of `pooltypes.ProtocolPoolDistrAccount` in `maccPerms`.

# Test: Search for the usage of the new account. Expect: Correct integration and usage.
rg --type go 'pooltypes.ProtocolPoolDistrAccount'

Length of output: 434


Script:

#!/bin/bash
# Description: Fetch the relevant lines of code around the usage of `pooltypes.ProtocolPoolDistrAccount` in the identified files to verify correct integration and usage.

# Fetching lines around the usage in test files and configuration files
rg --type go --context 5 'pooltypes.ProtocolPoolDistrAccount' tests/integration/distribution/keeper/msg_server_test.go
rg --type go --context 5 'pooltypes.ProtocolPoolDistrAccount' tests/integration/gov/keeper/keeper_test.go
rg --type go --context 5 'pooltypes.ProtocolPoolDistrAccount' simapp/app_config.go
rg --type go --context 5 'pooltypes.ProtocolPoolDistrAccount' simapp/v2/app_config.go

Length of output: 2627

@facundomedica facundomedica added this pull request to the merge queue Jul 24, 2024
Merged via the queue into main with commit 0fda53f Jul 24, 2024
75 checks passed
@facundomedica facundomedica deleted the facu/removepooldep-distr branch July 24, 2024 15:12
mergify bot pushed a commit that referenced this pull request Jul 24, 2024
tac0turtle pushed a commit that referenced this pull request Jul 24, 2024
…ous fund bug (backport #20790) (#21060)

Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com>
@coderabbitai coderabbitai bot mentioned this pull request Dec 18, 2024
12 tasks
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 C:x/gov C:x/protocolpool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants