-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
fix(baseapp): allow empty consensus params #18531
Conversation
Warning Rate Limit Exceeded@facundomedica has exceeded the limit for the number of files or commits that can be reviewed per hour. Please wait 13 minutes and 26 seconds before requesting another review. How to resolve this issue?After the wait time has elapsed, a review can be triggered using the @coderabbitai review command. Alternatively, push new commits to this PR. We recommend that you space out your commits to avoid hitting the rate limit. How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. WalkthroughThe changes involve updates to the Changes
TipsChat with CodeRabbit Bot (
|
baseapp/baseapp.go
Outdated
|
||
cp, err := app.paramStore.Get(ctx) | ||
if err != nil { | ||
panic(fmt.Errorf("consensus key is nil: %w", err)) | ||
// This could happen while migrating from v0.45/v0.46 to v0.50, we should | ||
// allow it to happen so during preblock the upgrade plan can be executed | ||
// and the consensus params set for the first time in the new format. | ||
app.logger.Error("couldn't get consensus params", "err", err) | ||
return cmtproto.ConsensusParams{} |
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.
Change potentially affects state.
Call sequence:
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).GetConsensusParams (baseapp/baseapp.go:518)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).PrepareProposal (baseapp/baseapp.go:402)
is this still needed? |
This comment has been minimized.
This comment has been minimized.
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- baseapp/baseapp.go (1 hunks)
- baseapp/baseapp_test.go (1 hunks)
Additional comments: 2
baseapp/baseapp.go (1)
- 522-532: The changes to the
GetConsensusParams
function to handle a nil consensus key by logging an error and returning an emptycmtproto.ConsensusParams
struct are appropriate for the upgrade scenario described. This prevents a panic during the upgrade process, allowing the consensus parameters to be set in the new format during thePreBlock
execution of the first block post-upgrade. Ensure that all other parts of the system that rely on consensus parameters can handle an empty struct being returned.baseapp/baseapp_test.go (1)
- 729-731: The test
TestGetEmptyConsensusParams
correctly checks for the expected behavior when no consensus parameters are found.
baseapp/baseapp_test.go
Outdated
@@ -720,6 +720,17 @@ func TestGetMaximumBlockGas(t *testing.T) { | |||
require.Panics(t, func() { suite.baseApp.GetMaximumBlockGas(ctx) }) | |||
} | |||
|
|||
func TestGetEmptyConsensusParmas(t *testing.T) { |
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.
There is a typo in the test function name TestGetEmptyConsensusParmas
; it should be TestGetEmptyConsensusParams
.
- func TestGetEmptyConsensusParmas(t *testing.T) {
+ func TestGetEmptyConsensusParams(t *testing.T) {
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.
func TestGetEmptyConsensusParmas(t *testing.T) { | |
func TestGetEmptyConsensusParams(t *testing.T) { |
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.
lgtm! We should add a changelog entry.
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.
makes sense thank you.
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
|
||
cp, err := app.paramStore.Get(ctx) | ||
if err != nil { | ||
panic(fmt.Errorf("consensus key is nil: %w", err)) | ||
// This could happen while migrating from v0.45/v0.46 to v0.50, we should | ||
// allow it to happen so during preblock the upgrade plan can be executed | ||
// and the consensus params set for the first time in the new format. | ||
app.logger.Error("failed to get consensus params", "err", err) | ||
return cmtproto.ConsensusParams{} |
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.
Change potentially affects state.
Call sequence:
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).GetConsensusParams (baseapp/baseapp.go:518)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).PrepareProposal (baseapp/baseapp.go:402)
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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (1)
- baseapp/baseapp.go (1 hunks)
Additional comments: 1
baseapp/baseapp.go (1)
- 522-532: The change to log an error and return an empty
cmtproto.ConsensusParams
struct instead of panicking is a significant change in behavior. Ensure that all parts of the system that rely onGetConsensusParams
can handle an emptycmtproto.ConsensusParams
struct without any adverse effects, especially during the upgrade process.
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.
Review Status
Actionable comments generated: 1
Configuration used: CodeRabbit UI
Files selected for processing (2)
- CHANGELOG.md (1 hunks)
- baseapp/baseapp_test.go (1 hunks)
Additional comments: 2
CHANGELOG.md (1)
- 70-70: The changelog entries accurately reflect the changes made in the associated pull requests and provide clear links to the issues addressed.
baseapp/baseapp_test.go (1)
- 720-721: The test
TestGetMaximumBlockGas
correctly asserts that the function panics when a negativeMaxGas
is stored, which aligns with the expected behavior.
func TestGetEmptyConsensusParams(t *testing.T) { | ||
suite := NewBaseAppSuite(t) | ||
_, err := suite.baseApp.InitChain(&abci.RequestInitChain{}) | ||
require.NoError(t, err) | ||
ctx := suite.baseApp.NewContext(true) | ||
|
||
cp := suite.baseApp.GetConsensusParams(ctx) | ||
require.Equal(t, cmtproto.ConsensusParams{}, cp) | ||
require.Equal(t, uint64(0), suite.baseApp.GetMaximumBlockGas(ctx)) | ||
} |
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 test TestGetEmptyConsensusParams
should also verify that an error is logged when no consensus parameters are found, as described in the PR summary. Consider using a mock logger to capture and assert the log output.
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> (cherry picked from commit fa5280f)
Description
This PR attempts to fix an issue when skipping v0.47 while upgrading to v0.50. FinalizeBlock panics because it tries to read consensus params in the new format before the PreBlock which is where the params migration happens.
The solution proposed here involves not erroring if no consensus params were found and returning an empty struct.
Negative: Preblock runs for a single block without consensus params.
It could be an issue for other modules with their own preblock as even if the consensus params are migrated, they won't get the new params until the next block.
I don't think this would be an issue for VoteExtensions, as the chain would presumably enable vote extensions once the v0.50 upgrade has been done.
Positive: FinalizeBlock doesn't panic and consensus params will be present during the first block at any time with the exception of PreBlock.
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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
make lint
andmake test
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...
!
in the type prefix if API or client breaking changeSummary by CodeRabbit
Bug Fixes
FinalizeBlock
calls are properly passed to ABCIListeners.Tests
Documentation