mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-29 00:45:50 +01:00
Merge bitcoin/bitcoin#24515: Only load BlockMan in BlockMan member functions
f865cf8dedAdd and use BlockManager::GetAllBlockIndices (Carl Dong)28ba0313eaAdd and use CBlockIndexHeightOnlyComparator (Carl Dong)12eb05df63move-only: Move CBlockIndexWorkComparator to blockstorage (Carl Dong)c600ee3816Only load BlockMan in BlockMan member functions (Carl Dong)42e56d9b18style-only: No need for std::pair for vSortedByHeight (Carl Dong)3bbb6fea05style-only: Various blockstorage.cpp cleanups (Carl Dong)5be9ee3c54refactor: more const annotations for uses of CBlockIndex* (Anthony Towns) Pull request description: The only important commit is "Only load BlockMan in BlockMan member functions", everything else is all just small style changes. Here's the commit message, reproduced: ``` This commit effectively splits the "load block index itself" logic from "derive Chainstate variables from loaded block index" logic. This means that BlockManager::LoadBlockIndex{,DB} will only load what's relevant to the BlockManager. ``` ACKs for top commit: ajtowns: ACKf865cf8ded; code review only MarcoFalke: review ACKf865cf8ded🗂 Tree-SHA512: 7b204d782834e06fd7329d022e2ae860181b4e8105c33bfb928539a4ec24161dc7438a9c4d4ee279dcad77de310c160b997bb8aa18923243d0fd55ccf4ad7c3a
This commit is contained in:
@@ -104,7 +104,8 @@ static int ComputeNextBlockAndDepth(const CBlockIndex* tip, const CBlockIndex* b
|
||||
return blockindex == tip ? 1 : -1;
|
||||
}
|
||||
|
||||
CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateManager& chainman) {
|
||||
static const CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateManager& chainman)
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
CChain& active_chain = chainman.ActiveChain();
|
||||
|
||||
@@ -121,7 +122,7 @@ CBlockIndex* ParseHashOrHeight(const UniValue& param, ChainstateManager& chainma
|
||||
return active_chain[height];
|
||||
} else {
|
||||
const uint256 hash{ParseHashV(param, "hash_or_height")};
|
||||
CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
|
||||
const CBlockIndex* pindex = chainman.m_blockman.LookupBlockIndex(hash);
|
||||
|
||||
if (!pindex) {
|
||||
throw JSONRPCError(RPC_INVALID_ADDRESS_OR_KEY, "Block not found");
|
||||
@@ -488,7 +489,7 @@ static RPCHelpMan getblockhash()
|
||||
if (nHeight < 0 || nHeight > active_chain.Height())
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Block height out of range");
|
||||
|
||||
CBlockIndex* pblockindex = active_chain[nHeight];
|
||||
const CBlockIndex* pblockindex = active_chain[nHeight];
|
||||
return pblockindex->GetBlockHash().GetHex();
|
||||
},
|
||||
};
|
||||
@@ -766,7 +767,7 @@ static RPCHelpMan pruneblockchain()
|
||||
// too low to be a block time (corresponds to timestamp from Sep 2001).
|
||||
if (heightParam > 1000000000) {
|
||||
// Add a 2 hour buffer to include blocks which might have had old timestamps
|
||||
CBlockIndex* pindex = active_chain.FindEarliestAtLeast(heightParam - TIMESTAMP_WINDOW, 0);
|
||||
const CBlockIndex* pindex = active_chain.FindEarliestAtLeast(heightParam - TIMESTAMP_WINDOW, 0);
|
||||
if (!pindex) {
|
||||
throw JSONRPCError(RPC_INVALID_PARAMETER, "Could not find block with at least the specified timestamp.");
|
||||
}
|
||||
@@ -860,7 +861,7 @@ static RPCHelpMan gettxoutsetinfo()
|
||||
{
|
||||
UniValue ret(UniValue::VOBJ);
|
||||
|
||||
CBlockIndex* pindex{nullptr};
|
||||
const CBlockIndex* pindex{nullptr};
|
||||
const CoinStatsHashType hash_type{request.params[0].isNull() ? CoinStatsHashType::HASH_SERIALIZED : ParseHashType(request.params[0].get_str())};
|
||||
CCoinsStats stats{hash_type};
|
||||
stats.index_requested = request.params[2].isNull() || request.params[2].get_bool();
|
||||
@@ -1764,7 +1765,7 @@ static RPCHelpMan getblockstats()
|
||||
{
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* pindex{ParseHashOrHeight(request.params[0], chainman)};
|
||||
const CBlockIndex* pindex{ParseHashOrHeight(request.params[0], chainman)};
|
||||
CHECK_NONFATAL(pindex != nullptr);
|
||||
|
||||
std::set<std::string> stats;
|
||||
@@ -2124,7 +2125,7 @@ static RPCHelpMan scantxoutset()
|
||||
g_should_abort_scan = false;
|
||||
int64_t count = 0;
|
||||
std::unique_ptr<CCoinsViewCursor> pcursor;
|
||||
CBlockIndex* tip;
|
||||
const CBlockIndex* tip;
|
||||
NodeContext& node = EnsureAnyNodeContext(request.context);
|
||||
{
|
||||
ChainstateManager& chainman = EnsureChainman(node);
|
||||
@@ -2312,7 +2313,7 @@ UniValue CreateUTXOSnapshot(
|
||||
{
|
||||
std::unique_ptr<CCoinsViewCursor> pcursor;
|
||||
CCoinsStats stats{CoinStatsHashType::HASH_SERIALIZED};
|
||||
CBlockIndex* tip;
|
||||
const CBlockIndex* tip;
|
||||
|
||||
{
|
||||
// We need to lock cs_main to ensure that the coinsdb isn't written to
|
||||
|
||||
Reference in New Issue
Block a user