mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-05 03:18:50 +02:00
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.
This commit is contained in:
committed by
James O'Beirne
parent
5b690f0aae
commit
4ae29f5f0c
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user