Changeset View
Changeset View
Standalone View
Standalone View
src/validation.h
Show First 20 Lines • Show All 713 Lines • ▼ Show 20 Lines | private: | ||||
*/ | */ | ||||
mutable std::atomic<bool> m_cached_finished_ibd{false}; | mutable std::atomic<bool> m_cached_finished_ibd{false}; | ||||
//! Reference to a BlockManager instance which itself is shared across all | //! Reference to a BlockManager instance which itself is shared across all | ||||
//! CChainState instances. Keeping a local reference allows us to test more | //! CChainState instances. Keeping a local reference allows us to test more | ||||
//! easily as opposed to referencing a global. | //! easily as opposed to referencing a global. | ||||
BlockManager &m_blockman; | BlockManager &m_blockman; | ||||
//! mempool that is kept in sync with the chain | |||||
CTxMemPool &m_mempool; | |||||
//! Manages the UTXO set, which is a reflection of the contents of | //! Manages the UTXO set, which is a reflection of the contents of | ||||
//! `m_chain`. | //! `m_chain`. | ||||
std::unique_ptr<CoinsViews> m_coins_views; | std::unique_ptr<CoinsViews> m_coins_views; | ||||
/** | /** | ||||
* 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, | explicit CChainState(CTxMemPool &mempool, BlockManager &blockman, | ||||
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. | ||||
*/ | */ | ||||
▲ Show 20 Lines • Show All 117 Lines • ▼ Show 20 Lines | bool ConnectBlock(const CBlock &block, BlockValidationState &state, | ||||
CBlockIndex *pindex, CCoinsViewCache &view, | CBlockIndex *pindex, CCoinsViewCache &view, | ||||
const CChainParams ¶ms, | const CChainParams ¶ms, | ||||
BlockValidationOptions options, bool fJustCheck = false) | BlockValidationOptions options, bool fJustCheck = false) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
// Block disconnection on our pcoinsTip: | // Block disconnection on our pcoinsTip: | ||||
bool DisconnectTip(const CChainParams ¶ms, BlockValidationState &state, | bool DisconnectTip(const CChainParams ¶ms, BlockValidationState &state, | ||||
DisconnectedBlockTransactions *disconnectpool) | DisconnectedBlockTransactions *disconnectpool) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::g_mempool.cs); | EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool.cs); | ||||
// Manual block validity manipulation: | // Manual block validity manipulation: | ||||
bool PreciousBlock(const Config &config, BlockValidationState &state, | bool PreciousBlock(const Config &config, BlockValidationState &state, | ||||
CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main); | CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main); | ||||
/** Mark a block as invalid. */ | /** Mark a block as invalid. */ | ||||
bool InvalidateBlock(const Config &config, BlockValidationState &state, | bool InvalidateBlock(const Config &config, BlockValidationState &state, | ||||
CBlockIndex *pindex) | CBlockIndex *pindex) | ||||
LOCKS_EXCLUDED(cs_main, m_cs_chainstate); | LOCKS_EXCLUDED(cs_main, m_cs_chainstate); | ||||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Lines | public: | ||||
std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); | std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(::cs_main); | ||||
private: | private: | ||||
bool ActivateBestChainStep(const Config &config, | bool ActivateBestChainStep(const Config &config, | ||||
BlockValidationState &state, | BlockValidationState &state, | ||||
CBlockIndex *pindexMostWork, | CBlockIndex *pindexMostWork, | ||||
const std::shared_ptr<const CBlock> &pblock, | const std::shared_ptr<const CBlock> &pblock, | ||||
bool &fInvalidFound, ConnectTrace &connectTrace) | bool &fInvalidFound, ConnectTrace &connectTrace) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::g_mempool.cs); | EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool.cs); | ||||
bool ConnectTip(const Config &config, BlockValidationState &state, | bool ConnectTip(const Config &config, BlockValidationState &state, | ||||
CBlockIndex *pindexNew, | CBlockIndex *pindexNew, | ||||
const std::shared_ptr<const CBlock> &pblock, | const std::shared_ptr<const CBlock> &pblock, | ||||
ConnectTrace &connectTrace, | ConnectTrace &connectTrace, | ||||
DisconnectedBlockTransactions &disconnectpool) | DisconnectedBlockTransactions &disconnectpool) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::g_mempool.cs); | EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool.cs); | ||||
void InvalidBlockFound(CBlockIndex *pindex, | void InvalidBlockFound(CBlockIndex *pindex, | ||||
const BlockValidationState &state) | const BlockValidationState &state) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
void InvalidChainFound(CBlockIndex *pindexNew) | void InvalidChainFound(CBlockIndex *pindexNew) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
CBlockIndex *FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main); | CBlockIndex *FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
bool MarkBlockAsFinal(BlockValidationState &state, | bool MarkBlockAsFinal(BlockValidationState &state, | ||||
const CBlockIndex *pindex) | const CBlockIndex *pindex) | ||||
▲ Show 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | public: | ||||
// | // | ||||
//! The total number of bytes available for us to use across all leveldb | //! The total number of bytes available for us to use across all leveldb | ||||
//! coins databases. This will be split somehow across chainstates. | //! coins databases. This will be split somehow across chainstates. | ||||
int64_t m_total_coinsdb_cache{0}; | int64_t m_total_coinsdb_cache{0}; | ||||
//! 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] mempool The mempool to pass to the chainstate | |||||
// constructor | |||||
//! @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(CTxMemPool &mempool, | ||||
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. | ||||
CChainState &ActiveChainstate() const; | CChainState &ActiveChainstate() const; | ||||
CChain &ActiveChain() const { return ActiveChainstate().m_chain; } | CChain &ActiveChain() const { return ActiveChainstate().m_chain; } | ||||
▲ Show 20 Lines • Show All 139 Lines • Show Last 20 Lines |