catch scenario when recovering directly after an upgrade

This commit is contained in:
Callum Waters
2022-11-22 15:26:02 +01:00
parent 578322a6fb
commit 15065f898c
2 changed files with 26 additions and 0 deletions
+7
View File
@@ -423,6 +423,13 @@ func (h *Handshaker) ReplayBlocks(
if err != nil {
return nil, err
}
// NOTE: There is a rare edge case where a node has upgraded from
// v0.37 with endblock to v0.38 with finalize block and thus
// does not have the app hash saved from the previous height
// here we take the appHash provided from the Info handshake
if len(finalizeBlockResponse.AgreedAppData) == 0 {
finalizeBlockResponse.AgreedAppData = appHash
}
mockApp := newMockProxyApp(finalizeBlockResponse)
h.logger.Info("Replay last block using mock app")
state, err = h.replayBlock(state, storeBlockHeight, mockApp)
+19
View File
@@ -448,6 +448,25 @@ func (store dbStore) LoadLastFinalizeBlockResponse(height int64) (*abci.Response
return nil, errors.New("expected height %d but last stored abci responses was at height %d")
}
// It is possible if this is called directly after an upgrade that
// ResponseFinalizeBlock is nil. In which case we use the legacy
// ABCI responses
if info.ResponseFinalizeBlock == nil {
// sanity check
if info.LegacyAbciResponses == nil {
panic("state store contains last abci response but it is empty")
}
legacyResp := info.LegacyAbciResponses
return &abci.ResponseFinalizeBlock{
TxResults: legacyResp.DeliverTxs,
ValidatorUpdates: legacyResp.EndBlock.ValidatorUpdates,
ConsensusParamUpdates: legacyResp.EndBlock.ConsensusParamUpdates,
Events: append(legacyResp.BeginBlock.Events, legacyResp.EndBlock.Events...),
// NOTE: AgreedAppData is missing in the response but will
// be caught and filled in consensus/replay.go
}, nil
}
return info.ResponseFinalizeBlock, nil
}