Skip to content

Commit 57ef2a4

Browse files
committed
validation: report if pruning prevents completion of verification
Now the verifychain RPC returns false if the checks didn't finish because the blocks requested to be queried have been pruned.
1 parent 0c7785b commit 57ef2a4

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

src/node/chainstate.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const C
194194
switch (result) {
195195
case VerifyDBResult::SUCCESS:
196196
case VerifyDBResult::INTERRUPTED:
197+
case VerifyDBResult::SKIPPED_MISSING_BLOCKS:
197198
break;
198199
case VerifyDBResult::CORRUPTED_BLOCK_DB:
199200
return {ChainstateLoadStatus::FAILURE, _("Corrupted block database detected")};

src/validation.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4081,6 +4081,7 @@ VerifyDBResult CVerifyDB::VerifyDB(
40814081
int nGoodTransactions = 0;
40824082
BlockValidationState state;
40834083
int reportDone = 0;
4084+
bool skipped_no_block_data{false};
40844085
bool skipped_l3_checks{false};
40854086
LogPrintf("Verification progress: 0%%\n");
40864087

@@ -4100,7 +4101,8 @@ VerifyDBResult CVerifyDB::VerifyDB(
41004101
if ((chainstate.m_blockman.IsPruneMode() || is_snapshot_cs) && !(pindex->nStatus & BLOCK_HAVE_DATA)) {
41014102
// If pruning or running under an assumeutxo snapshot, only go
41024103
// back as far as we have data.
4103-
LogPrintf("VerifyDB(): block verification stopping at height %d (pruning, no data)\n", pindex->nHeight);
4104+
LogPrintf("VerifyDB(): block verification stopping at height %d (no data). This could be due to pruning or use of an assumeutxo snapshot.\n", pindex->nHeight);
4105+
skipped_no_block_data = true;
41044106
break;
41054107
}
41064108
CBlock block;
@@ -4188,6 +4190,9 @@ VerifyDBResult CVerifyDB::VerifyDB(
41884190
if (skipped_l3_checks) {
41894191
return VerifyDBResult::SKIPPED_L3_CHECKS;
41904192
}
4193+
if (skipped_no_block_data) {
4194+
return VerifyDBResult::SKIPPED_MISSING_BLOCKS;
4195+
}
41914196
return VerifyDBResult::SUCCESS;
41924197
}
41934198

src/validation.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ enum class VerifyDBResult {
354354
CORRUPTED_BLOCK_DB,
355355
INTERRUPTED,
356356
SKIPPED_L3_CHECKS,
357+
SKIPPED_MISSING_BLOCKS,
357358
};
358359

359360
/** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */

test/functional/feature_pruning.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ def reorg_test(self):
223223
def reorg_back(self):
224224
# Verify that a block on the old main chain fork has been pruned away
225225
assert_raises_rpc_error(-1, "Block not available (pruned data)", self.nodes[2].getblock, self.forkhash)
226-
with self.nodes[2].assert_debug_log(expected_msgs=['block verification stopping at height', '(pruning, no data)']):
227-
self.nodes[2].verifychain(checklevel=4, nblocks=0)
226+
with self.nodes[2].assert_debug_log(expected_msgs=['block verification stopping at height', '(no data)']):
227+
assert not self.nodes[2].verifychain(checklevel=4, nblocks=0)
228228
self.log.info(f"Will need to redownload block {self.forkheight}")
229229

230230
# Verify that we have enough history to reorg back to the fork point

0 commit comments

Comments
 (0)