fix: use initialHeight correctly (#15789)
This commit is contained in:
parent
fb257ae9d9
commit
f95585b40d
@ -173,6 +173,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
* (baseapp) [#15789](https://github.com/cosmos/cosmos-sdk/pull/15789) Ensure `PrepareProposal` and `ProcessProposal` respect `InitialHeight` set by CometBFT when set to a value greater than 1.
|
||||
* (types) [#15691](https://github.com/cosmos/cosmos-sdk/pull/15691) Make Coin.Validate() check that .Amount is not nil
|
||||
* (types) [#15433](https://github.com/cosmos/cosmos-sdk/pull/15433) Allow disabling of account address caches (for printing bech32 account addresses).
|
||||
* (x/auth) [#15059](https://github.com/cosmos/cosmos-sdk/pull/15059) `ante.CountSubKeys` returns 0 when passing a nil `Pubkey`.
|
||||
|
||||
@ -48,13 +48,14 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
|
||||
|
||||
app.logger.Info("InitChain", "initialHeight", req.InitialHeight, "chainID", req.ChainId)
|
||||
|
||||
// If req.InitialHeight is > 1, then we set the initial version in the
|
||||
// stores.
|
||||
// Set the initial height, which will be used to determine if we are proposing
|
||||
// or processing the first block or not.
|
||||
app.initialHeight = req.InitialHeight
|
||||
|
||||
// if req.InitialHeight is > 1, then we set the initial version on all stores
|
||||
if req.InitialHeight > 1 {
|
||||
app.initialHeight = req.InitialHeight
|
||||
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
|
||||
if err := app.cms.SetInitialVersion(req.InitialHeight); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
@ -1017,11 +1018,13 @@ func SplitABCIQueryPath(requestPath string) (path []string) {
|
||||
// ProcessProposal. We use deliverState on the first block to be able to access
|
||||
// any state changes made in InitChain.
|
||||
func (app *BaseApp) getContextForProposal(ctx sdk.Context, height int64) sdk.Context {
|
||||
if height == 1 {
|
||||
if height == app.initialHeight {
|
||||
ctx, _ = app.deliverState.ctx.CacheContext()
|
||||
|
||||
// clear all context data set during InitChain to avoid inconsistent behavior
|
||||
ctx = ctx.WithBlockHeader(cmtproto.Header{})
|
||||
return ctx
|
||||
}
|
||||
|
||||
return ctx
|
||||
}
|
||||
|
||||
@ -1407,6 +1407,7 @@ func TestABCI_Proposal_Read_State_PrepareProposal(t *testing.T) {
|
||||
suite := NewBaseAppSuite(t, setInitChainerOpt, prepareOpt)
|
||||
|
||||
suite.baseApp.InitChain(abci.RequestInitChain{
|
||||
InitialHeight: 1,
|
||||
ConsensusParams: &cmtproto.ConsensusParams{},
|
||||
})
|
||||
|
||||
|
||||
@ -493,19 +493,21 @@ func (app *BaseApp) validateHeight(req abci.RequestBeginBlock) error {
|
||||
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
|
||||
}
|
||||
|
||||
if req.Header.Height != expectedHeight {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user