Skip to content
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

Merged
merged 6 commits into from
Apr 11, 2023
Merged

Conversation

alexanderbez
Copy link
Contributor

@alexanderbez alexanderbez commented Apr 11, 2023

Description

Set initialHeight in BaseApp always. Use that in getContextForProposal 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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • followed the guidelines for building modules
  • included the necessary unit and integration tests
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • reviewed "Files changed" and left comments if necessary
  • confirmed all CI checks have passed

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...

  • confirmed the correct type prefix in the PR title
  • confirmed ! in the type prefix if API or client breaking change
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic
  • reviewed API design and naming
  • reviewed documentation is accurate
  • reviewed tests and test coverage
  • manually tested (if applicable)

Comment on lines 493 to 512
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
}

Copy link
Contributor

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)

@alexanderbez alexanderbez marked this pull request as ready for review April 11, 2023 14:54
@alexanderbez alexanderbez requested a review from a team as a code owner April 11, 2023 14:54
@alexanderbez alexanderbez added the backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release label Apr 11, 2023
@github-actions

This comment has been minimized.

@alexanderbez alexanderbez enabled auto-merge (squash) April 11, 2023 14:57
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
Copy link
Member

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?

Copy link
Member

@facundomedica facundomedica left a 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

@alexanderbez alexanderbez merged commit f95585b into main Apr 11, 2023
@alexanderbez alexanderbez deleted the bez/baseapp-init-height-refactor branch April 11, 2023 15:49
mergify bot pushed a commit that referenced this pull request Apr 11, 2023
(cherry picked from commit f95585b)

# Conflicts:
#	CHANGELOG.md
#	baseapp/abci.go
#	baseapp/abci_test.go
facundomedica added a commit that referenced this pull request Apr 11, 2023
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Facundo Medica <facundomedica@gmail.com>
roy-dydx pushed a commit to dydxprotocol/cosmos-sdk that referenced this pull request Jul 11, 2023
Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
Co-authored-by: Facundo Medica <facundomedica@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport/v0.47.x PR scheduled for inclusion in the v0.47's next stable release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants