From 2e280311b87ac95a765edd3cac05096e48c73545 Mon Sep 17 00:00:00 2001 From: "Wladimir J. van der Laan" Date: Wed, 27 Aug 2014 09:20:33 +0200 Subject: [PATCH] Perform CVerifyDB on pcoinsdbview instead of pcoinsTip Bypassing the main coins cache allows more thorough checking with the same memory budget. This has no effect on performance because everything ends up in the child cache created by VerifyDB itself. It has bugged me ever since #4675, which effectively reduced the number of checked blocks to reduce peak memory usage. - Pass the coinsview to use as argument to VerifyDB - This also avoids that the first `pcoinsTip->Flush()` after VerifyDB writes a large slew of unchanged coin records back to the database. --- src/init.cpp | 2 +- src/main.cpp | 4 ++-- src/main.h | 2 +- src/rpcblockchain.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index e972413c4..7b1318654 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -969,7 +969,7 @@ bool AppInit2(boost::thread_group& threadGroup) } uiInterface.InitMessage(_("Verifying blocks...")); - if (!CVerifyDB().VerifyDB(GetArg("-checklevel", 3), + if (!CVerifyDB().VerifyDB(pcoinsdbview, GetArg("-checklevel", 3), GetArg("-checkblocks", 288))) { strLoadError = _("Corrupted block database detected"); break; diff --git a/src/main.cpp b/src/main.cpp index 6567c77e9..de5730a38 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3018,7 +3018,7 @@ CVerifyDB::~CVerifyDB() uiInterface.ShowProgress("", 100); } -bool CVerifyDB::VerifyDB(int nCheckLevel, int nCheckDepth) +bool CVerifyDB::VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth) { LOCK(cs_main); if (chainActive.Tip() == NULL || chainActive.Tip()->pprev == NULL) @@ -3031,7 +3031,7 @@ bool CVerifyDB::VerifyDB(int nCheckLevel, int nCheckDepth) nCheckDepth = chainActive.Height(); nCheckLevel = std::max(0, std::min(4, nCheckLevel)); LogPrintf("Verifying last %i blocks at level %i\n", nCheckDepth, nCheckLevel); - CCoinsViewCache coins(*pcoinsTip, true); + CCoinsViewCache coins(*coinsview, true); CBlockIndex* pindexState = chainActive.Tip(); CBlockIndex* pindexFailure = NULL; int nGoodTransactions = 0; diff --git a/src/main.h b/src/main.h index e5357cbfd..fae8990d2 100644 --- a/src/main.h +++ b/src/main.h @@ -942,7 +942,7 @@ class CVerifyDB { public: CVerifyDB(); ~CVerifyDB(); - bool VerifyDB(int nCheckLevel, int nCheckDepth); + bool VerifyDB(CCoinsView *coinsview, int nCheckLevel, int nCheckDepth); }; /** An in-memory indexed chain of blocks. */ diff --git a/src/rpcblockchain.cpp b/src/rpcblockchain.cpp index 58cab1404..b71d5a080 100644 --- a/src/rpcblockchain.cpp +++ b/src/rpcblockchain.cpp @@ -430,7 +430,7 @@ Value verifychain(const Array& params, bool fHelp) if (params.size() > 1) nCheckDepth = params[1].get_int(); - return CVerifyDB().VerifyDB(nCheckLevel, nCheckDepth); + return CVerifyDB().VerifyDB(pcoinsTip, nCheckLevel, nCheckDepth); } Value getblockchaininfo(const Array& params, bool fHelp)