-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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: remove setting of finalizeBlockState in FinalizeBlock + fix initialHeight + add ProcessProposal in tests/sims #16794
Conversation
There's a test failing because finalizeBlockState is nil. So that means there is a test that calls FinalizeBlock without initializing finalizeBlockState first?
So we are calling FinalizeBlock without executing either of those 🤔 |
|
Seems that |
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.
utACK. Changes make sense to me. The setting of finalizeBlockState
is set on ProcessProposal
and thus should not be in FinalizeBlock
. Good work
if app.initialHeight == 0 { // If initial height is 0, set it to 1 | ||
app.initialHeight = 1 | ||
} |
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.
I would put this in the BaseApp
constructor, not here.
Also, can you describe what issue this was causing?
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.
I don't think we can do it in the constructor, we have to get it in InitChain which contains InitialHeight (the line above app.initialHeight = req.InitialHeight
).
The issue here is the following:
- InitChain is called with InitialHeight of 0 (according to CometBFT it 0 == 1 in this context) and
app.initialHeight
is set to 0. - After that
ProcessProposal
gets called with Height 1 (calling it with height 0 is invalid; we have that check in place) getContextForProposal
is called with height 1. Then height != app.initialHeight (1 != 0), so it doesn't return the right context (the one that contains all the state written during InitChain).
Writing this makes me doubt if PrepareProposal/ProcessProposal can actually get called with height 0, AFAIK no, but I'm checking Comet's code. Do you know this @alexanderbez ?
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.
PrepareProposal/ProcessProposal can actually get called with height 0
This should never be the case I'd imagine, but either way, yeah, let's keep it here.
merging this to continue working on it in a separate PR |
Description
This is problem because if for some reason FinalizeBlock gets called without first calling ProcessProposal/InitChain a faulty block might be created (using old state probably) or some other undefined behavior.
So with this change if FinalizeBlock gets called in an unexpected way, it should panic given that there is no initialized state to read/write on.
Fixes some of the issues outlined here: #16796
A follow up PR is needed to fix integration tests (working on it now)
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
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 change