mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-11 12:22:39 -03:00
Merge bitcoin/bitcoin#27009: validation: Skip VerifyDB checks of level >=3 if dbcache is too small
fe683f3524
log: Log VerifyDB Progress over multiple lines (Martin Zumsande)61431e3a57
validation: Skip VerifyDB checks of level >=3 if dbcache is too small (Martin Zumsande) Pull request description: This is the first two commits from #25574, leaving out all changes to `-verifychain` error-handling : - The Problem of [25563](https://github.com/bitcoin/bitcoin/issues/25563) is that when we skip blocks at level 3 due to an insufficient dbcache (skipping some `DisconnectBlock()` calls), we would still attempt the level 4 checks, attempting to reconnect a block that was never disconnected, leading to an assert in `ConnectBlock()`. Fix this by not attempting level 4 checks in this case. - Logging of verification progress is now split over multiple lines. This is more verbose, but now each update has its own timestamp, and other threads logging concurrently will no longer lead to mangled output. This can be tested with a small `dbcache` value, for example: `bitcoind -signet -dbcache=10` `bitcoin-cli -signet verifychain 4 1000` Fixes #25563 ACKs for top commit: MarcoFalke: review ACKfe683f3524
🗄 john-moffett: ACKfe683f3524
Tree-SHA512: 3e2e0f8b73cbc518a0fa17912c1956da437787aab95001c110b01048472e0dfe4783c44df22bd903d198069dd2f6b02bfdf74e0b934c7a776f144c2e86cb818a
This commit is contained in:
commit
8f4ae65818
1 changed files with 23 additions and 17 deletions
|
@ -4081,7 +4081,8 @@ bool CVerifyDB::VerifyDB(
|
|||
int nGoodTransactions = 0;
|
||||
BlockValidationState state;
|
||||
int reportDone = 0;
|
||||
LogPrintf("[0%%]..."); /* Continued */
|
||||
bool skipped_l3_checks{false};
|
||||
LogPrintf("Verification progress: 0%%\n");
|
||||
|
||||
const bool is_snapshot_cs{!chainstate.m_from_snapshot_blockhash};
|
||||
|
||||
|
@ -4089,7 +4090,7 @@ bool CVerifyDB::VerifyDB(
|
|||
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) {
|
||||
// report every 10% step
|
||||
LogPrintf("[%d%%]...", percentageDone); /* Continued */
|
||||
LogPrintf("Verification progress: %d%%\n", percentageDone);
|
||||
reportDone = percentageDone / 10;
|
||||
}
|
||||
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
|
||||
|
@ -4124,17 +4125,21 @@ bool CVerifyDB::VerifyDB(
|
|||
// check level 3: check for inconsistencies during memory-only disconnect of tip blocks
|
||||
size_t curr_coins_usage = coins.DynamicMemoryUsage() + chainstate.CoinsTip().DynamicMemoryUsage();
|
||||
|
||||
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) {
|
||||
return error("VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
}
|
||||
if (res == DISCONNECT_UNCLEAN) {
|
||||
nGoodTransactions = 0;
|
||||
pindexFailure = pindex;
|
||||
if (nCheckLevel >= 3) {
|
||||
if (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) {
|
||||
return error("VerifyDB(): *** irrecoverable inconsistency in block data at %d, hash=%s", pindex->nHeight, pindex->GetBlockHash().ToString());
|
||||
}
|
||||
if (res == DISCONNECT_UNCLEAN) {
|
||||
nGoodTransactions = 0;
|
||||
pindexFailure = pindex;
|
||||
} else {
|
||||
nGoodTransactions += block.vtx.size();
|
||||
}
|
||||
} else {
|
||||
nGoodTransactions += block.vtx.size();
|
||||
skipped_l3_checks = true;
|
||||
}
|
||||
}
|
||||
if (ShutdownRequested()) return true;
|
||||
|
@ -4142,17 +4147,19 @@ bool CVerifyDB::VerifyDB(
|
|||
if (pindexFailure) {
|
||||
return error("VerifyDB(): *** coin database inconsistencies found (last %i blocks, %i good transactions before that)\n", chainstate.m_chain.Height() - pindexFailure->nHeight + 1, nGoodTransactions);
|
||||
}
|
||||
|
||||
if (skipped_l3_checks) {
|
||||
LogPrintf("Skipped verification of level >=3 (insufficient database cache size). Consider increasing -dbcache.\n");
|
||||
}
|
||||
// store block count as we move pindex at check level >= 4
|
||||
int block_count = chainstate.m_chain.Height() - pindex->nHeight;
|
||||
|
||||
// check level 4: try reconnecting blocks
|
||||
if (nCheckLevel >= 4) {
|
||||
if (nCheckLevel >= 4 && !skipped_l3_checks) {
|
||||
while (pindex != chainstate.m_chain.Tip()) {
|
||||
const int percentageDone = std::max(1, std::min(99, 100 - (int)(((double)(chainstate.m_chain.Height() - pindex->nHeight)) / (double)nCheckDepth * 50)));
|
||||
if (reportDone < percentageDone / 10) {
|
||||
// report every 10% step
|
||||
LogPrintf("[%d%%]...", percentageDone); /* Continued */
|
||||
LogPrintf("Verification progress: %d%%\n", percentageDone);
|
||||
reportDone = percentageDone / 10;
|
||||
}
|
||||
uiInterface.ShowProgress(_("Verifying blocks…").translated, percentageDone, false);
|
||||
|
@ -4167,8 +4174,7 @@ bool CVerifyDB::VerifyDB(
|
|||
}
|
||||
}
|
||||
|
||||
LogPrintf("[DONE].\n");
|
||||
LogPrintf("No coin database inconsistencies in last %i blocks (%i transactions)\n", block_count, nGoodTransactions);
|
||||
LogPrintf("Verification: No coin database inconsistencies in last %i blocks (%i transactions)\n", block_count, nGoodTransactions);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue