mirror of
https://github.com/tendermint/tendermint.git
synced 2026-09-29 03:05:49 +00:00
fix app hash in state rollback (#7837)
When testing rollback feature in the Cosmos SDK, we found that the app hash in Tendermint after rollback was the value after the latest block, rather than before it. Co-authored-by: Callum Waters <cmwaters19@gmail.com>
This commit is contained in:
@@ -41,6 +41,11 @@ func Rollback(bs BlockStore, ss Store) (int64, []byte, error) {
|
||||
if rollbackBlock == nil {
|
||||
return -1, nil, fmt.Errorf("block at height %d not found", rollbackHeight)
|
||||
}
|
||||
// we also need to retrieve the latest block because the app hash and last results hash is only agreed upon in the following block
|
||||
latestBlock := bs.LoadBlockMeta(invalidState.LastBlockHeight)
|
||||
if latestBlock == nil {
|
||||
return -1, nil, fmt.Errorf("block at height %d not found", invalidState.LastBlockHeight)
|
||||
}
|
||||
|
||||
previousLastValidatorSet, err := ss.LoadValidators(rollbackHeight)
|
||||
if err != nil {
|
||||
@@ -89,8 +94,8 @@ func Rollback(bs BlockStore, ss Store) (int64, []byte, error) {
|
||||
ConsensusParams: previousParams,
|
||||
LastHeightConsensusParamsChanged: paramsChangeHeight,
|
||||
|
||||
LastResultsHash: rollbackBlock.Header.LastResultsHash,
|
||||
AppHash: rollbackBlock.Header.AppHash,
|
||||
LastResultsHash: latestBlock.Header.LastResultsHash,
|
||||
AppHash: latestBlock.Header.AppHash,
|
||||
}
|
||||
|
||||
// persist the new state. This overrides the invalid one. NOTE: this will also
|
||||
|
||||
Reference in New Issue
Block a user