diff options
author | James O'Beirne <james.obeirne@pm.me> | 2021-04-13 10:05:28 -0400 |
---|---|---|
committer | James O'Beirne <james.obeirne@pm.me> | 2021-04-23 15:06:48 -0400 |
commit | 9b604c0207b526c008617cdca210f35db5e344db (patch) | |
tree | c144b73559ae20405ce9cbccb95fef580284d1e8 /src/validation.cpp | |
parent | 7901647d722bcc5b0554ad73b14481cbe73608e4 (diff) | |
download | bitcoin-9b604c0207b526c008617cdca210f35db5e344db.tar.xz |
validation: prepare VerifyDB for assumeutxo
Removes assumptions of use only on the active chainstate.
Diffstat (limited to 'src/validation.cpp')
-rw-r--r-- | src/validation.cpp | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/validation.cpp b/src/validation.cpp index 6fe096465a..332a38119a 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4104,7 +4104,7 @@ CVerifyDB::~CVerifyDB() bool CVerifyDB::VerifyDB( CChainState& chainstate, const CChainParams& chainparams, - CCoinsView* coinsview, + CCoinsView& coinsview, int nCheckLevel, int nCheckDepth) { AssertLockHeld(cs_main); @@ -4118,13 +4118,16 @@ bool CVerifyDB::VerifyDB( nCheckDepth = chainstate.m_chain.Height(); nCheckLevel = std::max(0, std::min(4, nCheckLevel)); LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel); - CCoinsViewCache coins(coinsview); + CCoinsViewCache coins(&coinsview); CBlockIndex* pindex; CBlockIndex* pindexFailure = nullptr; int nGoodTransactions = 0; BlockValidationState state; int reportDone = 0; LogPrintf("[0%%]..."); /* Continued */ + + bool is_snapshot_cs = !chainstate.m_from_snapshot_blockhash.IsNull(); + for (pindex = chainstate.m_chain.Tip(); pindex && pindex->pprev; pindex = pindex->pprev) { const int percentageDone = std::max(1, std::min(99, (int)(((double)(chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100)))); if (reportDone < percentageDone/10) { @@ -4135,8 +4138,9 @@ bool CVerifyDB::VerifyDB( uiInterface.ShowProgress(_("Verifying blocks...").translated, percentageDone, false); if (pindex->nHeight <= chainstate.m_chain.Height()-nCheckDepth) break; - if (fPruneMode && !(pindex->nStatus & BLOCK_HAVE_DATA)) { - // If pruning, only go back as far as we have data. + if ((fPruneMode || is_snapshot_cs) && !(pindex->nStatus & BLOCK_HAVE_DATA)) { + // If pruning or running under an assumeutxo snapshot, only go + // back as far as we have data. LogPrintf("VerifyDB(): block verification stopping at height %d (pruning, no data)\n", pindex->nHeight); break; } @@ -4158,9 +4162,9 @@ bool CVerifyDB::VerifyDB( } } // check level 3: check for inconsistencies during memory-only disconnect of tip blocks - int64_t curr_coins_usage = coins.DynamicMemoryUsage() + chainstate.CoinsTip().DynamicMemoryUsage(); + size_t curr_coins_usage = coins.DynamicMemoryUsage() + chainstate.CoinsTip().DynamicMemoryUsage(); - if (nCheckLevel >= 3 && static_cast<unsigned long>(curr_coins_usage) <= chainstate.m_coinstip_cache_size_bytes) { + if (nCheckLevel >= 3 && curr_coins_usage <= chainstate.m_coinstip_cache_size_bytes) { assert(coins.GetBestBlock() == pindex->GetBlockHash()); DisconnectResult res = chainstate.DisconnectBlock(block, pindex, coins); if (res == DISCONNECT_FAILED) { |