mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-19 06:43:45 +01:00
make GetFirstStoredBlock assert that 'start_block' always has data
And transfer the responsibility of verifying whether 'start_block' has data or not to the caller. This is because the 'GetFirstStoredBlock' function responsibility is to return the first block containing data. And the current implementation can return 'start_block' when it has no data!. Which is misleading at least. Edge case behavior change: Previously, if the block tip lacked data but all preceding blocks contained data, there was no prune violation. And now, such scenario will result in a prune violation.
This commit is contained in:
@@ -812,9 +812,7 @@ static RPCHelpMan pruneblockchain()
|
||||
|
||||
PruneBlockFilesManual(active_chainstate, height);
|
||||
const CBlockIndex& block{*CHECK_NONFATAL(active_chain.Tip())};
|
||||
const CBlockIndex* last_block{active_chainstate.m_blockman.GetFirstStoredBlock(block)};
|
||||
|
||||
return static_cast<int64_t>(last_block->nHeight - 1);
|
||||
return block.nStatus & BLOCK_HAVE_DATA ? active_chainstate.m_blockman.GetFirstStoredBlock(block)->nHeight - 1 : block.nHeight;
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -1267,7 +1265,8 @@ RPCHelpMan getblockchaininfo()
|
||||
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
|
||||
obj.pushKV("pruned", chainman.m_blockman.IsPruneMode());
|
||||
if (chainman.m_blockman.IsPruneMode()) {
|
||||
obj.pushKV("pruneheight", chainman.m_blockman.GetFirstStoredBlock(tip)->nHeight);
|
||||
bool has_tip_data = tip.nStatus & BLOCK_HAVE_DATA;
|
||||
obj.pushKV("pruneheight", has_tip_data ? chainman.m_blockman.GetFirstStoredBlock(tip)->nHeight : tip.nHeight + 1);
|
||||
|
||||
const bool automatic_pruning{chainman.m_blockman.GetPruneTarget() != BlockManager::PRUNE_TARGET_MANUAL};
|
||||
obj.pushKV("automatic_pruning", automatic_pruning);
|
||||
|
||||
Reference in New Issue
Block a user