diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4988,6 +4988,18 @@ bool CChainState::RewindBlockIndex(const Config &config) { LOCK(cs_main); + // Reduce validity flag and have-data flags. + // We do this after actual disconnecting, otherwise we'll end up writing the + // lack of data to disk before writing the chainstate, resulting in a + // failure to continue if interrupted. + for (const auto &entry : mapBlockIndex) { + CBlockIndex *pindexIter = entry.second; + if (pindexIter->IsValid(BlockValidity::TRANSACTIONS) && + pindexIter->HaveTxsDownloaded()) { + setBlockIndexCandidates.insert(pindexIter); + } + } + const CChainParams ¶ms = config.GetChainParams(); int nHeight = chainActive.Height() + 1; @@ -5018,18 +5030,6 @@ } } - // Reduce validity flag and have-data flags. - // We do this after actual disconnecting, otherwise we'll end up writing the - // lack of data to disk before writing the chainstate, resulting in a - // failure to continue if interrupted. - for (const auto &entry : mapBlockIndex) { - CBlockIndex *pindexIter = entry.second; - if (pindexIter->IsValid(BlockValidity::TRANSACTIONS) && - pindexIter->HaveTxsDownloaded()) { - setBlockIndexCandidates.insert(pindexIter); - } - } - if (chainActive.Tip() != nullptr) { // We can't prune block index candidates based on our tip if we have // no tip due to chainActive being empty!