mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-07 02:11:06 +02:00
refactor: more const annotations for uses of CBlockIndex*
This commit is contained in:
parent
430acb7d2a
commit
5be9ee3c54
@ -277,7 +277,7 @@ bool CoinStatsIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* n
|
||||
|
||||
{
|
||||
LOCK(cs_main);
|
||||
CBlockIndex* iter_tip{m_chainstate->m_blockman.LookupBlockIndex(current_tip->GetBlockHash())};
|
||||
const CBlockIndex* iter_tip{m_chainstate->m_blockman.LookupBlockIndex(current_tip->GetBlockHash())};
|
||||
const auto& consensus_params{Params().GetConsensus()};
|
||||
|
||||
do {
|
||||
|
@ -408,13 +408,13 @@ bool BlockManager::LoadBlockIndexDB(ChainstateManager& chainman)
|
||||
return true;
|
||||
}
|
||||
|
||||
CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
|
||||
const CBlockIndex* BlockManager::GetLastCheckpoint(const CCheckpointData& data)
|
||||
{
|
||||
const MapCheckpoints& checkpoints = data.mapCheckpoints;
|
||||
|
||||
for (const MapCheckpoints::value_type& i : reverse_iterate(checkpoints)) {
|
||||
const uint256& hash = i.second;
|
||||
CBlockIndex* pindex = LookupBlockIndex(hash);
|
||||
const CBlockIndex* pindex = LookupBlockIndex(hash);
|
||||
if (pindex) {
|
||||
return pindex;
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public:
|
||||
uint64_t CalculateCurrentUsage();
|
||||
|
||||
//! Returns last CBlockIndex* that is a checkpoint
|
||||
CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
const CBlockIndex* GetLastCheckpoint(const CCheckpointData& data) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
~BlockManager()
|
||||
{
|
||||
|
@ -490,7 +490,7 @@ public:
|
||||
{
|
||||
LOCK(cs_main);
|
||||
const CChainState& active = Assert(m_node.chainman)->ActiveChainstate();
|
||||
if (CBlockIndex* fork = active.FindForkInGlobalIndex(locator)) {
|
||||
if (const CBlockIndex* fork = active.FindForkInGlobalIndex(locator)) {
|
||||
return fork->nHeight;
|
||||
}
|
||||
return std::nullopt;
|
||||
@ -557,7 +557,7 @@ public:
|
||||
// used to limit the range, and passing min_height that's too low or
|
||||
// max_height that's too high will not crash or change the result.
|
||||
LOCK(::cs_main);
|
||||
if (CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) {
|
||||
if (const CBlockIndex* block = chainman().m_blockman.LookupBlockIndex(block_hash)) {
|
||||
if (max_height && block->nHeight >= *max_height) block = block->GetAncestor(*max_height);
|
||||
for (; block->nStatus & BLOCK_HAVE_DATA; block = block->pprev) {
|
||||
// Check pprev to not segfault if min_height is too low
|
||||
|
@ -50,7 +50,7 @@ void RegenerateCommitments(CBlock& block, ChainstateManager& chainman)
|
||||
tx.vout.erase(tx.vout.begin() + GetWitnessCommitmentIndex(block));
|
||||
block.vtx.at(0) = MakeTransactionRef(tx);
|
||||
|
||||
CBlockIndex* prev_block = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock));
|
||||
const CBlockIndex* prev_block = WITH_LOCK(::cs_main, return chainman.m_blockman.LookupBlockIndex(block.hashPrevBlock));
|
||||
GenerateCoinbaseCommitment(block, prev_block, Params().GetConsensus());
|
||||
|
||||
block.hashMerkleRoot = BlockMerkleRoot(block);
|
||||
|
@ -283,8 +283,8 @@ static bool rest_block(const std::any& context,
|
||||
return RESTERR(req, HTTP_BAD_REQUEST, "Invalid hash: " + hashStr);
|
||||
|
||||
CBlock block;
|
||||
CBlockIndex* pblockindex = nullptr;
|
||||
CBlockIndex* tip = nullptr;
|
||||
const CBlockIndex* pblockindex = nullptr;
|
||||
const CBlockIndex* tip = nullptr;
|
||||
{
|
||||
ChainstateManager* maybe_chainman = GetChainman(context, req);
|
||||
if (!maybe_chainman) return false;
|
||||
|
@ -110,7 +110,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();
|
||||
|
||||
@ -127,7 +128,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");
|
||||
@ -854,7 +855,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();
|
||||
},
|
||||
};
|
||||
@ -1132,7 +1133,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.");
|
||||
}
|
||||
@ -1226,7 +1227,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();
|
||||
@ -2177,7 +2178,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;
|
||||
@ -2572,7 +2573,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);
|
||||
@ -2760,7 +2761,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
|
||||
|
@ -67,7 +67,7 @@ static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue&
|
||||
LOCK(cs_main);
|
||||
|
||||
entry.pushKV("blockhash", hashBlock.GetHex());
|
||||
CBlockIndex* pindex = active_chainstate.m_blockman.LookupBlockIndex(hashBlock);
|
||||
const CBlockIndex* pindex = active_chainstate.m_blockman.LookupBlockIndex(hashBlock);
|
||||
if (pindex) {
|
||||
if (active_chainstate.m_chain.Contains(pindex)) {
|
||||
entry.pushKV("confirmations", 1 + active_chainstate.m_chain.Height() - pindex->nHeight);
|
||||
@ -207,7 +207,7 @@ static RPCHelpMan getrawtransaction()
|
||||
|
||||
bool in_active_chain = true;
|
||||
uint256 hash = ParseHashV(request.params[0], "parameter 1");
|
||||
CBlockIndex* blockindex = nullptr;
|
||||
const CBlockIndex* blockindex = nullptr;
|
||||
|
||||
if (hash == Params().GenesisBlock().hashMerkleRoot) {
|
||||
// Special exception for the genesis block coinbase transaction
|
||||
@ -302,7 +302,7 @@ static RPCHelpMan gettxoutproof()
|
||||
}
|
||||
}
|
||||
|
||||
CBlockIndex* pblockindex = nullptr;
|
||||
const CBlockIndex* pblockindex = nullptr;
|
||||
uint256 hashBlock;
|
||||
ChainstateManager& chainman = EnsureAnyChainman(request.context);
|
||||
if (!request.params[1].isNull()) {
|
||||
|
@ -152,14 +152,14 @@ arith_uint256 nMinimumChainWork;
|
||||
|
||||
CFeeRate minRelayTxFee = CFeeRate(DEFAULT_MIN_RELAY_TX_FEE);
|
||||
|
||||
CBlockIndex* CChainState::FindForkInGlobalIndex(const CBlockLocator& locator) const
|
||||
const CBlockIndex* CChainState::FindForkInGlobalIndex(const CBlockLocator& locator) const
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
// Find the latest block common to locator and chain - we expect that
|
||||
// locator.vHave is sorted descending by height.
|
||||
for (const uint256& hash : locator.vHave) {
|
||||
CBlockIndex* pindex{m_blockman.LookupBlockIndex(hash)};
|
||||
const CBlockIndex* pindex{m_blockman.LookupBlockIndex(hash)};
|
||||
if (pindex) {
|
||||
if (m_chain.Contains(pindex)) {
|
||||
return pindex;
|
||||
@ -3373,7 +3373,7 @@ static bool ContextualCheckBlockHeader(const CBlockHeader& block, BlockValidatio
|
||||
// Don't accept any forks from the main chain prior to last checkpoint.
|
||||
// GetLastCheckpoint finds the last checkpoint in MapCheckpoints that's in our
|
||||
// BlockIndex().
|
||||
CBlockIndex* pcheckpoint = blockman.GetLastCheckpoint(params.Checkpoints());
|
||||
const CBlockIndex* pcheckpoint = blockman.GetLastCheckpoint(params.Checkpoints());
|
||||
if (pcheckpoint && nHeight < pcheckpoint->nHeight) {
|
||||
LogPrintf("ERROR: %s: forked chain older than last checkpoint (height %d)\n", __func__, nHeight);
|
||||
return state.Invalid(BlockValidationResult::BLOCK_CHECKPOINT, "bad-fork-prior-to-checkpoint");
|
||||
@ -4186,7 +4186,7 @@ void CChainState::LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp)
|
||||
}
|
||||
|
||||
// process in case the block isn't known yet
|
||||
CBlockIndex* pindex = m_blockman.LookupBlockIndex(hash);
|
||||
const CBlockIndex* pindex = m_blockman.LookupBlockIndex(hash);
|
||||
if (!pindex || (pindex->nStatus & BLOCK_HAVE_DATA) == 0) {
|
||||
BlockValidationState state;
|
||||
if (AcceptBlock(pblock, state, nullptr, true, dbp, nullptr)) {
|
||||
|
@ -693,7 +693,7 @@ public:
|
||||
bool IsInitialBlockDownload() const;
|
||||
|
||||
/** Find the last common block of this chain and a locator. */
|
||||
CBlockIndex* FindForkInGlobalIndex(const CBlockLocator& locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
const CBlockIndex* FindForkInGlobalIndex(const CBlockLocator& locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
/**
|
||||
* Make various assertions about the state of the block index.
|
||||
|
Loading…
x
Reference in New Issue
Block a user