mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Merge bitcoin/bitcoin#25016: refactor: GetFirstStoredBlock() and getblockchaininfo follow-ups
e2b954e87f
rpc: use GetBlockTime() for getblockchaininfo#time (Jon Atack)86ce844d3b
blockstorage, refactor: pass GetFirstStoredBlock() start_block by reference (Jon Atack)ed12c0a49d
blockstorage, refactor: make GetFirstStoredBlock() a member of BlockManager (Jon Atack) Pull request description: Picks up the remaining review feedback in #21726 and #24956. - make the global function `GetFirstStoredBlock()` a member of the `BlockManager` class - pass the `start_block` param of `GetFirstStoredBlock()` by reference instead of a pointer - use `GetBlockTime()` for RPC getblockchaininfo#time ACKs for top commit: MarcoFalke: ACKe2b954e87f
Tree-SHA512: 546e3c2e18245996b5b286829a605ae919eff3510963ec71b7c9ede521b1f501697e5b2f9d35d7a0606a74cbc8907201c58acf1e2cf7daaa86eefe2e3a8e296b
This commit is contained in:
commit
194b414697
4 changed files with 13 additions and 12 deletions
|
@ -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
|
||||
|
|
|
@ -390,10 +390,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;
|
||||
}
|
||||
|
|
|
@ -178,6 +178,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;
|
||||
|
||||
|
@ -188,9 +191,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) */
|
||||
|
|
|
@ -760,8 +760,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).
|
||||
|
@ -786,8 +787,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);
|
||||
},
|
||||
|
@ -1207,7 +1208,7 @@ RPCHelpMan getblockchaininfo()
|
|||
obj.pushKV("headers", chainman.m_best_header ? chainman.m_best_header->nHeight : -1);
|
||||
obj.pushKV("bestblockhash", tip.GetBlockHash().GetHex());
|
||||
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(Params().TxData(), &tip));
|
||||
obj.pushKV("initialblockdownload", active_chainstate.IsInitialBlockDownload());
|
||||
|
@ -1215,7 +1216,7 @@ RPCHelpMan getblockchaininfo()
|
|||
obj.pushKV("size_on_disk", chainman.m_blockman.CalculateCurrentUsage());
|
||||
obj.pushKV("pruned", node::fPruneMode);
|
||||
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};
|
||||
|
|
Loading…
Add table
Reference in a new issue