src/validation.cpp
// 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.
//
Note that though this is marked const, we may end up modifying `m_cached_finished_ibd`, which
is a performance-related implementation detail.
Note that though this is marked const we may end up modifying ` m_cached_finished_ibd ` which is a performance - related implementation detail .
bool CChainState::IsInitialBlockDownload() const
{
    static bool fForceInitialBlocksDownloadMode = gArgs.GetBoolArg("-forceinitialblocksdownloadmode", DEFAULT_FORCE_INITIAL_BLOCKS_DOWNLOAD_MODE);
    if(fForceInitialBlocksDownloadMode)
        return true;
    if (m_cached_finished_ibd.load(std::memory_order_relaxed))
        return false;
    static bool check_peer_height = gArgs.GetBoolArg("-checkpeerheight", true);
    LOCK(cs_main);
    if (m_cached_finished_ibd.load(std::memory_order_relaxed))
        return false;
    if (fImporting || fReindex)
        return true;
    if (m_chain.Tip() == nullptr)
        return true;
    if (m_chain.Tip()->nChainWork < nMinimumChainWork)
        return true;
    if (m_chain.Tip()->nHeight > COINBASE_MATURITY
        && m_chain.Tip()->GetBlockTime() < (GetTime() - nMaxTipAge))
        return true;
    if (fParticlMode && check_peer_height
        && (GetNumPeers() < 1
            || m_chain.Tip()->nHeight < GetNumBlocksOfPeers()-10))
        return true;
    LogPrintf("Leaving InitialBlockDownload (latching to false)\n");
    m_cached_finished_ibd.store(true, std::memory_order_relaxed);
    return false;
}
bool CChainState :: IsInitialBlockDownload ( ) const { static bool fForceInitialBlocksDownloadMode = gArgs . GetBoolArg ( " " , DEFAULT_FORCE_INITIAL_BLOCKS_DOWNLOAD_MODE ) ; if ( fForceInitialBlocksDownloadMode ) return true ; if ( m_cached_finished_ibd . load ( std :: memory_order_relaxed ) ) return false ; static bool check_peer_height = gArgs . GetBoolArg ( " " , true ) ; LOCK ( cs_main ) ; if ( m_cached_finished_ibd . load ( std :: memory_order_relaxed ) ) return false ; if ( fImporting || fReindex ) return true ; if ( m_chain . Tip ( ) == nullptr ) return true ; if ( m_chain . Tip ( ) -> nChainWork < nMinimumChainWork ) return true ; if ( m_chain . Tip ( ) -> nHeight > COINBASE_MATURITY && m_chain . Tip ( ) -> GetBlockTime ( ) < ( GetTime ( ) - nMaxTipAge ) ) return true ; if ( fParticlMode && check_peer_height && ( GetNumPeers ( ) < 1 || m_chain . Tip ( ) -> nHeight < GetNumBlocksOfPeers ( ) - 10 ) ) return true ; LogPrintf ( " \n " ) ; m_cached_finished_ibd . store ( true , std :: memory_order_relaxed ) ; return false ; }
Note that though this is marked const, we may end up modifying `m_cached_finished_ibd`, which
is a performance-related implementation detail.
Note that though this is marked const we may end up modifying ` m_cached_finished_ibd ` which is a performance - related implementation detail .
// Optimization: pre-test latch before taking the lock.