Merge 194b414697 into merged_master (Bitcoin PR bitcoin/bitcoin#25016)

This commit is contained in:
James Dorfman 2024-08-08 17:30:27 +00:00
commit 387cfbcfe8
4 changed files with 13 additions and 12 deletions

View file

@ -75,7 +75,7 @@ bool BaseIndex::Init()
if (!m_best_block_index) {
// index is not built yet
// make sure we have all block data back to the genesis
prune_violation = node::GetFirstStoredBlock(active_chain.Tip()) != active_chain.Genesis();
prune_violation = m_chainstate->m_blockman.GetFirstStoredBlock(*active_chain.Tip()) != active_chain.Genesis();
}
// in case the index has a best block set and is not fully synced
// check if we have the required blocks to continue building the index

View file

@ -406,10 +406,10 @@ bool BlockManager::IsBlockPruned(const CBlockIndex* pblockindex)
return (m_have_pruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
}
const CBlockIndex* GetFirstStoredBlock(const CBlockIndex* start_block) {
const CBlockIndex* BlockManager::GetFirstStoredBlock(const CBlockIndex& start_block)
{
AssertLockHeld(::cs_main);
assert(start_block);
const CBlockIndex* last_block = start_block;
const CBlockIndex* last_block = &start_block;
while (last_block->pprev && (last_block->pprev->nStatus & BLOCK_HAVE_DATA)) {
last_block = last_block->pprev;
}

View file

@ -185,6 +185,9 @@ public:
//! Returns last CBlockIndex* that is a checkpoint
const CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
//! Find the first block that is not pruned
const CBlockIndex* GetFirstStoredBlock(const CBlockIndex& start_block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
/** True if any block files have ever been pruned. */
bool m_have_pruned = false;
@ -195,9 +198,6 @@ public:
void UpdatePruneLock(const std::string& name, const PruneLockInfo& lock_info) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
};
//! Find the first block that is not pruned
const CBlockIndex* GetFirstStoredBlock(const CBlockIndex* start_block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
void CleanupBlockRevFiles();
/** Open a block file (blk?????.dat) */

View file

@ -884,8 +884,9 @@ static RPCHelpMan pruneblockchain()
CChain& active_chain = active_chainstate.m_chain;
int heightParam = request.params[0].get_int();
if (heightParam < 0)
if (heightParam < 0) {
throw JSONRPCError(RPC_INVALID_PARAMETER, "Negative block height.");
}
// Height value more than a billion is too high to be a block height, and
// too low to be a block time (corresponds to timestamp from Sep 2001).
@ -910,8 +911,8 @@ static RPCHelpMan pruneblockchain()
}
PruneBlockFilesManual(active_chainstate, height);
const CBlockIndex* block = CHECK_NONFATAL(active_chain.Tip());
const CBlockIndex* last_block = node::GetFirstStoredBlock(block);
const CBlockIndex& block{*CHECK_NONFATAL(active_chain.Tip())};
const CBlockIndex* last_block{active_chainstate.m_blockman.GetFirstStoredBlock(block)};
return static_cast<uint64_t>(last_block->nHeight);
},
@ -1369,7 +1370,7 @@ RPCHelpMan getblockchaininfo()
if (!g_signed_blocks) {
obj.pushKV("difficulty", GetDifficulty(&tip));
}
obj.pushKV("time", int64_t{tip.nTime});
obj.pushKV("time", tip.GetBlockTime());
obj.pushKV("mediantime", tip.GetMedianTimePast());
obj.pushKV("verificationprogress", GuessVerificationProgress(&tip, Params().GetConsensus().nPowTargetSpacing));
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());
@ -1409,7 +1410,7 @@ RPCHelpMan getblockchaininfo()
}
if (node::fPruneMode) {
obj.pushKV("pruneheight", node::GetFirstStoredBlock(&tip)->nHeight);
obj.pushKV("pruneheight", chainman.m_blockman.GetFirstStoredBlock(tip)->nHeight);
// if 0, execution bypasses the whole if block.
bool automatic_pruning{args.GetIntArg("-prune", 0) != 1};