Bitcoin Core  0.19.99
P2P Digital Currency
Classes | Typedefs | Enumerations | Functions | Variables
validation.h File Reference
#include <amount.h>
#include <coins.h>
#include <crypto/common.h>
#include <fs.h>
#include <policy/feerate.h>
#include <protocol.h>
#include <script/script_error.h>
#include <sync.h>
#include <txmempool.h>
#include <txdb.h>
#include <versionbits.h>
#include <serialize.h>
#include <atomic>
#include <map>
#include <memory>
#include <set>
#include <stdint.h>
#include <utility>
#include <vector>
Include dependency graph for validation.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  BlockHasher
 
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...
 
struct  CBlockIndexWorkComparator
 
class  BlockManager
 Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-work tip is. 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...
 

Typedefs

typedef std::unordered_map< uint256, CBlockIndex *, BlockHasherBlockMap
 

Enumerations

enum  DisconnectResult { DISCONNECT_OK, DISCONNECT_UNCLEAN, DISCONNECT_FAILED }
 
enum  FlushStateMode { FlushStateMode::NONE, FlushStateMode::IF_NEEDED, FlushStateMode::PERIODIC, FlushStateMode::ALWAYS }
 

Functions

bool ProcessNewBlock (const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock) LOCKS_EXCLUDED(cs_main)
 Process an incoming block. More...
 
bool ProcessNewBlockHeaders (const std::vector< CBlockHeader > &block, BlockValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=nullptr) LOCKS_EXCLUDED(cs_main)
 Process incoming block headers. More...
 
FILE * OpenBlockFile (const FlatFilePos &pos, bool fReadOnly=false)
 Open a block file (blk?????.dat) More...
 
fs::path GetBlockPosFilename (const FlatFilePos &pos)
 Translation to a filesystem path. More...
 
bool LoadExternalBlockFile (const CChainParams &chainparams, FILE *fileIn, FlatFilePos *dbp=nullptr)
 Import blocks from an external file. More...
 
bool LoadGenesisBlock (const CChainParams &chainparams)
 Ensures we have a genesis block in the block tree, possibly writing one to disk. More...
 
bool LoadBlockIndex (const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Load the block tree and coins database from disk, initializing state if we're running with -reindex. More...
 
void UnloadBlockIndex ()
 Unload database information. More...
 
void ThreadScriptCheck (int worker_num)
 Run an instance of the script checking thread. More...
 
bool GetTransaction (const uint256 &hash, CTransactionRef &tx, const Consensus::Params &params, uint256 &hashBlock, const CBlockIndex *const blockIndex=nullptr)
 Retrieve a transaction (from memory pool, or from disk, if possible) More...
 
bool ActivateBestChain (BlockValidationState &state, const CChainParams &chainparams, std::shared_ptr< const CBlock > pblock=std::shared_ptr< const CBlock >())
 Find the best known block, and make it the tip of the block chain. More...
 
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). More...
 
uint64_t CalculateCurrentUsage ()
 Calculate the amount of disk space the block & undo files currently use. More...
 
