Changeset View
Changeset View
Standalone View
Standalone View
src/validation.h
Show First 20 Lines • Show All 285 Lines • ▼ Show 20 Lines | explicit PackageMempoolAcceptResult(const TxId &txid, | ||||
: m_tx_results{{txid, result}} {} | : m_tx_results{{txid, result}} {} | ||||
}; | }; | ||||
/** | /** | ||||
* Try to add a transaction to the mempool. This is an internal function and is | * Try to add a transaction to the mempool. This is an internal function and is | ||||
* exposed only for testing. Client code should use | * exposed only for testing. Client code should use | ||||
* ChainstateManager::ProcessTransaction() | * ChainstateManager::ProcessTransaction() | ||||
* | * | ||||
* @param[in] config The global configuration. | |||||
* @param[in] active_chainstate Reference to the active chainstate. | * @param[in] active_chainstate Reference to the active chainstate. | ||||
* @param[in] tx The transaction to submit for mempool | * @param[in] tx The transaction to submit for mempool | ||||
* acceptance. | * acceptance. | ||||
* @param[in] accept_time The timestamp for adding the transaction to | * @param[in] accept_time The timestamp for adding the transaction to | ||||
* the mempool. | * the mempool. | ||||
* It is also used to determine when the entry | * It is also used to determine when the entry | ||||
* expires. | * expires. | ||||
* @param[in] bypass_limits When true, don't enforce mempool fee and | * @param[in] bypass_limits When true, don't enforce mempool fee and | ||||
* capacity limits. | * capacity limits. | ||||
* @param[in] test_accept When true, run validation checks but don't | * @param[in] test_accept When true, run validation checks but don't | ||||
* submit to mempool. | * submit to mempool. | ||||
* @param[in] heightOverride Override the block height of the transaction. | * @param[in] heightOverride Override the block height of the transaction. | ||||
* Used only upon reorg. | * Used only upon reorg. | ||||
* | * | ||||
* @returns a MempoolAcceptResult indicating whether the transaction was | * @returns a MempoolAcceptResult indicating whether the transaction was | ||||
* accepted/rejected with reason. | * accepted/rejected with reason. | ||||
*/ | */ | ||||
MempoolAcceptResult | MempoolAcceptResult | ||||
AcceptToMemoryPool(const Config &config, Chainstate &active_chainstate, | AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, | ||||
const CTransactionRef &tx, int64_t accept_time, | int64_t accept_time, bool bypass_limits, | ||||
bool bypass_limits, bool test_accept = false, | bool test_accept = false, unsigned int heightOverride = 0) | ||||
unsigned int heightOverride = 0) | |||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
/** | /** | ||||
* Validate (and maybe submit) a package to the mempool. | * Validate (and maybe submit) a package to the mempool. | ||||
* See doc/policy/packages.md for full detailson package validation rules. | * See doc/policy/packages.md for full detailson package validation rules. | ||||
* | * | ||||
* @param[in] test_accept When true, run validation checks but don't | * @param[in] test_accept When true, run validation checks but don't | ||||
* submit to mempool. | * submit to mempool. | ||||
* @returns a PackageMempoolAcceptResult which includes a MempoolAcceptResult | * @returns a PackageMempoolAcceptResult which includes a MempoolAcceptResult | ||||
* for each transaction. If a transaction fails, validation will exit early | * for each transaction. If a transaction fails, validation will exit early | ||||
* and some results may be missing. It is also possible for the package to | * and some results may be missing. It is also possible for the package to | ||||
* be partially submitted. | * be partially submitted. | ||||
*/ | */ | ||||
PackageMempoolAcceptResult | PackageMempoolAcceptResult | ||||
ProcessNewPackage(const Config &config, Chainstate &active_chainstate, | ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, | ||||
CTxMemPool &pool, const Package &txns, bool test_accept) | const Package &txns, bool test_accept) | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main); | EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
/** | /** | ||||
* Simple class for regulating resource usage during CheckInputScripts (and | * Simple class for regulating resource usage during CheckInputScripts (and | ||||
* CScriptCheck), atomic so as to be compatible with parallel validation. | * CScriptCheck), atomic so as to be compatible with parallel validation. | ||||
*/ | */ | ||||
class CheckInputsLimiter { | class CheckInputsLimiter { | ||||
protected: | protected: | ||||
▲ Show 20 Lines • Show All 555 Lines • ▼ Show 20 Lines | public: | ||||
* Note that if this is called while a snapshot chainstate is active, and if | * Note that if this is called while a snapshot chainstate is active, and if | ||||
* it is called on a background chainstate whose tip has reached the base | * it is called on a background chainstate whose tip has reached the base | ||||
* block of the snapshot, its execution will take *MINUTES* while it hashes | * block of the snapshot, its execution will take *MINUTES* while it hashes | ||||
* the background UTXO set to verify the assumeutxo value the snapshot was | * the background UTXO set to verify the assumeutxo value the snapshot was | ||||
* activated with. `cs_main` will be held during this time. | * activated with. `cs_main` will be held during this time. | ||||
* | * | ||||
* @returns true unless a system error occurred | * @returns true unless a system error occurred | ||||
*/ | */ | ||||
bool ActivateBestChain(const Config &config, BlockValidationState &state, | bool ActivateBestChain(BlockValidationState &state, | ||||
std::shared_ptr<const CBlock> pblock = nullptr) | std::shared_ptr<const CBlock> pblock = nullptr) | ||||
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, | EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, | ||||
!cs_avalancheFinalizedBlockIndex) | !cs_avalancheFinalizedBlockIndex) | ||||
LOCKS_EXCLUDED(cs_main); | LOCKS_EXCLUDED(cs_main); | ||||
bool AcceptBlock(const Config &config, | bool AcceptBlock(const Config &config, | ||||
const std::shared_ptr<const CBlock> &pblock, | const std::shared_ptr<const CBlock> &pblock, | ||||
BlockValidationState &state, bool fRequested, | BlockValidationState &state, bool fRequested, | ||||
Show All 17 Lines | bool DisconnectTip(BlockValidationState &state, | ||||
EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs); | EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs); | ||||
// Manual block validity manipulation: | // Manual block validity manipulation: | ||||
/** | /** | ||||
* Mark a block as precious and reorganize. | * Mark a block as precious and reorganize. | ||||
* | * | ||||
* May not be called in a validationinterface callback. | * May not be called in a validationinterface callback. | ||||
*/ | */ | ||||
bool PreciousBlock(const Config &config, BlockValidationState &state, | bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex) | ||||
CBlockIndex *pindex) | |||||
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, | EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, | ||||
!cs_avalancheFinalizedBlockIndex) | !cs_avalancheFinalizedBlockIndex) | ||||
LOCKS_EXCLUDED(cs_main); | 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) LOCKS_EXCLUDED(cs_main) | CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main) | ||||
EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, | EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex, | ||||
!cs_avalancheFinalizedBlockIndex); | !cs_avalancheFinalizedBlockIndex); | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | public: | ||||
* | * | ||||
* By default this only executes fully when using the Regtest chain; see: | * By default this only executes fully when using the Regtest chain; see: | ||||
* fCheckBlockIndex. | * fCheckBlockIndex. | ||||
*/ | */ | ||||
void CheckBlockIndex(); | void CheckBlockIndex(); | ||||
/** Load the persisted mempool from disk */ | /** Load the persisted mempool from disk */ | ||||
void | void | ||||
LoadMempool(const Config &config, const fs::path &load_path, | LoadMempool(const fs::path &load_path, | ||||
fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen); | fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen); | ||||
/** Update the chain tip based on database information, i.e. CoinsTip()'s | /** Update the chain tip based on database information, i.e. CoinsTip()'s | ||||
* best block. */ | * best block. */ | ||||
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main); | bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main); | ||||
//! Dictates whether we need to flush the cache to disk or not. | //! Dictates whether we need to flush the cache to disk or not. | ||||
//! | //! | ||||
Show All 10 Lines | public: | ||||
//! Indirection necessary to make lock annotations work with an optional | //! Indirection necessary to make lock annotations work with an optional | ||||
//! mempool. | //! mempool. | ||||
RecursiveMutex *MempoolMutex() const LOCK_RETURNED(m_mempool->cs) { | RecursiveMutex *MempoolMutex() const LOCK_RETURNED(m_mempool->cs) { | ||||
return m_mempool ? &m_mempool->cs : nullptr; | return m_mempool ? &m_mempool->cs : nullptr; | ||||
} | } | ||||
private: | private: | ||||
bool ActivateBestChainStep(const Config &config, | bool ActivateBestChainStep(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, m_mempool->cs, | EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs, | ||||
!cs_avalancheFinalizedBlockIndex); | !cs_avalancheFinalizedBlockIndex); | ||||
bool ConnectTip(const Config &config, BlockValidationState &state, | bool ConnectTip(BlockValidationState &state, | ||||
BlockPolicyValidationState &blockPolicyState, | BlockPolicyValidationState &blockPolicyState, | ||||
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, m_mempool->cs, | EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs, | ||||
!cs_avalancheFinalizedBlockIndex); | !cs_avalancheFinalizedBlockIndex); | ||||
void InvalidBlockFound(CBlockIndex *pindex, | void InvalidBlockFound(CBlockIndex *pindex, | ||||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Lines | |||||
public: | public: | ||||
using Options = kernel::ChainstateManagerOpts; | using Options = kernel::ChainstateManagerOpts; | ||||
explicit ChainstateManager(Options options) | explicit ChainstateManager(Options options) | ||||
: m_options{std::move(options)} { | : m_options{std::move(options)} { | ||||
Assert(m_options.adjusted_time_callback); | Assert(m_options.adjusted_time_callback); | ||||
} | } | ||||
const Config &GetConfig() const { return m_options.config; } | |||||
const CChainParams &GetParams() const { | const CChainParams &GetParams() const { | ||||
return m_options.config.GetChainParams(); | return m_options.config.GetChainParams(); | ||||
} | } | ||||
const Consensus::Params &GetConsensus() const { | const Consensus::Params &GetConsensus() const { | ||||
return m_options.config.GetChainParams().GetConsensus(); | return m_options.config.GetChainParams().GetConsensus(); | ||||
} | } | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 244 Lines • Show Last 20 Lines |