diff --git a/consensus/replay.go b/consensus/replay.go index c87f996b7..ea9b2ff46 100644 --- a/consensus/replay.go +++ b/consensus/replay.go @@ -391,7 +391,6 @@ func (h *Handshaker) ReplayBlocks( // Either the app is asking for replay, or we're all synced up. if appBlockHeight < storeBlockHeight { // the app is behind, so replay blocks, but no need to go through WAL (state is already synced to store) - fmt.Println("here3") return h.replayBlocks(state, proxyApp, appBlockHeight, storeBlockHeight, false) } else if appBlockHeight == storeBlockHeight { @@ -405,7 +404,6 @@ func (h *Handshaker) ReplayBlocks( // so we'll need to replay a block using the WAL. switch { case appBlockHeight < stateBlockHeight: - fmt.Println("here2") // the app is further behind than it should be, so replay blocks // but leave the last block to go through the WAL return h.replayBlocks(state, proxyApp, appBlockHeight, storeBlockHeight, true) @@ -416,12 +414,10 @@ func (h *Handshaker) ReplayBlocks( // NOTE: We could instead use the cs.WAL on cs.Start, // but we'd have to allow the WAL to replay a block that wrote it's #ENDHEIGHT h.logger.Info("Replay last block using real app") - fmt.Println("here4") state, err = h.replayBlock(state, storeBlockHeight, proxyApp.Consensus()) return state.AppHash, err case appBlockHeight == storeBlockHeight: - fmt.Println("here1") // We ran Commit, but didn't save the state, so replayBlock with mock app. finalizeBlockResponse, err := h.stateStore.LoadLastFinalizeBlockResponse(storeBlockHeight) if err != nil { diff --git a/consensus/replay_test.go b/consensus/replay_test.go index a47afadad..f82dea501 100644 --- a/consensus/replay_test.go +++ b/consensus/replay_test.go @@ -306,9 +306,9 @@ const numBlocks = 6 // Test handshake/replay // 0 - all synced up -// 1 - saved block but app and state are behind -// 2 - save block and committed but state is behind -// 3 - save block and committed with truncated block store and state behind +// 1 - saved block but app and state are behind by one height +// 2 - save block and committed (i.e. app got `Commit`) but state is behind +// 3 - same as 2 but with a truncated block store var modes = []uint{0, 1, 2, 3} // This is actually not a test, it's for storing validator change tx data for testHandshakeReplay @@ -736,8 +736,6 @@ func testHandshakeReplay(t *testing.T, config *cfg.Config, nBlocks int, mode uin require.Equal(t, state.LastBlockHeight, res.LastBlockHeight) require.Equal(t, int64(numBlocks), res.LastBlockHeight) - fmt.Printf("mode: %d, appHash: %X, data: %s\n", mode, latestAppHash, res.Data) - // the app hash should be synced up if !bytes.Equal(latestAppHash, res.LastBlockAppHash) { t.Fatalf( @@ -800,9 +798,12 @@ func buildAppStateFromChain(t *testing.T, proxyApp proxy.AppConns, stateStore sm state = applyBlock(t, stateStore, mempool, evpool, state, block, proxyApp, bs) } + // mode 1 only the block at the last height is saved + // mode 2 and 3, the block is saved, commit is called, but the state is not saved if mode == 2 || mode == 3 { // update the kvstore height and apphash // as if we ran commit but not + // here we expect a dummy state store to be used state = applyBlock(t, stateStore, mempool, evpool, state, chain[nBlocks-1], proxyApp, bs) } default: @@ -858,10 +859,15 @@ func buildTMStateFromChain( } dummyStateStore := &smmocks.Store{} - vals, _ := stateStore.LoadValidators(int64(len(chain) - 1)) - dummyStateStore.On("LoadValidators", int64(5)).Return(vals, nil) + lastHeight := int64(len(chain)) + penultimateHeight := int64(len(chain) - 1) + vals, _ := stateStore.LoadValidators(penultimateHeight) + dummyStateStore.On("LoadValidators", penultimateHeight).Return(vals, nil) dummyStateStore.On("Save", mock.Anything).Return(nil) - dummyStateStore.On("SaveFinalizeBlockResponse", mock.Anything, mock.Anything).Return(nil) + dummyStateStore.On("SaveFinalizeBlockResponse", lastHeight, mock.MatchedBy(func(response *abci.ResponseFinalizeBlock) bool { + stateStore.SaveFinalizeBlockResponse(lastHeight, response) + return true + })).Return(nil) // apply the final block to a state copy so we can // get the right next appHash but keep the state back diff --git a/state/store.go b/state/store.go index cdfce15ea..f2da03ec3 100644 --- a/state/store.go +++ b/state/store.go @@ -445,7 +445,7 @@ func (store dbStore) LoadLastFinalizeBlockResponse(height int64) (*abci.Response // Here we validate the result by comparing its height to the expected height. if height != info.GetHeight() { - return nil, errors.New("expected height %d but last stored abci responses was at height %d") + return nil, fmt.Errorf("expected height %d but last stored abci responses was at height %d", height, info.GetHeight()) } // It is possible if this is called directly after an upgrade that