diff --git a/state/rollback.go b/state/rollback.go index f46fd7eed..a80c34fc8 100644 --- a/state/rollback.go +++ b/state/rollback.go @@ -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) diff --git a/state/rollback_test.go b/state/rollback_test.go index 32528bd34..7daf69253 100644 --- a/state/rollback_test.go +++ b/state/rollback_test.go @@ -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) {