-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughThe changes focus on the Changes
Sequence DiagramsequenceDiagram
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
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
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this 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:
- Making both checks use panic for consistency, or
- Document the rationale for the different approaches
📜 Review details
Configuration used: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 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 2Length 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() { |
There was a problem hiding this comment.
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.
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