-
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: use initialHeight correctly #15789
Conversation
return fmt.Errorf("invalid height: %d", req.Header.Height) | ||
} | ||
|
||
// expectedHeight holds the expected height to validate. | ||
lastBlockHeight := app.LastBlockHeight() | ||
|
||
// expectedHeight holds the expected height to validate | ||
var expectedHeight int64 | ||
if app.LastBlockHeight() == 0 && app.initialHeight > 1 { | ||
// In this case, we're validating the first block of the chain (no | ||
// previous commit). The height we're expecting is the initial height. | ||
if lastBlockHeight == 0 && app.initialHeight > 1 { | ||
// In this case, we're validating the first block of the chain, i.e no | ||
// previous commit. The height we're expecting is the initial height. | ||
expectedHeight = app.initialHeight | ||
} else { | ||
// This case can mean two things: | ||
// - either there was already a previous commit in the store, in which | ||
// case we increment the version from there, | ||
// - or there was no previous commit, and initial version was not set, | ||
// in which case we start at version 1. | ||
expectedHeight = app.LastBlockHeight() + 1 | ||
// | ||
// - Either there was already a previous commit in the store, in which | ||
// case we increment the version from there. | ||
// - Or there was no previous commit, in which case we start at version 1. | ||
expectedHeight = lastBlockHeight + 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.
Change potentially affects state.
Call sequence:
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).validateHeight (baseapp/baseapp.go:491)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).BeginBlock (baseapp/baseapp.go:162)
This comment has been minimized.
This comment has been minimized.
initHeader = cmtproto.Header{ChainID: req.ChainId, Height: req.InitialHeight, Time: req.Time} | ||
err := app.cms.SetInitialVersion(req.InitialHeight) | ||
if err != nil { | ||
initHeader.Height = req.InitialHeight |
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.
any clues why we are doing this here and not above?
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. I don't understand some things, but they were already there
…cosmos-sdk into bez/baseapp-init-height-refactor
(cherry picked from commit f95585b) # Conflicts: # CHANGELOG.md # baseapp/abci.go # baseapp/abci_test.go
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> Co-authored-by: Facundo Medica <facundomedica@gmail.com>
Description
Set
initialHeight
inBaseApp
always. Use that ingetContextForProposal
instead of assuming first block == 1.This PR is a fix only for chains that are NEW and starting with
InitialHeight > 1
...which is probably no one but it's good to fix anyway.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