mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 06:58:57 +01:00
move-mostly: Make pindexBestHeader a ChainMan member
[META] In the next commit, we move the clearing of pindexBestHeader to
ChainstateManager::Unload()
This commit is contained in:
@@ -81,7 +81,7 @@ const CBlockIndex* BlockManager::LookupBlockIndex(const uint256& hash) const
|
||||
return it == m_block_index.end() ? nullptr : &it->second;
|
||||
}
|
||||
|
||||
CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
|
||||
CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block, CBlockIndex*& best_header)
|
||||
{
|
||||
AssertLockHeld(cs_main);
|
||||
|
||||
@@ -106,8 +106,9 @@ CBlockIndex* BlockManager::AddToBlockIndex(const CBlockHeader& block)
|
||||
pindexNew->nTimeMax = (pindexNew->pprev ? std::max(pindexNew->pprev->nTimeMax, pindexNew->nTime) : pindexNew->nTime);
|
||||
pindexNew->nChainWork = (pindexNew->pprev ? pindexNew->pprev->nChainWork : 0) + GetBlockProof(*pindexNew);
|
||||
pindexNew->RaiseValidity(BLOCK_VALID_TREE);
|
||||
if (pindexBestHeader == nullptr || pindexBestHeader->nChainWork < pindexNew->nChainWork)
|
||||
pindexBestHeader = pindexNew;
|
||||
if (best_header == nullptr || best_header->nChainWork < pindexNew->nChainWork) {
|
||||
best_header = pindexNew;
|
||||
}
|
||||
|
||||
m_dirty_blockindex.insert(pindexNew);
|
||||
|
||||
|
||||
@@ -147,7 +147,7 @@ public:
|
||||
/** Clear all data members. */
|
||||
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
CBlockIndex* AddToBlockIndex(const CBlockHeader& block) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
CBlockIndex* AddToBlockIndex(const CBlockHeader& block, CBlockIndex*& best_header) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
/** Create a new block index entry for a given block hash */
|
||||
CBlockIndex* InsertBlockIndex(const uint256& hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
|
||||
|
||||
|
||||
@@ -212,9 +212,10 @@ public:
|
||||
bool getHeaderTip(int& height, int64_t& block_time) override
|
||||
{
|
||||
LOCK(::cs_main);
|
||||
if (::pindexBestHeader) {
|
||||
height = ::pindexBestHeader->nHeight;
|
||||
block_time = ::pindexBestHeader->GetBlockTime();
|
||||
auto best_header = chainman().pindexBestHeader;
|
||||
if (best_header) {
|
||||
height = best_header->nHeight;
|
||||
block_time = best_header->GetBlockTime();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user