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/distribution): panic on negative community pool #23507

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

DeVikingMark
Copy link

@DeVikingMark DeVikingMark commented Jan 25, 2025

Previously, the ValidateGenesis function would return an error when encountering
a negative CommunityPool value. This change makes it panic instead, as specified
in the TODO comment. This is a breaking change that will be introduced in v0.53.

This change helps maintain the invariant that the community pool should never
be negative, making it easier to catch and debug issues earlier in the
development process.

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling for community pool validation during genesis initialization
    • Implemented stricter validation mechanism to prevent potential negative value scenarios

@DeVikingMark DeVikingMark requested review from alpe, JulianToledano and a team as code owners January 25, 2025 01:35
@github-actions github-actions bot added the C:x/distribution distribution module related label Jan 25, 2025
Copy link
Contributor

coderabbitai bot commented Jan 25, 2025

📝 Walkthrough

Walkthrough

The changes focus on the ValidateGenesis method in the FeePool struct within the distribution module. The modification alters the error handling approach for the CommunityPool, replacing a previous error return with a panic mechanism. This change means that when negative values are detected in the community pool during genesis validation, the function will now immediately terminate with a panic instead of returning a standard error.

Changes

File Change Summary
x/distribution/types/fee_pool.go Modified ValidateGenesis() method to use panic instead of returning an error when negative values are found in the CommunityPool

Sequence Diagram

sequenceDiagram
    participant Genesis as Genesis Initialization
    participant FeePool as FeePool Validator
    participant CommunityPool as Community Pool

    Genesis->>FeePool: Validate Genesis
    FeePool->>CommunityPool: Check Pool Values
    alt Negative Values Detected
        FeePool->>FeePool: Panic Immediately
    else Valid Pool
        FeePool-->>Genesis: Validation Successful
    end
Loading

The sequence diagram illustrates the new validation flow, highlighting the immediate panic mechanism when negative values are encountered during the genesis validation process.

✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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.

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.

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

🧹 Nitpick comments (2)
x/distribution/types/fee_pool.go (2)

23-24: Document the panic behavior.

Consider adding a doc comment to ValidateGenesis to explicitly document that it panics on negative CommunityPool values.

 // ValidateGenesis validates the fee pool for a genesis state
+// Panics if CommunityPool contains negative values.
 func (f FeePool) ValidateGenesis() error {

23-24: Consider consistent error handling approach.

The method handles similar conditions differently:

  • DecimalPool: Returns error for negative values
  • CommunityPool: Panics for negative values

This asymmetric approach might be confusing. Consider either:

  1. Making both checks use panic for consistency, or
  2. Document the rationale for the different approaches
📜 Review details

Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e9b16a4 and b79de8e.

📒 Files selected for processing (1)
  • x/distribution/types/fee_pool.go (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
x/distribution/types/fee_pool.go (1)

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

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Summary
🔇 Additional comments (1)
x/distribution/types/fee_pool.go (1)

23-24: Approved: Breaking change from error to panic.

The change aligns with the PR objectives to enforce the invariant that CommunityPool cannot be negative. This is a breaking change for v0.53.

Let's verify the impact of this breaking change:

✅ Verification successful

Breaking change confirmed: Panic on negative community pool during genesis

The change from error to panic affects chain initialization, as ValidateGenesis is called during genesis state validation. Node operators should ensure their genesis state has no negative community pool values before upgrading to v0.53.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for direct callers of ValidateGenesis that might need updates
ast-grep --pattern 'ValidateGenesis()' 

Length of output: 40


Script:

#!/bin/bash
# Find the complete type definition and method signature
ast-grep --pattern 'type FeePool struct'

# Search for any imports of this package
rg "\".*distribution/types\"" -A 1 -B 1

# Search for ValidateGenesis calls with context
rg "ValidateGenesis" -A 2 -B 2

Length of output: 53247

@@ -20,8 +20,8 @@ func (f FeePool) ValidateGenesis() error {
return fmt.Errorf("negative DecimalPool in distribution fee pool, is %v", f.DecimalPool)
}

if f.CommunityPool.IsAnyNegative() { // TODO(@julienrbrt) in v0.53, panic if the community pool is set
return fmt.Errorf("negative CommunityPool in distribution fee pool, is %v", f.CommunityPool)
if f.CommunityPool.IsAnyNegative() {
Copy link
Member

@julienrbrt julienrbrt Jan 25, 2025

Choose a reason for hiding this comment

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

The comment means to panic if it is set at all, as it should be specified in protocolpool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C:x/distribution distribution module related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants