diff options
author | James O'Beirne <james.obeirne@gmail.com> | 2019-12-12 10:48:28 -0500 |
---|---|---|
committer | James O'Beirne <james.obeirne@pm.me> | 2020-03-17 14:03:40 -0400 |
commit | 4ae29f5f0c5117032debb722d7049664fdceeae8 (patch) | |
tree | 48432a68a7fc218f88aa8dc3eaa6e7abef4477b6 /src/validation.h | |
parent | 5b690f0aae21e7d46cbefe3f5be645842ac4ae3b (diff) |
use ChainstateManager to initialize chainstate
This allows us to easily initialize multiple chainstates on startup in future
commits. It retires the g_chainstate global in lieu of g_chainman.
Diffstat (limited to 'src/validation.h')
-rw-r--r-- | src/validation.h | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/src/validation.h b/src/validation.h index 3b160ac799..901f6d22bd 100644 --- a/src/validation.h +++ b/src/validation.h @@ -592,8 +592,7 @@ private: std::unique_ptr<CoinsViews> m_coins_views; public: - explicit CChainState(BlockManager& blockman) : m_blockman(blockman) {} - explicit CChainState(uint256 from_snapshot_blockhash = uint256()); + explicit CChainState(BlockManager& blockman, uint256 from_snapshot_blockhash = uint256()); /** * Initialize the CoinsViews UTXO set database management data structures. The in-memory @@ -839,9 +838,14 @@ private: bool m_snapshot_validated{false}; // For access to m_active_chainstate. + friend CChainState& ChainstateActive(); friend CChain& ChainActive(); public: + //! A single BlockManager instance is shared across each constructed + //! chainstate to avoid duplicating block metadata. + BlockManager m_blockman GUARDED_BY(::cs_main); + //! Instantiate a new chainstate and assign it based upon whether it is //! from a snapshot. //! @@ -858,6 +862,11 @@ public: int ActiveHeight() const { return ActiveChain().Height(); } CBlockIndex* ActiveTip() const { return ActiveChain().Tip(); } + BlockMap& BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) + { + return m_blockman.m_block_index; + } + bool IsSnapshotActive() const; Optional<uint256> SnapshotBlockhash() const; @@ -885,6 +894,8 @@ public: void Reset(); }; +extern ChainstateManager g_chainman; + /** @returns the most-work valid chainstate. */ CChainState& ChainstateActive(); @@ -894,11 +905,6 @@ CChain& ChainActive(); /** @returns the global block index map. */ BlockMap& BlockIndex(); -// Most often ::ChainstateActive() should be used instead of this, but some code -// may not be able to assume that this has been initialized yet and so must use it -// directly, e.g. init.cpp. -extern std::unique_ptr<CChainState> g_chainstate; - /** Global variable that points to the active block tree (protected by cs_main) */ extern std::unique_ptr<CBlockTreeDB> pblocktree; |