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:
yihuang
2022-02-19 07:40:55 -08:00
committed by GitHub
co-authored by Callum Waters
parent abfcd08903
commit 8a238fdcb4
3 changed files with 21 additions and 4 deletions
+7 -2
View File
@@ -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