Changeset View
Changeset View
Standalone View
Standalone View
src/validation.h
Show First 20 Lines • Show All 836 Lines • ▼ Show 20 Lines | private: | ||||
/** | /** | ||||
* The best finalized block. | * The best finalized block. | ||||
* This block cannot be reorged in any way except by explicit user action. | * This block cannot be reorged in any way except by explicit user action. | ||||
*/ | */ | ||||
const CBlockIndex *m_finalizedBlockIndex GUARDED_BY(cs_main) = nullptr; | const CBlockIndex *m_finalizedBlockIndex GUARDED_BY(cs_main) = nullptr; | ||||
public: | public: | ||||
explicit CChainState(BlockManager &blockman) : m_blockman(blockman) {} | explicit CChainState(BlockManager &blockman, | ||||
explicit CChainState(BlockHash from_snapshot_blockhash = BlockHash()); | BlockHash from_snapshot_blockhash = BlockHash()); | ||||
/** | /** | ||||
* Initialize the CoinsViews UTXO set database management data structures. | * Initialize the CoinsViews UTXO set database management data structures. | ||||
* The in-memory cache is initialized separately. | * The in-memory cache is initialized separately. | ||||
* | * | ||||
* All parameters forwarded to CoinsViews. | * All parameters forwarded to CoinsViews. | ||||
*/ | */ | ||||
void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe, | void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe, | ||||
▲ Show 20 Lines • Show All 289 Lines • ▼ Show 20 Lines | private: | ||||
//! most-work chain. | //! most-work chain. | ||||
CChainState *m_active_chainstate{nullptr}; | CChainState *m_active_chainstate{nullptr}; | ||||
//! If true, the assumed-valid chainstate has been fully validated | //! If true, the assumed-valid chainstate has been fully validated | ||||
//! by the background validation chainstate. | //! by the background validation chainstate. | ||||
bool m_snapshot_validated{false}; | bool m_snapshot_validated{false}; | ||||
// For access to m_active_chainstate. | // For access to m_active_chainstate. | ||||
friend CChainState &ChainstateActive(); | |||||
friend CChain &ChainActive(); | friend CChain &ChainActive(); | ||||
public: | 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 | //! Instantiate a new chainstate and assign it based upon whether it is | ||||
//! from a snapshot. | //! from a snapshot. | ||||
//! | //! | ||||
//! @param[in] snapshot_blockhash If given, signify that this chainstate | //! @param[in] snapshot_blockhash If given, signify that this chainstate | ||||
//! is based on a snapshot. | //! is based on a snapshot. | ||||
CChainState & | CChainState & | ||||
InitializeChainstate(const BlockHash &snapshot_blockhash = BlockHash()) | InitializeChainstate(const BlockHash &snapshot_blockhash = BlockHash()) | ||||
EXCLUSIVE_LOCKS_REQUIRED(::cs_main); | EXCLUSIVE_LOCKS_REQUIRED(::cs_main); | ||||
//! Get all chainstates currently being used. | //! Get all chainstates currently being used. | ||||
std::vector<CChainState *> GetAll(); | std::vector<CChainState *> GetAll(); | ||||
//! The most-work chain. | //! The most-work chain. | ||||
CChain &ActiveChain() const; | CChain &ActiveChain() const; | ||||
int ActiveHeight() const { return ActiveChain().Height(); } | int ActiveHeight() const { return ActiveChain().Height(); } | ||||
CBlockIndex *ActiveTip() const { return ActiveChain().Tip(); } | CBlockIndex *ActiveTip() const { return ActiveChain().Tip(); } | ||||
BlockMap &BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) { | |||||
return m_blockman.m_block_index; | |||||
} | |||||
bool IsSnapshotActive() const; | bool IsSnapshotActive() const; | ||||
std::optional<BlockHash> SnapshotBlockhash() const; | std::optional<BlockHash> SnapshotBlockhash() const; | ||||
//! Is there a snapshot in use and has it been fully validated? | //! Is there a snapshot in use and has it been fully validated? | ||||
bool IsSnapshotValidated() const { return m_snapshot_validated; } | bool IsSnapshotValidated() const { return m_snapshot_validated; } | ||||
//! @returns true if this chainstate is being used to validate an active | //! @returns true if this chainstate is being used to validate an active | ||||
Show All 11 Lines | public: | ||||
//! Unload block index and chain data before shutdown. | //! Unload block index and chain data before shutdown. | ||||
void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); | void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); | ||||
//! Clear (deconstruct) chainstate data. | //! Clear (deconstruct) chainstate data. | ||||
void Reset(); | void Reset(); | ||||
}; | }; | ||||
extern ChainstateManager g_chainman; | |||||
/** @returns the most-work valid chainstate. */ | /** @returns the most-work valid chainstate. */ | ||||
CChainState &ChainstateActive(); | CChainState &ChainstateActive(); | ||||
/** @returns the most-work chain. */ | /** @returns the most-work chain. */ | ||||
CChain &ChainActive(); | CChain &ChainActive(); | ||||
/** @returns the global block index map. */ | /** @returns the global block index map. */ | ||||
BlockMap &BlockIndex(); | 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) | * Global variable that points to the active block tree (protected by cs_main) | ||||
*/ | */ | ||||
extern std::unique_ptr<CBlockTreeDB> pblocktree; | extern std::unique_ptr<CBlockTreeDB> pblocktree; | ||||
/** | /** | ||||
* Return the spend height, which is one more than the inputs.GetBestBlock(). | * Return the spend height, which is one more than the inputs.GetBestBlock(). | ||||
* While checking, GetBestBlock() refers to the parent block. (protected by | * While checking, GetBestBlock() refers to the parent block. (protected by | ||||
Show All 24 Lines |