![]() |
Bitcoin Core
23.99.0
P2P Digital Currency
|
#include <arith_uint256.h>
#include <attributes.h>
#include <chain.h>
#include <chainparams.h>
#include <kernel/chainstatemanager_opts.h>
#include <consensus/amount.h>
#include <deploymentstatus.h>
#include <fs.h>
#include <node/blockstorage.h>
#include <policy/feerate.h>
#include <policy/packages.h>
#include <policy/policy.h>
#include <script/script_error.h>
#include <sync.h>
#include <txdb.h>
#include <txmempool.h>
#include <uint256.h>
#include <util/check.h>
#include <util/hasher.h>
#include <util/translation.h>
#include <versionbits.h>
#include <atomic>
#include <map>
#include <memory>
#include <optional>
#include <set>
#include <stdint.h>
#include <string>
#include <thread>
#include <utility>
#include <vector>
Go to the source code of this file.
Classes | |
struct | MempoolAcceptResult |
Validation result for a single transaction mempool acceptance. More... | |
struct | PackageMempoolAcceptResult |
Validation result for package mempool acceptance. More... | |
class | CScriptCheck |
Closure representing one script verification Note that this stores references to the spending transaction. More... | |
class | CVerifyDB |
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases. More... | |
class | CoinsViews |
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO set. More... | |
class | CChainState |
CChainState stores and provides an API to update our local knowledge of the current best chain. More... | |
class | ChainstateManager |
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate generated by downloading blocks, and an optional snapshot chainstate loaded from a UTXO snapshot. More... | |
Namespaces | |
node | |
Consensus | |
Transaction validation functions. | |
Enumerations | |
enum | SynchronizationState { SynchronizationState::INIT_REINDEX, SynchronizationState::INIT_DOWNLOAD, SynchronizationState::POST_INIT } |
Current sync state passed to tip changed callbacks. More... | |
enum | DisconnectResult { DISCONNECT_OK, DISCONNECT_UNCLEAN, DISCONNECT_FAILED } |
enum | FlushStateMode { FlushStateMode::NONE, FlushStateMode::IF_NEEDED, FlushStateMode::PERIODIC, FlushStateMode::ALWAYS } |
enum | CoinsCacheSizeState { CoinsCacheSizeState::CRITICAL = 2, CoinsCacheSizeState::LARGE = 1, CoinsCacheSizeState::OK = 0 } |
Functions | |
void | StartScriptCheckWorkerThreads (int threads_num) |
Run instances of script checking worker threads. More... | |
void | StopScriptCheckWorkerThreads () |
Stop all of the script checking worker threads. More... | |
CAmount | GetBlockSubsidy (int nHeight, const Consensus::Params &consensusParams) |
bool | AbortNode (BlockValidationState &state, const std::string &strMessage, const bilingual_str &userMessage=bilingual_str{}) |
double | GuessVerificationProgress (const ChainTxData &data, const CBlockIndex *pindex) |
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). More... | |
void | PruneBlockFilesManual (CChainState &active_chainstate, int nManualPruneHeight) |
Prune block files up to a given height. More... | |
MempoolAcceptResult | AcceptToMemoryPool (CChainState &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
Try to add a transaction to the mempool. More... | |
PackageMempoolAcceptResult | ProcessNewPackage (CChainState &active_chainstate, CTxMemPool &pool, const Package &txns, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
Validate (and maybe submit) a package to the mempool. More... | |
bool | InitScriptExecutionCache (size_t max_size_bytes) |
Initializes the script-execution cache. More... | |
bool | CheckBlock (const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW=true, bool fCheckMerkleRoot=true) |
Functions for validating blocks and updating the block tree. More... | |
bool | TestBlockValidity (BlockValidationState &state, const CChainParams &chainparams, CChainState &chainstate, const CBlock &block, CBlockIndex *pindexPrev, const std::function< int64_t()> &adjusted_time_callback, bool fCheckPOW=true, bool fCheckMerkleRoot=true) EXCLUSIVE_LOCKS_REQUIRED(cs_main) |
Check a block is completely valid from start to finish (only works on top of our current best block) More... | |
template<typename DEP > | |
bool | DeploymentActiveAfter (const CBlockIndex *pindexPrev, const ChainstateManager &chainman, DEP dep) |
Deployment* info via ChainstateManager. More... | |
template<typename DEP > | |
bool | DeploymentActiveAt (const CBlockIndex &index, const ChainstateManager &chainman, DEP dep) |
template<typename DEP > | |
bool | DeploymentEnabled (const ChainstateManager &chainman, DEP dep) |
const AssumeutxoData * | ExpectedAssumeutxo (const int height, const CChainParams ¶ms) |
Return the expected assumeutxo value for a given height, if one exists. More... | |
Variables | |
static const int | MAX_SCRIPTCHECK_THREADS = 15 |
Maximum number of dedicated script-checking threads allowed. More... | |
static const int | DEFAULT_SCRIPTCHECK_THREADS = 0 |
-par default (number of script-checking threads, 0 = auto) More... | |
static const int64_t | DEFAULT_MAX_TIP_AGE = 24 * 60 * 60 |
static const bool | DEFAULT_CHECKPOINTS_ENABLED = true |
static const bool | DEFAULT_TXINDEX = false |
static constexpr bool | DEFAULT_COINSTATSINDEX {false} |
static const char *const | DEFAULT_BLOCKFILTERINDEX = "0" |
static const int | DEFAULT_STOPATHEIGHT = 0 |
Default for -stopatheight. More... | |
static const unsigned int | MIN_BLOCKS_TO_KEEP = 288 |
Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ActiveChain().Tip() will not be pruned. More... | |
static const signed int | DEFAULT_CHECKBLOCKS = 6 |
static constexpr int | DEFAULT_CHECKLEVEL {3} |
static const uint64_t | MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024 |
RecursiveMutex | cs_main |
Mutex to guard access to validation specific variables, such as reading or changing the chainstate. More... | |
GlobalMutex | g_best_block_mutex |
std::condition_variable | g_best_block_cv |
uint256 | g_best_block |
Used to notify getblocktemplate RPC of new tips. More... | |
bool | g_parallel_script_checks |
Whether there are dedicated script-checking threads running. More... | |
bool | fCheckBlockIndex |
bool | fCheckpointsEnabled |
int64_t | nMaxTipAge |
If the tip is older than this (in seconds), the node is considered to be in initial block download. More... | |
uint256 | hashAssumeValid |
Block hash whose ancestors we will assume to have valid scripts without checking them. More... | |
arith_uint256 | nMinimumChainWork |
Minimum work we will assume exists on some valid chain. More... | |
const std::vector< std::string > | CHECKLEVEL_DOC |
Documentation for argument 'checklevel'. More... | |
bool CheckFinalTxAtTip(const CBlockIndex *active_chain_tip, const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(boo | CheckSequenceLocksAtTip )(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx, LockPoints *lp=nullptr, bool useExistingLockPoints=false) |
Check if transaction will be final in the next block to be created. More... | |
|
strong |
Enumerator | |
---|---|
CRITICAL | The coins cache is in immediate need of a flush. |
LARGE | The cache is at >= 90% capacity. |
OK |
Definition at line 408 of file validation.h.
enum DisconnectResult |
Enumerator | |
---|---|
DISCONNECT_OK | |
DISCONNECT_UNCLEAN | |
DISCONNECT_FAILED |
Definition at line 356 of file validation.h.
|
strong |
Enumerator | |
---|---|
NONE | |
IF_NEEDED | |
PERIODIC | |
ALWAYS |
Definition at line 366 of file validation.h.
|
strong |
Current sync state passed to tip changed callbacks.
Enumerator | |
---|---|
INIT_REINDEX | |
INIT_DOWNLOAD | |
POST_INIT |
Definition at line 88 of file validation.h.
bool AbortNode | ( | BlockValidationState & | state, |
const std::string & | strMessage, | ||
const bilingual_str & | userMessage = bilingual_str{} |
||
) |
Definition at line 1785 of file validation.cpp.
MempoolAcceptResult AcceptToMemoryPool | ( | CChainState & | active_chainstate, |
const CTransactionRef & | tx, | ||
int64_t | accept_time, | ||
bool | bypass_limits, | ||
bool | test_accept | ||
) |
Try to add a transaction to the mempool.
This is an internal function and is exposed only for testing. Client code should use ChainstateManager::ProcessTransaction()
[in] | active_chainstate | Reference to the active chainstate. |
[in] | tx | The transaction to submit for mempool acceptance. |
[in] | accept_time | The timestamp for adding the transaction to the mempool. It is also used to determine when the entry expires. |
[in] | bypass_limits | When true, don't enforce mempool fee and capacity limits. |
[in] | test_accept | When true, run validation checks but don't submit to mempool. |
Definition at line 1415 of file validation.cpp.
bool CheckBlock | ( | const CBlock & | block, |
BlockValidationState & | state, | ||
const Consensus::Params & | consensusParams, | ||
bool | fCheckPOW = true , |
||
bool | fCheckMerkleRoot = true |
||
) |
Functions for validating blocks and updating the block tree.
Context-independent validity checks
Definition at line 3323 of file validation.cpp.
bool DeploymentActiveAfter | ( | const CBlockIndex * | pindexPrev, |
const ChainstateManager & | chainman, | ||
DEP | dep | ||
) |
Deployment* info via ChainstateManager.
Definition at line 1025 of file validation.h.
bool DeploymentActiveAt | ( | const CBlockIndex & | index, |
const ChainstateManager & | chainman, | ||
DEP | dep | ||
) |
bool DeploymentEnabled | ( | const ChainstateManager & | chainman, |
DEP | dep | ||
) |
const AssumeutxoData* ExpectedAssumeutxo | ( | const int | height, |
const CChainParams & | params | ||
) |
Return the expected assumeutxo value for a given height, if one exists.
[in] | height | Get the assumeutxo value for this height. |
Definition at line 4725 of file validation.cpp.
CAmount GetBlockSubsidy | ( | int | nHeight, |
const Consensus::Params & | consensusParams | ||
) |
double GuessVerificationProgress | ( | const ChainTxData & | data, |
const CBlockIndex * | pindex | ||
) |
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
Definition at line 4658 of file validation.cpp.
bool InitScriptExecutionCache | ( | size_t | max_size_bytes | ) |
Initializes the script-execution cache.
Definition at line 1659 of file validation.cpp.
PackageMempoolAcceptResult ProcessNewPackage | ( | CChainState & | active_chainstate, |
CTxMemPool & | pool, | ||
const Package & | txns, | ||
bool | test_accept | ||
) |
Validate (and maybe submit) a package to the mempool.
See doc/policy/packages.md for full details on package validation rules.
[in] | test_accept | When true, run validation checks but don't submit to mempool. |
Definition at line 1442 of file validation.cpp.
void PruneBlockFilesManual | ( | CChainState & | active_chainstate, |
int | nManualPruneHeight | ||
) |
Prune block files up to a given height.
Definition at line 3864 of file validation.cpp.
void StartScriptCheckWorkerThreads | ( | int | threads_num | ) |
Run instances of script checking worker threads.
Definition at line 1889 of file validation.cpp.
void StopScriptCheckWorkerThreads | ( | ) |
Stop all of the script checking worker threads.
Definition at line 1894 of file validation.cpp.
bool TestBlockValidity | ( | BlockValidationState & | state, |
const CChainParams & | chainparams, | ||
CChainState & | chainstate, | ||
const CBlock & | block, | ||
CBlockIndex * | pindexPrev, | ||
const std::function< int64_t()> & | adjusted_time_callback, | ||
bool | fCheckPOW = true , |
||
bool | fCheckMerkleRoot = true |
||
) |
Check a block is completely valid from start to finish (only works on top of our current best block)
Definition at line 3830 of file validation.cpp.
const std::vector<std::string> CHECKLEVEL_DOC |
Documentation for argument 'checklevel'.
Definition at line 96 of file validation.cpp.
bool CheckFinalTxAtTip (const CBlockIndex* active_chain_tip, const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED( boo CheckSequenceLocksAtTip) (CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx, LockPoints *lp=nullptr, bool useExistingLockPoints=false) |
Check if transaction will be final in the next block to be created.
Check if transaction will be BIP68 final in the next block to be created on top of tip.
[in] | tip | Chain tip to check tx sequence locks against. For example, the tip of the current active chain. |
[in] | coins_view | Any CCoinsView that provides access to the relevant coins for checking sequence locks. For example, it can be a CCoinsViewCache that isn't connected to anything but contains all the relevant coins, or a CCoinsViewMemPool that is connected to the mempool and chainstate UTXO set. In the latter case, the caller is responsible for holding the appropriate locks to ensure that calls to GetCoin() return correct coins. Simulates calling SequenceLocks() with data from the tip passed in. Optionally stores in LockPoints the resulting height and time calculated and the hash of the block needed for calculation or skips the calculation and uses the LockPoints passed in for evaluation. The LockPoints should not be considered valid if CheckSequenceLocksAtTip returns false. |
Definition at line 283 of file validation.h.
RecursiveMutex cs_main |
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
This may also need to be locked when updating the transaction pool, e.g. on AcceptToMemoryPool. See CTxMemPool::cs comment for details.
The transaction pool has a separate lock to allow reading from it and the chainstate at the same time.
Definition at line 121 of file validation.cpp.
|
static |
Definition at line 70 of file validation.h.
|
static |
Definition at line 75 of file validation.h.
|
staticconstexpr |
Definition at line 76 of file validation.h.
|
static |
Definition at line 67 of file validation.h.
|
staticconstexpr |
Definition at line 69 of file validation.h.
|
static |
Definition at line 66 of file validation.h.
|
static |
-par default (number of script-checking threads, 0 = auto)
Definition at line 65 of file validation.h.
|
static |
Default for -stopatheight.
Definition at line 72 of file validation.h.
|
static |
Definition at line 68 of file validation.h.
bool fCheckBlockIndex |
Definition at line 127 of file validation.cpp.
bool fCheckpointsEnabled |
Definition at line 128 of file validation.cpp.
uint256 g_best_block |
Used to notify getblocktemplate RPC of new tips.
Definition at line 125 of file validation.cpp.
std::condition_variable g_best_block_cv |
Definition at line 124 of file validation.cpp.
GlobalMutex g_best_block_mutex |
Definition at line 123 of file validation.cpp.
bool g_parallel_script_checks |
Whether there are dedicated script-checking threads running.
False indicates all script checking is done on the main threadMessageHandler thread.
Definition at line 126 of file validation.cpp.
uint256 hashAssumeValid |
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition at line 131 of file validation.cpp.
|
static |
Maximum number of dedicated script-checking threads allowed.
Definition at line 63 of file validation.h.
|
static |
Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ActiveChain().Tip() will not be pruned.
Definition at line 74 of file validation.h.
|
static |
Definition at line 85 of file validation.h.
int64_t nMaxTipAge |
If the tip is older than this (in seconds), the node is considered to be in initial block download.
Definition at line 129 of file validation.cpp.
arith_uint256 nMinimumChainWork |
Minimum work we will assume exists on some valid chain.
Definition at line 132 of file validation.cpp.