aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2020-12-24 16:18:46 -0500
committerCarl Dong <contact@carldong.me>2022-04-19 14:34:55 -0400
commit0d567daf23c9fcb2d95b38913ee45a8b0ba3b027 (patch)
tree42b303f528ebc5b426bcbc614afce1a9b892a357 /src/node
parent5d670173a32ccdcb25d3a6bf97317f0ac774e0ed (diff)
downloadbitcoin-0d567daf23c9fcb2d95b38913ee45a8b0ba3b027.tar.xz
move-mostly: Make pindexBestHeader a ChainMan member
[META] In the next commit, we move the clearing of pindexBestHeader to ChainstateManager::Unload()
Diffstat (limited to 'src/node')
-rw-r--r--src/node/blockstorage.cpp7
-rw-r--r--src/node/blockstorage.h2
-rw-r--r--src/node/interfaces.cpp7
3 files changed, 9 insertions, 7 deletions
diff --git a/src/node/blockstorage.cpp b/src/node/blockstorage.cpp
index 45e7ca4796..c7a769eb33 100644
--- a/src/node/blockstorage.cpp
+++ b/src/node/blockstorage.cpp
@@ -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);
diff --git a/src/node/blockstorage.h b/src/node/blockstorage.h
index a051e90808..3a95e321f7 100644
--- a/src/node/blockstorage.h
+++ b/src/node/blockstorage.h
@@ -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);
diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp
index 73d15652b1..96e0e365a4 100644
--- a/src/node/interfaces.cpp
+++ b/src/node/interfaces.cpp
@@ -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;