Note that though this is marked const, we may end up modifying `m_cached_finished_ibd`, which is a performance-related implementation detail. This function must be marked `const` so that `CValidationInterface` clients (which are given a `const CChainState*`) can call it.
| 1573 | // can call it. |
| 1574 | // |
| 1575 | bool CChainState::IsInitialBlockDownload() const |
| 1576 | { |
| 1577 | // Optimization: pre-test latch before taking the lock. |
| 1578 | if (m_cached_finished_ibd.load(std::memory_order_relaxed)) |
| 1579 | return false; |
| 1580 | |
| 1581 | LOCK(cs_main); |
| 1582 | if (m_cached_finished_ibd.load(std::memory_order_relaxed)) |
| 1583 | return false; |
| 1584 | if (fImporting || fReindex) |
| 1585 | return true; |
| 1586 | if (m_chain.Tip() == nullptr) |
| 1587 | return true; |
| 1588 | if (m_chain.Tip()->nChainWork < nMinimumChainWork) |
| 1589 | return true; |
| 1590 | if (m_chain.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge)) |
| 1591 | return true; |
| 1592 | LogPrintf("Leaving InitialBlockDownload (latching to false)\n"); |
| 1593 | m_cached_finished_ibd.store(true, std::memory_order_relaxed); |
| 1594 | return false; |
| 1595 | } |
| 1596 | |
| 1597 | static void AlertNotify(const std::string& strMessage) |
| 1598 | { |
no test coverage detected