void PruneOneBlockFile (const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Mark one block file as pruned. More...
 
void UnlinkPrunedFiles (const std::set< int > &setFilesToPrune)
 Actually unlink the specified files. More...
 
void PruneBlockFilesManual (int nManualPruneHeight)
 Prune block files up to a given height. More...
 
bool AcceptToMemoryPool (CTxMemPool &pool, TxValidationState &state, const CTransactionRef &tx, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 (try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions replaced from mempool More...
 
ThresholdState VersionBitsTipState (const Consensus::Params &params, Consensus::DeploymentPos pos)
 Get the BIP9 state for a given deployment at the current tip. More...
 
BIP9Stats VersionBitsTipStatistics (const Consensus::Params &params, Consensus::DeploymentPos pos)
 Get the numerical statistics for the BIP9 state for a given deployment at the current tip. More...
 
int VersionBitsTipStateSinceHeight (const Consensus::Params &params, Consensus::DeploymentPos pos)
 Get the block height at which the BIP9 deployment switched into the state for the block building on the current tip. More...
 
void UpdateCoins (const CTransaction &tx, CCoinsViewCache &inputs, int nHeight)
 Apply the effects of this transaction on the UTXO set represented by view. More...
 
bool CheckFinalTx (const CTransaction &tx, int flags=-1) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Transaction validation functions. More...
 
bool TestLockPointValidity (const LockPoints *lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Test whether the LockPoints height and time are still valid on the current chain. More...
 
bool CheckSequenceLocks (const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp=nullptr, bool useExistingLockPoints=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Check if transaction will be BIP 68 final in the next block to be created. More...
 
void InitScriptExecutionCache ()
 Initializes the script-execution cache. More...
 
bool ReadBlockFromDisk (CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
 Functions for disk access for blocks. More...
 
bool ReadBlockFromDisk (CBlock &block, const CBlockIndex *pindex, const Consensus::Params &consensusParams)
 
bool ReadRawBlockFromDisk (std::vector< uint8_t > &block, const FlatFilePos &pos, const CMessageHeader::MessageStartChars &message_start)
 
bool ReadRawBlockFromDisk (std::vector< uint8_t > &block, const CBlockIndex *pindex, const CMessageHeader::MessageStartChars &message_start)
 
bool UndoReadFromDisk (CBlockUndo &blockundo, const CBlockIndex *pindex)
 
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, const CBlock &block, CBlockIndex *pindexPrev, 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...
 
bool IsWitnessEnabled (const CBlockIndex *pindexPrev, const Consensus::Params &params)
 Check whether witness commitments are required for a block, and whether to enforce NULLDUMMY (BIP 147) rules. More...
 
bool RewindBlockIndex (const CChainParams &params) LOCKS_EXCLUDED(cs_main)
 When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index. More...
 
int GetWitnessCommitmentIndex (const CBlock &block)
 Compute at which vout of the block's coinbase transaction the witness commitment occurs, or -1 if not found. More...
 
void UpdateUncommittedBlockStructures (CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
 Update uncommitted block structures (currently: only the witness reserved value). More...
 
std::vector< unsigned char > GenerateCoinbaseCommitment (CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
 Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks). More...
 
CBlockIndexLookupBlockIndex (const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 
CBlockIndexFindForkInGlobalIndex (const CChain &chain, const CBlockLocator &locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Find the last common block between the parameter chain and a locator. More...
 
bool PreciousBlock (BlockValidationState &state, const CChainParams &params, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
 Mark a block as precious and reorganize. More...
 
bool InvalidateBlock (BlockValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
 Mark a block as invalid. More...
 
void ResetBlockFailureFlags (CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Remove invalidity status from a block and its descendants. More...
 
CChainStateChainstateActive ()
 
CChainChainActive ()
 
BlockMapBlockIndex ()
 
int GetSpendHeight (const CCoinsViewCache &inputs)
 Return the spend height, which is one more than the inputs.GetBestBlock(). More...
 
int32_t ComputeBlockVersion (const CBlockIndex *pindexPrev, const Consensus::Params &params)
 Determine what nVersion a new block should use. More...
 
CBlockFileInfoGetBlockFileInfo (size_t n)
 Get block file info entry for one block file. More...
 
bool DumpMempool (const CTxMemPool &pool)
 Dump the mempool to disk. More...
 
bool LoadMempool (CTxMemPool &pool)
 Load the mempool from disk. More...
 
bool IsBlockPruned (const CBlockIndex *pblockindex)
 Check whether the block associated with this index entry is pruned or not. More...
 

Variables

static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000
 Default for -minrelaytxfee, minimum relay fee for transactions. More...
 
static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25
 Default for -limitancestorcount, max number of in-mempool ancestors. More...
 
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101
 Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors. More...
 
static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25
 Default for -limitdescendantcount, max number of in-mempool descendants. More...
 
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101
 Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants. More...
 
static const unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT = 10000
 An extra transaction can be added to a package, as long as it only has one ancestor and is no larger than this. More...
 
static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336
 Default for -mempoolexpiry, expiration time for mempool transactions in hours. More...
 
static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000
 Maximum kilobytes for transactions to store for processing during reorg. More...
 
static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000
 The maximum size of a blk?????.dat file (since 0.8) More...
 
static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000
 The pre-allocation chunk size for blk?????.dat files (since 0.8) More...
 
static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000
 The pre-allocation chunk size for rev?????.dat files (since 0.8) More...
 
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 int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16
 Number of blocks that can be requested at any given time from a single peer. More...
 
static const unsigned int BLOCK_STALLING_TIMEOUT = 2
 Timeout in seconds during which a peer must stall block download progress before being disconnected. More...
 
static const unsigned int MAX_HEADERS_RESULTS = 2000
 Number of headers sent in one getheaders result. More...
 
static const int MAX_CMPCTBLOCK_DEPTH = 5
 Maximum depth of blocks we're willing to serve as compact blocks to peers when requested. More...
 
static const int MAX_BLOCKTXN_DEPTH = 10
 Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for. More...
 
static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024
 Size of the "block download window": how far ahead of our current height do we fetch? Larger windows tolerate larger download speed differences between peer, but increase the potential degree of disordering of blocks on disk (which make reindexing and pruning harder). More...
 
static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60
 Time to wait (in seconds) between writing blocks/block index to disk. More...
 
static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60
 Time to wait (in seconds) between flushing chainstate to disk. More...
 
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000
 Block download timeout base, expressed in millionths of the block interval (i.e. More...
 
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000
 Additional block download timeout per parallel downloading peer (i.e. More...
 
static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
 
static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60
 Maximum age of our tip in seconds for us to be considered current for fee estimation. More...
 
static const bool DEFAULT_CHECKPOINTS_ENABLED = true
 
static const bool DEFAULT_TXINDEX = false
 
static const char *const DEFAULT_BLOCKFILTERINDEX = "0"
 
static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100
 
static const bool DEFAULT_PERSIST_MEMPOOL = true
 Default for -persistmempool. More...
 
static const bool DEFAULT_FEEFILTER = true
 Default for using fee filter. More...
 
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8
 Maximum number of headers to announce when relaying blocks with headers message. More...
 
static const int MAX_UNCONNECTING_HEADERS = 10
 Maximum number of unconnecting headers announcements before DoS score. More...
 
static const int DEFAULT_STOPATHEIGHT = 0
 Default for -stopatheight. More...
 
CCriticalSection cs_main
 Mutex to guard access to validation specific variables, such as reading or changing the chainstate. More...
 
CBlockPolicyEstimator feeEstimator
 
CTxMemPool mempool
 
Mutex g_best_block_mutex
 
std::condition_variable g_best_block_cv
 
uint256 g_best_block
 
std::atomic_bool fImporting
 
std::atomic_bool fReindex
 
bool g_parallel_script_checks
 Whether there are dedicated script-checking threads running. More...
 
bool fRequireStandard
 
bool fCheckBlockIndex
 
bool fCheckpointsEnabled
 
size_t nCoinCacheUsage
 
CFeeRate minRelayTxFee
 A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) More...
 
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...
 
CBlockIndexpindexBestHeader
 Best header we've seen so far (used for getheaders queries' starting points). More...
 
bool fHavePruned
 Pruning-related variables and constants. More...
 
bool fPruneMode
 True if we're running in -prune mode. More...
 
uint64_t nPruneTarget
 Number of MiB of block files that we're trying to stay below. More...
 
static const unsigned int MIN_BLOCKS_TO_KEEP = 288
 Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ChainActive().Tip() will not be pruned. More...
 
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288
 Minimum blocks required to signal NODE_NETWORK_LIMITED. More...
 
static const signed int DEFAULT_CHECKBLOCKS = 6
 
static const unsigned int DEFAULT_CHECKLEVEL = 3
 
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024
 
std::unique_ptr< CChainStateg_chainstate
 
std::unique_ptr< CBlockTreeDBpblocktree
 Global variable that points to the active block tree (protected by cs_main) More...
 
VersionBitsCache versionbitscache
 

Typedef Documentation

◆ BlockMap

typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap

Definition at line 142 of file validation.h.

Enumeration Type Documentation

◆ DisconnectResult

Enumerator
DISCONNECT_OK 
DISCONNECT_UNCLEAN 
DISCONNECT_FAILED 

Definition at line 407 of file validation.h.

◆ FlushStateMode

enum FlushStateMode
strong
See also
CChainState::FlushStateToDisk
Enumerator
NONE 
IF_NEEDED 
PERIODIC 
ALWAYS 

Definition at line 417 of file validation.h.

Function Documentation

◆ AcceptToMemoryPool()

bool AcceptToMemoryPool ( CTxMemPool pool,
TxValidationState state,
const CTransactionRef tx,
std::list< CTransactionRef > *  plTxnReplaced,
bool  bypass_limits,
const CAmount  nAbsurdFee,
bool  test_accept = false 
)

(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions replaced from mempool

Definition at line 1061 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ActivateBestChain()

bool ActivateBestChain ( BlockValidationState state,
const CChainParams chainparams,
std::shared_ptr< const CBlock pblock = std::shared_ptr< const CBlock >() 
)

Find the best known block, and make it the tip of the block chain.

May not be called with cs_main held. May not be called in a validationinterface callback.

Definition at line 2886 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BlockIndex()

BlockMap& BlockIndex ( )
Returns
the global block index map.

Definition at line 1296 of file validation.cpp.

Here is the caller graph for this function:

◆ CalculateCurrentUsage()

uint64_t CalculateCurrentUsage ( )

Calculate the amount of disk space the block & undo files currently use.

Calculate the amount of disk space the block & undo files currently use.

Definition at line 3825 of file validation.cpp.

Here is the caller graph for this function:

◆ ChainActive()

CChain& ChainActive ( )
Returns
the most-work chain.

Definition at line 91 of file validation.cpp.

◆ ChainstateActive()

CChainState& ChainstateActive ( )
Returns
the most-work valid chainstate.

Definition at line 86 of file validation.cpp.

Here is the caller graph for this function:

◆ CheckBlock()

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 3263 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckFinalTx()

bool CheckFinalTx ( const CTransaction tx,
int  flags = -1 
)

Transaction validation functions.

Check if transaction will be final in the next block to be created.

Calls IsFinalTx() with current block height and appropriate block time.

See consensus/consensus.h for flag definitions.

Definition at line 188 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ CheckSequenceLocks()

bool CheckSequenceLocks ( const CTxMemPool pool,
const CTransaction tx,
int  flags,
LockPoints lp = nullptr,
bool  useExistingLockPoints = false 
)

Check if transaction will be BIP 68 final in the next block to be created.

Simulates calling SequenceLocks() with data from the tip of the current active chain. 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 CheckSequenceLocks returns false.

See consensus/consensus.h for flag definitions.

Definition at line 238 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ComputeBlockVersion()

int32_t ComputeBlockVersion ( const CBlockIndex pindexPrev,
const Consensus::Params params 
)

Determine what nVersion a new block should use.

Definition at line 1777 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DumpMempool()

bool DumpMempool ( const CTxMemPool pool)

Dump the mempool to disk.

Definition at line 5020 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FindForkInGlobalIndex()

CBlockIndex* FindForkInGlobalIndex ( const CChain chain,
const CBlockLocator locator 
)

Find the last common block between the parameter chain and a locator.

Definition at line 159 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GenerateCoinbaseCommitment()

std::vector<unsigned char> GenerateCoinbaseCommitment ( CBlock block,
const CBlockIndex pindexPrev,
const Consensus::Params consensusParams 
)

Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks).

Definition at line 3363 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBlockFileInfo()

CBlockFileInfo* GetBlockFileInfo ( size_t  n)

Get block file info entry for one block file.

Definition at line 4916 of file validation.cpp.

Here is the caller graph for this function:

◆ GetBlockPosFilename()

fs::path GetBlockPosFilename ( const FlatFilePos pos)

Translation to a filesystem path.

Definition at line 4004 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBlockSubsidy()

CAmount GetBlockSubsidy ( int  nHeight,
const Consensus::Params consensusParams 
)

Definition at line 1220 of file validation.cpp.

Here is the caller graph for this function:

◆ GetSpendHeight()

int GetSpendHeight ( const CCoinsViewCache inputs)

Return the spend height, which is one more than the inputs.GetBestBlock().

While checking, GetBestBlock() refers to the parent block. (protected by cs_main) This is also true for mempool checks.

Definition at line 1448 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTransaction()

bool GetTransaction ( const uint256 hash,
CTransactionRef txOut,
const Consensus::Params consensusParams,
uint256 hashBlock,
const CBlockIndex *const  block_index 
)

Retrieve a transaction (from memory pool, or from disk, if possible)

Retrieve a transaction (from memory pool, or from disk, if possible)

If blockIndex is provided, the transaction is fetched from the corresponding block.

Definition at line 1073 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetWitnessCommitmentIndex()

int GetWitnessCommitmentIndex ( const CBlock block)

Compute at which vout of the block's coinbase transaction the witness commitment occurs, or -1 if not found.

Definition at line 3338 of file validation.cpp.

Here is the caller graph for this function:

◆ GuessVerificationProgress()

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 5075 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InitScriptExecutionCache()

void InitScriptExecutionCache ( )

Initializes the script-execution cache.

Definition at line 1459 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ InvalidateBlock()

bool InvalidateBlock ( BlockValidationState state,
const CChainParams chainparams,
CBlockIndex pindex 
)

Mark a block as invalid.

Definition at line 3058 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsBlockPruned()

bool IsBlockPruned ( const CBlockIndex pblockindex)
inline

Check whether the block associated with this index entry is pruned or not.

Definition at line 792 of file validation.h.

Here is the caller graph for this function:

◆ IsWitnessEnabled()

bool IsWitnessEnabled ( const CBlockIndex pindexPrev,
const Consensus::Params params 
)

Check whether witness commitments are required for a block, and whether to enforce NULLDUMMY (BIP 147) rules.

Note that transaction witness validation rules are always enforced when P2SH is enforced.

Definition at line 3332 of file validation.cpp.

Here is the caller graph for this function:

◆ LoadBlockIndex()

bool LoadBlockIndex ( const CChainParams chainparams)

Load the block tree and coins database from disk, initializing state if we're running with -reindex.

Definition at line 4553 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadExternalBlockFile()

bool LoadExternalBlockFile ( const CChainParams chainparams,
FILE *  fileIn,
FlatFilePos dbp = nullptr 
)

Import blocks from an external file.

Definition at line 4605 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadGenesisBlock()

bool LoadGenesisBlock ( const CChainParams chainparams)

Ensures we have a genesis block in the block tree, possibly writing one to disk.

Definition at line 4600 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LoadMempool()

bool LoadMempool ( CTxMemPool pool)

Load the mempool from disk.

Definition at line 4943 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LookupBlockIndex()

CBlockIndex* LookupBlockIndex ( const uint256 hash)

Definition at line 152 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OpenBlockFile()

FILE* OpenBlockFile ( const FlatFilePos pos,
bool  fReadOnly = false 
)

Open a block file (blk?????.dat)

Definition at line 3995 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PreciousBlock()

bool PreciousBlock ( BlockValidationState state,
const CChainParams params,
CBlockIndex pindex 
)

Mark a block as precious and reorganize.

May not be called in a validationinterface callback.

Definition at line 2918 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessNewBlock()

bool ProcessNewBlock ( const CChainParams chainparams,
const std::shared_ptr< const CBlock pblock,
bool  fForceProcessing,
bool *  fNewBlock 
)

Process an incoming block.

This only returns after the best known valid block is made active. Note that it does not, however, guarantee that the specific block passed to it has been checked for validity!

If you want to possibly get feedback on whether pblock is valid, you must install a CValidationInterface (see validationinterface.h) - this will have its BlockChecked method called whenever any block completes validation.

Note that we guarantee that either the proof-of-work is valid on pblock, or (and possibly also) BlockChecked will have been called.

May not be called in a validationinterface callback.

Parameters
[in]pblockThe block we want to process.
[in]fForceProcessingProcess this block even if unrequested; used for non-network block sources and whitelisted peers.
[out]fNewBlockA boolean which is set to indicate if the block was first received via this call
Returns
If the block was processed, independently of block validity

Definition at line 3760 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessNewBlockHeaders()

bool ProcessNewBlockHeaders ( const std::vector< CBlockHeader > &  block,
BlockValidationState state,
const CChainParams chainparams,
const CBlockIndex **  ppindex = nullptr 
)

Process incoming block headers.

May not be called in a validationinterface callback.

Parameters
[in]blockThe block headers themselves
[out]stateThis may be set to an Error state if any error occurred processing them
[in]chainparamsThe params for the chain we want to connect to
[out]ppindexIf set, the pointer will be set to point to the last new block index object for the given headers

Definition at line 3633 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PruneBlockFilesManual()

void PruneBlockFilesManual ( int  nManualPruneHeight)

Prune block files up to a given height.

Definition at line 3904 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PruneOneBlockFile()

void PruneOneBlockFile ( const int  fileNumber)

Mark one block file as pruned.

Definition at line 3837 of file validation.cpp.

Here is the caller graph for this function:

◆ ReadBlockFromDisk() [1/2]

bool ReadBlockFromDisk ( CBlock block,
const FlatFilePos pos,
const Consensus::Params consensusParams 
)

Functions for disk access for blocks.

Definition at line 1134 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadBlockFromDisk() [2/2]

bool ReadBlockFromDisk ( CBlock block,
const CBlockIndex pindex,
const Consensus::Params consensusParams 
)

Definition at line 1158 of file validation.cpp.

Here is the call graph for this function:

◆ ReadRawBlockFromDisk() [1/2]

bool ReadRawBlockFromDisk ( std::vector< uint8_t > &  block,
const FlatFilePos pos,
const CMessageHeader::MessageStartChars message_start 
)

Definition at line 1174 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ReadRawBlockFromDisk() [2/2]

bool ReadRawBlockFromDisk ( std::vector< uint8_t > &  block,
const CBlockIndex pindex,
const CMessageHeader::MessageStartChars message_start 
)

Definition at line 1209 of file validation.cpp.

Here is the call graph for this function:

◆ ResetBlockFailureFlags()

void ResetBlockFailureFlags ( CBlockIndex pindex)

Remove invalidity status from a block and its descendants.

Definition at line 3096 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RewindBlockIndex()

bool RewindBlockIndex ( const CChainParams params)

When there are blocks in the active chain with missing data, rewind the chainstate and remove them from the block index.

Definition at line 4504 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestBlockValidity()

bool TestBlockValidity ( BlockValidationState state,
const CChainParams chainparams,
const CBlock block,
CBlockIndex pindexPrev,
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 3795 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ TestLockPointValidity()

bool TestLockPointValidity ( const LockPoints lp)

Test whether the LockPoints height and time are still valid on the current chain.

Definition at line 220 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ThreadScriptCheck()

void ThreadScriptCheck ( int  worker_num)

Run an instance of the script checking thread.

Definition at line 1770 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UndoReadFromDisk()

bool UndoReadFromDisk ( CBlockUndo blockundo,
const CBlockIndex pindex 
)

Definition at line 1588 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnlinkPrunedFiles()

void UnlinkPrunedFiles ( const std::set< int > &  setFilesToPrune)

Actually unlink the specified files.

Definition at line 3871 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UnloadBlockIndex()

void UnloadBlockIndex ( )

Unload database information.

Definition at line 4532 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateCoins()

void UpdateCoins ( const CTransaction tx,
CCoinsViewCache inputs,
int  nHeight 
)

Apply the effects of this transaction on the UTXO set represented by view.

Definition at line 1436 of file validation.cpp.

Here is the call graph for this function:

◆ UpdateUncommittedBlockStructures()

void UpdateUncommittedBlockStructures ( CBlock block,
const CBlockIndex pindexPrev,
const Consensus::Params consensusParams 
)

Update uncommitted block structures (currently: only the witness reserved value).

This is safe for submitted blocks.

Definition at line 3351 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VersionBitsTipState()

ThresholdState VersionBitsTipState ( const Consensus::Params params,
Consensus::DeploymentPos  pos 
)

Get the BIP9 state for a given deployment at the current tip.

Definition at line 4923 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VersionBitsTipStateSinceHeight()

int VersionBitsTipStateSinceHeight ( const Consensus::Params params,
Consensus::DeploymentPos  pos 
)

Get the block height at which the BIP9 deployment switched into the state for the block building on the current tip.

Definition at line 4935 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ VersionBitsTipStatistics()

BIP9Stats VersionBitsTipStatistics ( const Consensus::Params params,
Consensus::DeploymentPos  pos 
)

Get the numerical statistics for the BIP9 state for a given deployment at the current tip.

Definition at line 4929 of file validation.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ BLOCK_DOWNLOAD_TIMEOUT_BASE

const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000
static

Block download timeout base, expressed in millionths of the block interval (i.e.

10 min)

Definition at line 105 of file validation.h.

◆ BLOCK_DOWNLOAD_TIMEOUT_PER_PEER

const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000
static

Additional block download timeout per parallel downloading peer (i.e.

5 min)

Definition at line 107 of file validation.h.

◆ BLOCK_DOWNLOAD_WINDOW

const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024
static

Size of the "block download window": how far ahead of our current height do we fetch? Larger windows tolerate larger download speed differences between peer, but increase the potential degree of disordering of blocks on disk (which make reindexing and pruning harder).

We'll probably want to make this a per-peer adaptive value at some point.

Definition at line 99 of file validation.h.

◆ BLOCK_STALLING_TIMEOUT

const unsigned int BLOCK_STALLING_TIMEOUT = 2
static

Timeout in seconds during which a peer must stall block download progress before being disconnected.

Definition at line 86 of file validation.h.

◆ BLOCKFILE_CHUNK_SIZE

const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000
static

The pre-allocation chunk size for blk?????.dat files (since 0.8)

Definition at line 75 of file validation.h.

◆ 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 106 of file validation.cpp.

◆ DATABASE_FLUSH_INTERVAL

const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60
static

Time to wait (in seconds) between flushing chainstate to disk.

Definition at line 103 of file validation.h.

◆ DATABASE_WRITE_INTERVAL

const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60
static

Time to wait (in seconds) between writing blocks/block index to disk.

Definition at line 101 of file validation.h.

◆ DEFAULT_ANCESTOR_LIMIT

const unsigned int DEFAULT_ANCESTOR_LIMIT = 25
static

Default for -limitancestorcount, max number of in-mempool ancestors.

Definition at line 55 of file validation.h.

◆ DEFAULT_ANCESTOR_SIZE_LIMIT

const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101
static

Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors.

Definition at line 57 of file validation.h.

◆ DEFAULT_BANSCORE_THRESHOLD

const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100
static

Definition at line 116 of file validation.h.

◆ DEFAULT_BLOCKFILTERINDEX

const char* const DEFAULT_BLOCKFILTERINDEX = "0"
static

Definition at line 115 of file validation.h.

◆ DEFAULT_CHECKBLOCKS

const signed int DEFAULT_CHECKBLOCKS = 6
static

Definition at line 182 of file validation.h.

◆ DEFAULT_CHECKLEVEL

const unsigned int DEFAULT_CHECKLEVEL = 3
static

Definition at line 183 of file validation.h.

◆ DEFAULT_CHECKPOINTS_ENABLED

const bool DEFAULT_CHECKPOINTS_ENABLED = true
static

Definition at line 113 of file validation.h.

◆ DEFAULT_DESCENDANT_LIMIT

const unsigned int DEFAULT_DESCENDANT_LIMIT = 25
static

Default for -limitdescendantcount, max number of in-mempool descendants.

Definition at line 59 of file validation.h.

◆ DEFAULT_DESCENDANT_SIZE_LIMIT

const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101
static

Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.

Definition at line 61 of file validation.h.

◆ DEFAULT_FEEFILTER

const bool DEFAULT_FEEFILTER = true
static

Default for using fee filter.

Definition at line 120 of file validation.h.

◆ DEFAULT_MAX_TIP_AGE

const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
static

Definition at line 109 of file validation.h.

◆ DEFAULT_MEMPOOL_EXPIRY

const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336
static

Default for -mempoolexpiry, expiration time for mempool transactions in hours.

Definition at line 69 of file validation.h.

◆ DEFAULT_MIN_RELAY_TX_FEE

const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000
static

Default for -minrelaytxfee, minimum relay fee for transactions.

Definition at line 53 of file validation.h.

◆ DEFAULT_PERSIST_MEMPOOL

const bool DEFAULT_PERSIST_MEMPOOL = true
static

Default for -persistmempool.

Definition at line 118 of file validation.h.

◆ DEFAULT_SCRIPTCHECK_THREADS

const int DEFAULT_SCRIPTCHECK_THREADS = 0
static

-par default (number of script-checking threads, 0 = auto)

Definition at line 82 of file validation.h.

◆ DEFAULT_STOPATHEIGHT

const int DEFAULT_STOPATHEIGHT = 0
static

Default for -stopatheight.

Definition at line 129 of file validation.h.

◆ DEFAULT_TXINDEX

const bool DEFAULT_TXINDEX = false
static

Definition at line 114 of file validation.h.

◆ EXTRA_DESCENDANT_TX_SIZE_LIMIT

const unsigned int EXTRA_DESCENDANT_TX_SIZE_LIMIT = 10000
static

An extra transaction can be added to a package, as long as it only has one ancestor and is no larger than this.

Not really any reason to make this configurable as it doesn't materially change DoS parameters.

Definition at line 67 of file validation.h.

◆ fCheckBlockIndex

bool fCheckBlockIndex

Definition at line 118 of file validation.cpp.

◆ fCheckpointsEnabled

bool fCheckpointsEnabled

Definition at line 119 of file validation.cpp.

◆ feeEstimator

CBlockPolicyEstimator feeEstimator

Definition at line 129 of file validation.cpp.

◆ fHavePruned

bool fHavePruned

Pruning-related variables and constants.

True if any block files have ever been pruned.

Definition at line 115 of file validation.cpp.

◆ fImporting

std::atomic_bool fImporting

◆ fPruneMode

bool fPruneMode

True if we're running in -prune mode.

Definition at line 116 of file validation.cpp.

◆ fReindex

std::atomic_bool fReindex

◆ fRequireStandard

bool fRequireStandard

Definition at line 117 of file validation.cpp.

◆ g_best_block

uint256 g_best_block

Definition at line 111 of file validation.cpp.

◆ g_best_block_cv

std::condition_variable g_best_block_cv

Definition at line 110 of file validation.cpp.

◆ g_best_block_mutex

Mutex g_best_block_mutex

Definition at line 109 of file validation.cpp.

◆ g_chainstate

std::unique_ptr<CChainState> g_chainstate

Definition at line 84 of file validation.cpp.

◆ g_parallel_script_checks

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 112 of file validation.cpp.

◆ hashAssumeValid

uint256 hashAssumeValid

Block hash whose ancestors we will assume to have valid scripts without checking them.

Definition at line 124 of file validation.cpp.

◆ MAX_BLOCKFILE_SIZE

const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000
static

The maximum size of a blk?????.dat file (since 0.8)

Definition at line 73 of file validation.h.

◆ MAX_BLOCKS_IN_TRANSIT_PER_PEER

const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16
static

Number of blocks that can be requested at any given time from a single peer.

Definition at line 84 of file validation.h.

◆ MAX_BLOCKS_TO_ANNOUNCE

const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8
static

Maximum number of headers to announce when relaying blocks with headers message.

Definition at line 123 of file validation.h.

◆ MAX_BLOCKTXN_DEPTH

const int MAX_BLOCKTXN_DEPTH = 10
static

Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for.

Definition at line 94 of file validation.h.

◆ MAX_CMPCTBLOCK_DEPTH

const int MAX_CMPCTBLOCK_DEPTH = 5
static

Maximum depth of blocks we're willing to serve as compact blocks to peers when requested.

For older blocks, a regular BLOCK response will be sent.

Definition at line 92 of file validation.h.

◆ MAX_DISCONNECTED_TX_POOL_SIZE

const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000
static

Maximum kilobytes for transactions to store for processing during reorg.

Definition at line 71 of file validation.h.

◆ MAX_FEE_ESTIMATION_TIP_AGE

const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60
static

Maximum age of our tip in seconds for us to be considered current for fee estimation.

Definition at line 111 of file validation.h.

◆ MAX_HEADERS_RESULTS

const unsigned int MAX_HEADERS_RESULTS = 2000
static

Number of headers sent in one getheaders result.

We rely on the assumption that if a peer sends less than this number, we reached its tip. Changing this value is a protocol upgrade.

Definition at line 89 of file validation.h.

◆ MAX_SCRIPTCHECK_THREADS

const int MAX_SCRIPTCHECK_THREADS = 15
static

Maximum number of dedicated script-checking threads allowed.

Definition at line 80 of file validation.h.

◆ MAX_UNCONNECTING_HEADERS

const int MAX_UNCONNECTING_HEADERS = 10
static

Maximum number of unconnecting headers announcements before DoS score.

Definition at line 126 of file validation.h.

◆ mempool

CTxMemPool mempool

◆ MIN_BLOCKS_TO_KEEP

const unsigned int MIN_BLOCKS_TO_KEEP = 288
static

Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ChainActive().Tip() will not be pruned.

Definition at line 178 of file validation.h.

◆ MIN_DISK_SPACE_FOR_BLOCK_FILES

const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024
static

Definition at line 193 of file validation.h.

◆ minRelayTxFee

CFeeRate minRelayTxFee

A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)

Definition at line 127 of file validation.cpp.

◆ nCoinCacheUsage

size_t nCoinCacheUsage

Definition at line 120 of file validation.cpp.

◆ nMaxTipAge

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 122 of file validation.cpp.

◆ nMinimumChainWork

arith_uint256 nMinimumChainWork

Minimum work we will assume exists on some valid chain.

Definition at line 125 of file validation.cpp.

◆ NODE_NETWORK_LIMITED_MIN_BLOCKS

const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288
static

Minimum blocks required to signal NODE_NETWORK_LIMITED.

Definition at line 180 of file validation.h.

◆ nPruneTarget

uint64_t nPruneTarget

Number of MiB of block files that we're trying to stay below.

Definition at line 121 of file validation.cpp.

◆ pblocktree

std::unique_ptr<CBlockTreeDB> pblocktree

Global variable that points to the active block tree (protected by cs_main)

Definition at line 178 of file validation.cpp.

◆ pindexBestHeader

CBlockIndex* pindexBestHeader

Best header we've seen so far (used for getheaders queries' starting points).

Definition at line 108 of file validation.cpp.

◆ UNDOFILE_CHUNK_SIZE

const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000
static

The pre-allocation chunk size for rev?????.dat files (since 0.8)

Definition at line 77 of file validation.h.

◆ versionbitscache

VersionBitsCache versionbitscache