mirror of
https://github.com/tendermint/tendermint.git
synced 2026-01-03 19:53:58 +00:00
genesis: add support for arbitrary initial height (#5191)
Adds a genesis parameter `initial_height` which specifies the initial block height, as well as ABCI `RequestInitChain.InitialHeight` to pass it to the ABCI application, and `State.InitialHeight` to keep track of the initial height throughout the code. Fixes #2543, based on [RFC-002](https://github.com/tendermint/spec/pull/119). Spec changes in https://github.com/tendermint/spec/pull/135.
This commit is contained in:
@@ -110,12 +110,12 @@ func SaveState(db dbm.DB, state State) {
|
||||
|
||||
func saveState(db dbm.DB, state State, key []byte) {
|
||||
nextHeight := state.LastBlockHeight + 1
|
||||
// If first block, save validators for block 1.
|
||||
// If first block, save validators for the block.
|
||||
if nextHeight == 1 {
|
||||
nextHeight = state.InitialHeight
|
||||
// This extra logic due to Tendermint validator set changes being delayed 1 block.
|
||||
// It may get overwritten due to InitChain validator updates.
|
||||
lastHeightVoteChanged := int64(1)
|
||||
saveValidatorsInfo(db, nextHeight, lastHeightVoteChanged, state.Validators)
|
||||
saveValidatorsInfo(db, nextHeight, nextHeight, state.Validators)
|
||||
}
|
||||
// Save next validators.
|
||||
saveValidatorsInfo(db, nextHeight+1, state.LastHeightValidatorsChanged, state.NextValidators)
|
||||
@@ -130,11 +130,16 @@ func saveState(db dbm.DB, state State, key []byte) {
|
||||
|
||||
// BootstrapState saves a new state, used e.g. by state sync when starting from non-zero height.
|
||||
func BootstrapState(db dbm.DB, state State) error {
|
||||
height := state.LastBlockHeight
|
||||
saveValidatorsInfo(db, height, height, state.LastValidators)
|
||||
saveValidatorsInfo(db, height+1, height+1, state.Validators)
|
||||
saveValidatorsInfo(db, height+2, height+2, state.NextValidators)
|
||||
saveConsensusParamsInfo(db, height+1, height+1, state.ConsensusParams)
|
||||
height := state.LastBlockHeight + 1
|
||||
if height == 1 {
|
||||
height = state.InitialHeight
|
||||
}
|
||||
if height > 1 && !state.LastValidators.IsNilOrEmpty() {
|
||||
saveValidatorsInfo(db, height-1, height-1, state.LastValidators)
|
||||
}
|
||||
saveValidatorsInfo(db, height, height, state.Validators)
|
||||
saveValidatorsInfo(db, height+1, height+1, state.NextValidators)
|
||||
saveConsensusParamsInfo(db, height, height, state.ConsensusParams)
|
||||
return db.SetSync(stateKey, state.Bytes())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user