Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | |||||
#include <util/moneystr.h> | #include <util/moneystr.h> | ||||
#include <util/strencodings.h> | #include <util/strencodings.h> | ||||
#include <util/system.h> | #include <util/system.h> | ||||
#include <util/translation.h> | #include <util/translation.h> | ||||
#include <validationinterface.h> | #include <validationinterface.h> | ||||
#include <warnings.h> | #include <warnings.h> | ||||
#include <boost/algorithm/string/replace.hpp> | #include <boost/algorithm/string/replace.hpp> | ||||
#include <boost/thread.hpp> // boost::this_thread::interruption_point() (mingw) | |||||
#include <optional> | #include <optional> | ||||
#include <string> | #include <string> | ||||
#include <thread> | #include <thread> | ||||
#define MICRO 0.000001 | #define MICRO 0.000001 | ||||
#define MILLI 0.001 | #define MILLI 0.001 | ||||
▲ Show 20 Lines • Show All 2,925 Lines • ▼ Show 20 Lines | bool CChainState::ActivateBestChain(const Config &config, | ||||
// mutual exclusion so that only one caller may execute this function at a | // mutual exclusion so that only one caller may execute this function at a | ||||
// time | // time | ||||
LOCK(m_cs_chainstate); | LOCK(m_cs_chainstate); | ||||
CBlockIndex *pindexMostWork = nullptr; | CBlockIndex *pindexMostWork = nullptr; | ||||
CBlockIndex *pindexNewTip = nullptr; | CBlockIndex *pindexNewTip = nullptr; | ||||
int nStopAtHeight = gArgs.GetArg("-stopatheight", DEFAULT_STOPATHEIGHT); | int nStopAtHeight = gArgs.GetArg("-stopatheight", DEFAULT_STOPATHEIGHT); | ||||
do { | do { | ||||
boost::this_thread::interruption_point(); | |||||
// Block until the validation queue drains. This should largely | // Block until the validation queue drains. This should largely | ||||
// never happen in normal operation, however may happen during | // never happen in normal operation, however may happen during | ||||
// reindex, causing memory blowup if we run too far ahead. | // reindex, causing memory blowup if we run too far ahead. | ||||
// Note that if a validationinterface callback ends up calling | // Note that if a validationinterface callback ends up calling | ||||
// ActivateBestChain this may lead to a deadlock! We should | // ActivateBestChain this may lead to a deadlock! We should | ||||
// probably have a DEBUG_LOCKORDER test for this in the future. | // probably have a DEBUG_LOCKORDER test for this in the future. | ||||
LimitValidationInterfaceQueue(); | LimitValidationInterfaceQueue(); | ||||
▲ Show 20 Lines • Show All 1,876 Lines • ▼ Show 20 Lines | bool CVerifyDB::VerifyDB(const Config &config, CCoinsView *coinsview, | ||||
CBlockIndex *pindex; | CBlockIndex *pindex; | ||||
CBlockIndex *pindexFailure = nullptr; | CBlockIndex *pindexFailure = nullptr; | ||||
int nGoodTransactions = 0; | int nGoodTransactions = 0; | ||||
BlockValidationState state; | BlockValidationState state; | ||||
int reportDone = 0; | int reportDone = 0; | ||||
LogPrintfToBeContinued("[0%%]..."); | LogPrintfToBeContinued("[0%%]..."); | ||||
for (pindex = ::ChainActive().Tip(); pindex && pindex->pprev; | for (pindex = ::ChainActive().Tip(); pindex && pindex->pprev; | ||||
pindex = pindex->pprev) { | pindex = pindex->pprev) { | ||||
boost::this_thread::interruption_point(); | |||||
const int percentageDone = | const int percentageDone = | ||||
std::max(1, std::min(99, (int)(((double)(::ChainActive().Height() - | std::max(1, std::min(99, (int)(((double)(::ChainActive().Height() - | ||||
pindex->nHeight)) / | pindex->nHeight)) / | ||||
(double)nCheckDepth * | (double)nCheckDepth * | ||||
(nCheckLevel >= 4 ? 50 : 100)))); | (nCheckLevel >= 4 ? 50 : 100)))); | ||||
if (reportDone < percentageDone / 10) { | if (reportDone < percentageDone / 10) { | ||||
// report every 10% step | // report every 10% step | ||||
LogPrintfToBeContinued("[%d%%]...", percentageDone); | LogPrintfToBeContinued("[%d%%]...", percentageDone); | ||||
▲ Show 20 Lines • Show All 79 Lines • ▼ Show 20 Lines | bool CVerifyDB::VerifyDB(const Config &config, CCoinsView *coinsview, | ||||
} | } | ||||
// store block count as we move pindex at check level >= 4 | // store block count as we move pindex at check level >= 4 | ||||
int block_count = ::ChainActive().Height() - pindex->nHeight; | int block_count = ::ChainActive().Height() - pindex->nHeight; | ||||
// check level 4: try reconnecting blocks | // check level 4: try reconnecting blocks | ||||
if (nCheckLevel >= 4) { | if (nCheckLevel >= 4) { | ||||
while (pindex != ::ChainActive().Tip()) { | while (pindex != ::ChainActive().Tip()) { | ||||
boost::this_thread::interruption_point(); | |||||
const int percentageDone = std::max( | const int percentageDone = std::max( | ||||
1, std::min(99, 100 - int(double(::ChainActive().Height() - | 1, std::min(99, 100 - int(double(::ChainActive().Height() - | ||||
pindex->nHeight) / | pindex->nHeight) / | ||||
double(nCheckDepth) * 50))); | double(nCheckDepth) * 50))); | ||||
if (reportDone < percentageDone / 10) { | if (reportDone < percentageDone / 10) { | ||||
// report every 10% step | // report every 10% step | ||||
LogPrintfToBeContinued("[%d%%]...", percentageDone); | LogPrintfToBeContinued("[%d%%]...", percentageDone); | ||||
reportDone = percentageDone / 10; | reportDone = percentageDone / 10; | ||||
Show All 10 Lines | if (nCheckLevel >= 4) { | ||||
if (!::ChainstateActive().ConnectBlock( | if (!::ChainstateActive().ConnectBlock( | ||||
block, state, pindex, coins, params, | block, state, pindex, coins, params, | ||||
BlockValidationOptions(config))) { | BlockValidationOptions(config))) { | ||||
return error("VerifyDB(): *** found unconnectable block at %d, " | return error("VerifyDB(): *** found unconnectable block at %d, " | ||||
"hash=%s (%s)", | "hash=%s (%s)", | ||||
pindex->nHeight, pindex->GetBlockHash().ToString(), | pindex->nHeight, pindex->GetBlockHash().ToString(), | ||||
state.ToString()); | state.ToString()); | ||||
} | } | ||||
if (ShutdownRequested()) { | |||||
return true; | |||||
} | |||||
} | } | ||||
} | } | ||||
LogPrintf("[DONE].\n"); | LogPrintf("[DONE].\n"); | ||||
LogPrintf("No coin database inconsistencies in last %i blocks (%i " | LogPrintf("No coin database inconsistencies in last %i blocks (%i " | ||||
"transactions)\n", | "transactions)\n", | ||||
block_count, nGoodTransactions); | block_count, nGoodTransactions); | ||||
▲ Show 20 Lines • Show All 1,109 Lines • Show Last 20 Lines |