From 403e677c9ebbf9744733010e6b0c2d1b182ee850 Mon Sep 17 00:00:00 2001 From: James O'Beirne Date: Wed, 27 Mar 2019 12:21:50 -0400 Subject: refactoring: IsInitialBlockDownload -> CChainState We introduce CChainState.m_cached_finished_ibd because the static state it replaces would've been shared across all CChainState instances. --- src/validation.h | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'src/validation.h') diff --git a/src/validation.h b/src/validation.h index 3eece8d2b9..d4c368a99c 100644 --- a/src/validation.h +++ b/src/validation.h @@ -249,8 +249,6 @@ bool LoadChainTip(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_m void UnloadBlockIndex(); /** Run an instance of the script checking thread */ void ThreadScriptCheck(int worker_num); -/** Check whether we are doing an initial block download (synchronizing from disk or network) */ -bool IsInitialBlockDownload(); /** Retrieve a transaction (from memory pool, or from disk, if possible) */ bool GetTransaction(const uint256& hash, CTransactionRef& tx, const Consensus::Params& params, uint256& hashBlock, const CBlockIndex* const blockIndex = nullptr); /** @@ -503,6 +501,14 @@ private: */ CCriticalSection m_cs_chainstate; + /** + * Whether this chainstate is undergoing initial block download. + * + * Mutable because we need to be able to mark IsInitialBlockDownload() + * const, which latches this for caching purposes. + */ + mutable std::atomic m_cached_finished_ibd{false}; + public: //! The current chain of blockheaders we consult and build on. //! @see CChain, CBlockIndex. @@ -565,6 +571,9 @@ public: void UnloadBlockIndex(); + /** Check whether we are doing an initial block download (synchronizing from disk or network) */ + bool IsInitialBlockDownload() const; + private: bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main); bool ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions &disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main); -- cgit v1.2.3