mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-10 14:48:46 +02:00
chain: add CChain::IsTipRecent helper
Factor the chain tip work/recency check out of `ChainstateManager::IsInitialBlockDownload()` into a reusable `CChain::IsTipRecent()` helper, and annotate it as requiring `cs_main` since it's reading mutable state. Also introduce a local `chainman_ref` in the kernel import-blocks wrapper to reduce repetition and keep follow-up diffs small. `IsInitialBlockDownload` returns were also unified to make the followup move clean. Co-authored-by: Patrick Strateman <patrick.strateman@gmail.com> Co-authored-by: Martin Zumsande <mzumsande@gmail.com>
This commit is contained in:
@@ -1947,25 +1947,12 @@ void Chainstate::InitCoinsCache(size_t cache_size_bytes)
|
||||
bool ChainstateManager::IsInitialBlockDownload() const
|
||||
{
|
||||
// Optimization: pre-test latch before taking the lock.
|
||||
if (!m_cached_is_ibd.load(std::memory_order_relaxed))
|
||||
return false;
|
||||
if (!m_cached_is_ibd.load(std::memory_order_relaxed)) return false;
|
||||
|
||||
LOCK(cs_main);
|
||||
if (!m_cached_is_ibd.load(std::memory_order_relaxed))
|
||||
return false;
|
||||
if (m_blockman.LoadingBlocks()) {
|
||||
return true;
|
||||
}
|
||||
CChain& chain{ActiveChain()};
|
||||
if (chain.Tip() == nullptr) {
|
||||
return true;
|
||||
}
|
||||
if (chain.Tip()->nChainWork < MinimumChainWork()) {
|
||||
return true;
|
||||
}
|
||||
if (chain.Tip()->Time() < Now<NodeSeconds>() - m_options.max_tip_age) {
|
||||
return true;
|
||||
}
|
||||
if (!m_cached_is_ibd.load(std::memory_order_relaxed)) return false;
|
||||
if (m_blockman.LoadingBlocks()) return true;
|
||||
if (!ActiveChain().IsTipRecent(MinimumChainWork(), m_options.max_tip_age)) return true;
|
||||
LogInfo("Leaving InitialBlockDownload (latching to false)");
|
||||
m_cached_is_ibd.store(false, std::memory_order_relaxed);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user