diff options
author | Ryan Ofsky <ryan@ofsky.org> | 2023-08-04 16:43:39 -0400 |
---|---|---|
committer | Ryan Ofsky <ryan@ofsky.org> | 2023-08-18 12:52:30 -0400 |
commit | 94a98fbd1d14a4ea10629b917771d50f3191e944 (patch) | |
tree | e6347c9765e91c3e6d7318905262fb1e2088fbfb /src/validation.h | |
parent | 9b066da8af77f971046a42118fd65046321bed1b (diff) | |
download | bitcoin-94a98fbd1d14a4ea10629b917771d50f3191e944.tar.xz |
assumeutxo cleanup: Move IsInitialBlockDownload & NotifyHeaderTip to ChainstateManager
This change makes IsInitialBlockDownload and NotifyHeaderTip functions no
longer tied to individual Chainstate objects. It makes them work with the
ChainstateManager object instead so code is simpler and it is no longer
possible to call them incorrectly with an inactive Chainstate.
This change also makes m_cached_finished_ibd caching easier to reason about,
because now there is only one cached value instead of two (for background and
snapshot chainstates) so the cached IBD state now no longer gets reset when a
snapshot is loaded.
There should be no change in behavior because these functions were always
called on the active ChainState objects.
These changes were discussed previously
https://github.com/bitcoin/bitcoin/pull/27746#discussion_r1246868905 and
https://github.com/bitcoin/bitcoin/pull/27746#discussion_r1237552792 as
possible followups for that PR.
Diffstat (limited to 'src/validation.h')
-rw-r--r-- | src/validation.h | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/src/validation.h b/src/validation.h index e4980c51a7..ba427afc64 100644 --- a/src/validation.h +++ b/src/validation.h @@ -473,14 +473,6 @@ protected: */ Mutex m_chainstate_mutex; - /** - * 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<bool> m_cached_finished_ibd{false}; - //! Optional mempool that is kept in sync with the chain. //! Only the active chainstate has a mempool. CTxMemPool* m_mempool; @@ -707,9 +699,6 @@ public: void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); - /** Check whether we are doing an initial block download (synchronizing from disk or network) */ - bool IsInitialBlockDownload() const; - /** Find the last common block of this chain and a locator. */ const CBlockIndex* FindForkInGlobalIndex(const CBlockLocator& locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main); @@ -952,6 +941,15 @@ public: node::BlockManager m_blockman; /** + * Whether initial block download has ended and IsInitialBlockDownload + * should return false from now on. + * + * Mutable because we need to be able to mark IsInitialBlockDownload() + * const, which latches this for caching purposes. + */ + mutable std::atomic<bool> m_cached_finished_ibd{false}; + + /** * Every received block is assigned a unique and increasing identifier, so we * know which one to give priority in case of a fork. */ @@ -1067,6 +1065,9 @@ public: return m_snapshot_chainstate && m_ibd_chainstate && m_ibd_chainstate->m_disabled; } + /** Check whether we are doing an initial block download (synchronizing from disk or network) */ + bool IsInitialBlockDownload() const; + /** * Import blocks from an external file * |