Changeset View
Changeset View
Standalone View
Standalone View
src/validation.cpp
Show First 20 Lines • Show All 4,432 Lines • ▼ Show 20 Lines | LogPrintf( | ||||
chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), | chainActive.Tip()->GetBlockHash().ToString(), chainActive.Height(), | ||||
FormatISO8601DateTime(chainActive.Tip()->GetBlockTime()), | FormatISO8601DateTime(chainActive.Tip()->GetBlockTime()), | ||||
GuessVerificationProgress(config.GetChainParams().TxData(), | GuessVerificationProgress(config.GetChainParams().TxData(), | ||||
chainActive.Tip())); | chainActive.Tip())); | ||||
return true; | return true; | ||||
} | } | ||||
CVerifyDB::CVerifyDB() { | CVerifyDB::CVerifyDB() { | ||||
uiInterface.ShowProgress(_("Verifying blocks..."), 0); | uiInterface.ShowProgress(_("Verifying blocks..."), 0, false); | ||||
} | } | ||||
CVerifyDB::~CVerifyDB() { | CVerifyDB::~CVerifyDB() { | ||||
uiInterface.ShowProgress("", 100); | uiInterface.ShowProgress("", 100, false); | ||||
} | } | ||||
bool CVerifyDB::VerifyDB(const Config &config, CCoinsView *coinsview, | bool CVerifyDB::VerifyDB(const Config &config, CCoinsView *coinsview, | ||||
int nCheckLevel, int nCheckDepth) { | int nCheckLevel, int nCheckDepth) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
if (chainActive.Tip() == nullptr || chainActive.Tip()->pprev == nullptr) { | if (chainActive.Tip() == nullptr || chainActive.Tip()->pprev == nullptr) { | ||||
return true; | return true; | ||||
} | } | ||||
Show All 29 Lines | for (CBlockIndex *pindex = chainActive.Tip(); pindex && pindex->pprev; | ||||
(double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100)))); | (double)nCheckDepth * (nCheckLevel >= 4 ? 50 : 100)))); | ||||
if (reportDone < percentageDone / 10) { | if (reportDone < percentageDone / 10) { | ||||
// report every 10% step | // report every 10% step | ||||
LogPrintf("[%d%%]...", percentageDone); | LogPrintf("[%d%%]...", percentageDone); | ||||
reportDone = percentageDone / 10; | reportDone = percentageDone / 10; | ||||
} | } | ||||
uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone); | uiInterface.ShowProgress(_("Verifying blocks..."), percentageDone, | ||||
false); | |||||
if (pindex->nHeight < chainActive.Height() - nCheckDepth) { | if (pindex->nHeight < chainActive.Height() - nCheckDepth) { | ||||
break; | break; | ||||
} | } | ||||
if (fPruneMode && !pindex->nStatus.hasData()) { | if (fPruneMode && !pindex->nStatus.hasData()) { | ||||
// If pruning, only go back as far as we have data. | // If pruning, only go back as far as we have data. | ||||
LogPrintf("VerifyDB(): block verification stopping at height %d " | LogPrintf("VerifyDB(): block verification stopping at height %d " | ||||
"(pruning, no data)\n", | "(pruning, no data)\n", | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | if (nCheckLevel >= 4) { | ||||
CBlockIndex *pindex = pindexState; | CBlockIndex *pindex = pindexState; | ||||
while (pindex != chainActive.Tip()) { | while (pindex != chainActive.Tip()) { | ||||
boost::this_thread::interruption_point(); | boost::this_thread::interruption_point(); | ||||
uiInterface.ShowProgress( | uiInterface.ShowProgress( | ||||
_("Verifying blocks..."), | _("Verifying blocks..."), | ||||
std::max( | 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))), | ||||
false); | |||||
pindex = chainActive.Next(pindex); | pindex = chainActive.Next(pindex); | ||||
CBlock block; | CBlock block; | ||||
if (!ReadBlockFromDisk(block, pindex, config)) { | if (!ReadBlockFromDisk(block, pindex, config)) { | ||||
return error( | return error( | ||||
"VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", | "VerifyDB(): *** ReadBlockFromDisk failed at %d, hash=%s", | ||||
pindex->nHeight, pindex->GetBlockHash().ToString()); | pindex->nHeight, pindex->GetBlockHash().ToString()); | ||||
} | } | ||||
if (!ConnectBlock(config, block, state, pindex, coins)) { | if (!ConnectBlock(config, block, state, pindex, coins)) { | ||||
▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | if (hashHeads.empty()) { | ||||
// We're already in a consistent state. | // We're already in a consistent state. | ||||
return true; | return true; | ||||
} | } | ||||
if (hashHeads.size() != 2) { | if (hashHeads.size() != 2) { | ||||
return error("ReplayBlocks(): unknown inconsistent state"); | return error("ReplayBlocks(): unknown inconsistent state"); | ||||
} | } | ||||
uiInterface.ShowProgress(_("Replaying blocks..."), 0); | uiInterface.ShowProgress(_("Replaying blocks..."), 0, false); | ||||
LogPrintf("Replaying blocks\n"); | LogPrintf("Replaying blocks\n"); | ||||
// Old tip during the interrupted flush. | // Old tip during the interrupted flush. | ||||
const CBlockIndex *pindexOld = nullptr; | const CBlockIndex *pindexOld = nullptr; | ||||
// New tip during the interrupted flush. | // New tip during the interrupted flush. | ||||
const CBlockIndex *pindexNew; | const CBlockIndex *pindexNew; | ||||
// Latest block common to both the old and the new tip. | // Latest block common to both the old and the new tip. | ||||
const CBlockIndex *pindexFork = nullptr; | const CBlockIndex *pindexFork = nullptr; | ||||
▲ Show 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | for (int nHeight = nForkHeight + 1; nHeight <= pindexNew->nHeight; | ||||
pindex->GetBlockHash().ToString(), nHeight); | pindex->GetBlockHash().ToString(), nHeight); | ||||
if (!RollforwardBlock(pindex, cache, config)) { | if (!RollforwardBlock(pindex, cache, config)) { | ||||
return false; | return false; | ||||
} | } | ||||
} | } | ||||
cache.SetBestBlock(pindexNew->GetBlockHash()); | cache.SetBestBlock(pindexNew->GetBlockHash()); | ||||
cache.Flush(); | cache.Flush(); | ||||
uiInterface.ShowProgress("", 100); | uiInterface.ShowProgress("", 100, false); | ||||
return true; | return true; | ||||
} | } | ||||
bool RewindBlockIndex(const Config &config) { | bool RewindBlockIndex(const Config &config) { | ||||
LOCK(cs_main); | LOCK(cs_main); | ||||
const CChainParams ¶ms = config.GetChainParams(); | const CChainParams ¶ms = config.GetChainParams(); | ||||
int nHeight = chainActive.Height() + 1; | int nHeight = chainActive.Height() + 1; | ||||
▲ Show 20 Lines • Show All 798 Lines • Show Last 20 Lines |