diff options
author | Martin Zumsande <mzumsande@gmail.com> | 2023-02-06 15:05:33 -0500 |
---|---|---|
committer | Martin Zumsande <mzumsande@gmail.com> | 2023-02-16 17:58:52 -0500 |
commit | 57ef2a4812f443b2d734f43cebf3ef5038da83f2 (patch) | |
tree | 4a6adc2b45ff7e36e47e6d5b97e03ee4f3c9b43d | |
parent | 0c7785bb2540b69564104767d38342704230cbc2 (diff) | |
download | bitcoin-57ef2a4812f443b2d734f43cebf3ef5038da83f2.tar.xz |
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.
-rw-r--r-- | src/node/chainstate.cpp | 1 | ||||
-rw-r--r-- | src/validation.cpp | 7 | ||||
-rw-r--r-- | src/validation.h | 1 | ||||
-rwxr-xr-x | test/functional/feature_pruning.py | 4 |
4 files changed, 10 insertions, 3 deletions
diff --git a/src/node/chainstate.cpp b/src/node/chainstate.cpp index c521b20b2a..11898ac0b3 100644 --- a/src/node/chainstate.cpp +++ b/src/node/chainstate.cpp @@ -194,6 +194,7 @@ ChainstateLoadResult VerifyLoadedChainstate(ChainstateManager& chainman, const C switch (result) { case VerifyDBResult::SUCCESS: case VerifyDBResult::INTERRUPTED: + case VerifyDBResult::SKIPPED_MISSING_BLOCKS: break; case VerifyDBResult::CORRUPTED_BLOCK_DB: return {ChainstateLoadStatus::FAILURE, _("Corrupted block database detected")}; diff --git a/src/validation.cpp b/src/validation.cpp index 4da52b7d8b..de1a4ce91f 100644 --- a/src/validation.cpp +++ b/src/validation.cpp @@ -4081,6 +4081,7 @@ VerifyDBResult CVerifyDB::VerifyDB( int nGoodTransactions = 0; BlockValidationState state; int reportDone = 0; + bool skipped_no_block_data{false}; bool skipped_l3_checks{false}; LogPrintf("Verification progress: 0%%\n"); @@ -4100,7 +4101,8 @@ VerifyDBResult CVerifyDB::VerifyDB( if ((chainstate.m_blockman.IsPruneMode() || is_snapshot_cs) && !(pindex->nStatus & BLOCK_HAVE_DATA)) { // If pruning or running under an assumeutxo snapshot, only go // back as far as we have data. - LogPrintf("VerifyDB(): block verification stopping at height %d (pruning, no data)\n", pindex->nHeight); + 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); + skipped_no_block_data = true; break; } CBlock block; @@ -4188,6 +4190,9 @@ VerifyDBResult CVerifyDB::VerifyDB( if (skipped_l3_checks) { return VerifyDBResult::SKIPPED_L3_CHECKS; } + if (skipped_no_block_data) { + return VerifyDBResult::SKIPPED_MISSING_BLOCKS; + } return VerifyDBResult::SUCCESS; } diff --git a/src/validation.h b/src/validation.h index 044b4ef823..65f59ab2c2 100644 --- a/src/validation.h +++ b/src/validation.h @@ -354,6 +354,7 @@ enum class VerifyDBResult { CORRUPTED_BLOCK_DB, INTERRUPTED, SKIPPED_L3_CHECKS, + SKIPPED_MISSING_BLOCKS, }; /** RAII wrapper for VerifyDB: Verify consistency of the block and coin databases */ diff --git a/test/functional/feature_pruning.py b/test/functional/feature_pruning.py index 664ed779db..519877ac5b 100755 --- a/test/functional/feature_pruning.py +++ b/test/functional/feature_pruning.py @@ -223,8 +223,8 @@ class PruneTest(BitcoinTestFramework): def reorg_back(self): # Verify that a block on the old main chain fork has been pruned away assert_raises_rpc_error(-1, "Block not available (pruned data)", self.nodes[2].getblock, self.forkhash) - with self.nodes[2].assert_debug_log(expected_msgs=['block verification stopping at height', '(pruning, no data)']): - self.nodes[2].verifychain(checklevel=4, nblocks=0) + with self.nodes[2].assert_debug_log(expected_msgs=['block verification stopping at height', '(no data)']): + assert not self.nodes[2].verifychain(checklevel=4, nblocks=0) self.log.info(f"Will need to redownload block {self.forkheight}") # Verify that we have enough history to reorg back to the fork point |