Skip to content

Commit

Permalink
Fix codecov: fix app hash in state rollback (backport #7837) (#7881)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnasu committed Feb 28, 2022
1 parent 17bca34 commit 218e5cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
4 changes: 2 additions & 2 deletions state/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ func Rollback(bs BlockStore, ss Store) (int64, []byte, error) {
rollbackHeight := invalidState.LastBlockHeight - 1
rollbackBlock := bs.LoadBlockMeta(rollbackHeight)
if rollbackBlock == nil {
return -1, nil, fmt.Errorf("block at height %d not found", rollbackHeight)
return -1, nil, fmt.Errorf("block at RollbackHeight %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)
return -1, nil, fmt.Errorf("block at LastBlockHeight %d not found", invalidState.LastBlockHeight)
}

_, prevVoterSet, _, _, err := ss.LoadVoters(rollbackHeight, nil)
Expand Down
12 changes: 9 additions & 3 deletions state/rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,18 @@ func TestRollbackNoBlocks(t *testing.T) {
stateStore := setupStateStore(t, height)
blockStore := &mocks.BlockStore{}
blockStore.On("Height").Return(height)
blockStore.On("LoadBlockMeta", height).Return(nil)
blockStore.On("LoadBlockMeta", height-1).Return(nil)
blockStore.On("LoadBlockMeta", height-1).Once().Return(nil)

_, _, err := state.Rollback(blockStore, stateStore)
require.Error(t, err)
require.Contains(t, err.Error(), "block at height 99 not found")
require.Contains(t, err.Error(), "block at RollbackHeight 99 not found")

blockStore.On("LoadBlockMeta", height-1).Once().Return(&types.BlockMeta{})
blockStore.On("LoadBlockMeta", height).Return(nil)

_, _, err = state.Rollback(blockStore, stateStore)
require.Error(t, err)
require.Contains(t, err.Error(), "block at LastBlockHeight 100 not found")
}

func TestRollbackDifferentStateHeight(t *testing.T) {
Expand Down

0 comments on commit 218e5cd

Please sign in to comment.