Bitcoin ABC  0.22.13
P2P Digital Currency
Classes | Namespaces | Macros | Typedefs | Enumerations | Functions | Variables
validation.h File Reference
#include <amount.h>
#include <blockfileinfo.h>
#include <blockindexworkcomparator.h>
#include <coins.h>
#include <consensus/consensus.h>
#include <disconnectresult.h>
#include <flatfile.h>
#include <fs.h>
#include <protocol.h>
#include <script/script_error.h>
#include <script/script_metrics.h>
#include <sync.h>
#include <txdb.h>
#include <txmempool.h>
#include <versionbits.h>
#include <atomic>
#include <cstdint>
#include <map>
#include <memory>
#include <optional>
#include <set>
#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

class  BlockValidationOptions
 
class  CheckInputsLimiter
 Simple class for regulating resource usage during CheckInputScripts (and CScriptCheck), atomic so as to be compatible with parallel validation. More...
 
class  TxSigCheckLimiter
 
class  CScriptCheck
 Closure representing one script verification. More...
 
class  CVerifyDB
 RAII wrapper for VerifyDB: Verify consistency of the block and coin databases. More...
 
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...
 
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

 Consensus
 

Macros

#define MIN_TRANSACTION_SIZE   (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))
 

Typedefs

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

Enumerations

enum  SynchronizationState { SynchronizationState::INIT_REINDEX, SynchronizationState::INIT_DOWNLOAD, SynchronizationState::POST_INIT }
 Current sync state passed to tip changed callbacks. More...
 
enum  FlushStateMode { FlushStateMode::NONE, FlushStateMode::IF_NEEDED, FlushStateMode::PERIODIC, FlushStateMode::ALWAYS }
 
enum  CoinsCacheSizeState { CoinsCacheSizeState::CRITICAL = 2, CoinsCacheSizeState::LARGE = 1, CoinsCacheSizeState::OK = 0 }
 

Functions

static const Amount DEFAULT_MIN_RELAY_TX_FEE_PER_KB (1000 *SATOSHI)
 Default for -minrelaytxfee, minimum relay fee for transactions. More...
 
bool LoadExternalBlockFile (const Config &config, 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...
 
void UnloadBlockIndex ()
 Unload database information. More...
 
void ThreadScriptCheck (int worker_num)
 Run an instance of the script checking thread. More...
 
bool GetTransaction (const TxId &txid, CTransactionRef &txOut, const Consensus::Params &params, BlockHash &hashBlock, const CBlockIndex *const blockIndex=nullptr)
 Retrieve a transaction (from memory pool, or from disk, if possible). More...
 
bool ActivateBestChain (const Config &config, BlockValidationState &state, 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...
 
Amount 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 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 (const Config &config, CTxMemPool &pool, TxValidationState &state, const CTransactionRef &tx, bool bypass_limits, const Amount nAbsurdFee, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 (try to) add transaction to memory pool More...
 
bool CheckInputScripts (const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &view, const uint32_t flags, bool sigCacheStore, bool scriptCacheStore, const PrecomputedTransactionData &txdata, int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks, CheckInputsLimiter *pBlockLimitSigChecks, std::vector< CScriptCheck > *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Check whether all of this transaction's input scripts succeed. More...
 
static bool CheckInputScripts (const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &view, const uint32_t flags, bool sigCacheStore, bool scriptCacheStore, const PrecomputedTransactionData &txdata, int &nSigChecksOut) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Handy shortcut to full fledged CheckInputScripts call. More...
 
ThresholdState VersionBitsTipState (const Consensus::Params &params, Consensus::DeploymentPos pos)
 Get the BIP9 state for a given deployment at the current tip. More...
 
ThresholdState VersionBitsBlockState (const Consensus::Params &params, Consensus::DeploymentPos pos, const CBlockIndex *pindex)
 Get the BIP9 state for a given deployment at a given block. 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...
 
void SpendCoins (CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
 Mark all the coins corresponding to a given transaction inputs as spent. More...
 
void UpdateCoins (CCoinsViewCache &view, const CTransaction &tx, int nHeight)
 Apply the effects of this transaction on the UTXO set represented by view. More...
 
void UpdateCoins (CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
 
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...
 
bool UndoReadFromDisk (CBlockUndo &blockundo, const CBlockIndex *pindex)
 
bool CheckBlock (const CBlock &block, BlockValidationState &state, const Consensus::Params &params, BlockValidationOptions validationOptions)
 Functions for validating blocks and updating the block tree. More...
 
bool ContextualCheckTransactionForCurrentBlock (const Consensus::Params &params, const CTransaction &tx, TxValidationState &state, int flags=-1)
 This is a variant of ContextualCheckTransaction which computes the contextual check for a transaction based on the chain tip. More...
 
bool TestBlockValidity (BlockValidationState &state, const CChainParams &params, const CBlock &block, CBlockIndex *pindexPrev, BlockValidationOptions validationOptions) 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...
 
CBlockIndexLookupBlockIndex (const BlockHash &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 (const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
 Mark a block as precious and reorganize. More...
 
void ResetBlockFailureFlags (CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Remove invalidity status from a block and its descendants. More...
 
void UnparkBlockAndChildren (CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Remove parked status from a block and its descendants. More...
 
void UnparkBlock (CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
 Remove parked status from a block. More...
 
ChainstateManager g_chainman GUARDED_BY (::cs_main)
 DEPRECATED! Please use node.chainman instead. 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 (const Config &config, 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 Amount DEFAULT_UTXO_FEE = Amount::zero()
 Default for -excessutxocharge for transactions transactions. 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_BLOCKFILE_SIZE = 0x8000000
 The maximum size of a blk?????.dat file (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 int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
 
static const bool DEFAULT_CHECKPOINTS_ENABLED = true
 
static const bool DEFAULT_TXINDEX = false
 
static const char *const DEFAULT_BLOCKFILTERINDEX = "0"
 
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 bool DEFAULT_PEERBLOOMFILTERS = true
 
static const int DEFAULT_STOPATHEIGHT = 0
 Default for -stopatheight. More...
 
static const int DEFAULT_MAX_REORG_DEPTH = 10
 Default for -maxreorgdepth. More...
 
static const int64_t DEFAULT_MIN_FINALIZATION_DELAY = 2 * 60 * 60
 Default for -finalizationdelay This is the minimum time between a block header reception and the block finalization. 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 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
 Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat) At 1MB per block, 288 blocks = 288MB. More...
 
RecursiveMutex cs_main
 Global state. More...
 
CTxMemPool g_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 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...
 
BlockHash 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...
 
std::unique_ptr< CCoinsViewCachepcoinsTip
 Global variable that points to the active CCoinsView (protected by cs_main) More...
 
std::unique_ptr< CBlockTreeDBpblocktree
 Global variable that points to the active block tree (protected by cs_main) More...
 

Macro Definition Documentation

◆ MIN_TRANSACTION_SIZE

#define MIN_TRANSACTION_SIZE   (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))

Definition at line 64 of file validation.h.

Typedef Documentation

◆ BlockMap

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

Definition at line 132 of file validation.h.

Enumeration Type Documentation

◆ CoinsCacheSizeState

enum CoinsCacheSizeState
strong
Enumerator
CRITICAL 

The coins cache is in immediate need of a flush.

LARGE 

The cache is at >= 90% capacity.

OK 

Definition at line 665 of file validation.h.

◆ FlushStateMode

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

Definition at line 549 of file validation.h.

◆ SynchronizationState

enum SynchronizationState
strong

Current sync state passed to tip changed callbacks.

Enumerator
INIT_REINDEX 
INIT_DOWNLOAD 
POST_INIT 

Definition at line 128 of file validation.h.

Function Documentation

◆ AcceptToMemoryPool()

bool AcceptToMemoryPool ( const Config config,
CTxMemPool pool,
TxValidationState state,
const CTransactionRef tx,
bool  bypass_limits,
const Amount  nAbsurdFee,
bool  test_accept = false 
)

(try to) add transaction to memory pool

Definition at line 781 of file validation.cpp.

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

◆ ActivateBestChain()

bool ActivateBestChain ( const Config config,
BlockValidationState state,
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 3112 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 931 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 4471 of file validation.cpp.

Here is the caller graph for this function:

◆ ChainActive()

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

Definition at line 78 of file validation.cpp.

Here is the call graph for this function:

◆ ChainstateActive()

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

Definition at line 72 of file validation.cpp.

◆ CheckBlock()

bool CheckBlock ( const CBlock block,
BlockValidationState state,
const Consensus::Params params,
BlockValidationOptions  validationOptions 
)

Functions for validating blocks and updating the block tree.

Context-independent validity checks.

Returns true if the provided block is valid (has valid header, transactions are valid, block is a valid size, etc.)

Definition at line 3733 of file validation.cpp.

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

◆ CheckInputScripts() [1/2]

bool CheckInputScripts ( const CTransaction tx,
TxValidationState state,
const CCoinsViewCache view,
const uint32_t  flags,
bool  sigCacheStore,
bool  scriptCacheStore,
const PrecomputedTransactionData txdata,
int &  nSigChecksOut,
TxSigCheckLimiter txLimitSigChecks,
CheckInputsLimiter pBlockLimitSigChecks,
std::vector< CScriptCheck > *  pvChecks 
)

Check whether all of this transaction's input scripts succeed.

This involves ECDSA signature checks so can be computationally intensive. This function should only be called after the cheap sanity checks in CheckTxInputs passed.

If pvChecks is not nullptr, script checks are pushed onto it instead of being performed inline. Any script checks which are not necessary (eg due to script execution cache hits) are, obviously, not pushed onto pvChecks/run.

Upon success nSigChecksOut will be filled in with either:

  • correct total for all inputs, or,
  • 0, in the case when checks were pushed onto pvChecks (i.e., a cache miss with pvChecks non-null), in which case the total can be found by executing pvChecks and adding the results.

Setting sigCacheStore/scriptCacheStore to false will remove elements from the corresponding cache which are matched. This is useful for checking blocks where we will likely never need the cache entry again.

pLimitSigChecks can be passed to limit the sigchecks count either in parallel or serial validation. With pvChecks null (serial validation), breaking the pLimitSigChecks limit will abort evaluation early and return false. With pvChecks not-null (parallel validation): the cached nSigChecks may itself break the limit in which case false is returned, OR, each entry in the returned pvChecks must be executed exactly once in order to probe the limit accurately.

Definition at line 1141 of file validation.cpp.

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

◆ CheckInputScripts() [2/2]

static bool CheckInputScripts ( const CTransaction tx,
TxValidationState state,
const CCoinsViewCache view,
const uint32_t  flags,
bool  sigCacheStore,
bool  scriptCacheStore,
const PrecomputedTransactionData txdata,
int &  nSigChecksOut 
)
inlinestatic

Handy shortcut to full fledged CheckInputScripts call.

Definition at line 365 of file validation.h.

Here is the call 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 202 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 1498 of file validation.cpp.

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

◆ ContextualCheckTransactionForCurrentBlock()

bool ContextualCheckTransactionForCurrentBlock ( const Consensus::Params params,
const CTransaction tx,
TxValidationState state,
int  flags = -1 
)

This is a variant of ContextualCheckTransaction which computes the contextual check for a transaction based on the chain tip.

See consensus/consensus.h for flag definitions.

Definition at line 3902 of file validation.cpp.

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

◆ DEFAULT_MIN_RELAY_TX_FEE_PER_KB()

static const Amount DEFAULT_MIN_RELAY_TX_FEE_PER_KB ( 1000 *  SATOSHI)
static

Default for -minrelaytxfee, minimum relay fee for transactions.

Here is the caller graph for this function:

◆ DumpMempool()

bool DumpMempool ( const CTxMemPool pool)

Dump the mempool to disk.

Definition at line 5882 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 151 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 5739 of file validation.cpp.

Here is the caller graph for this function:

◆ GetBlockSubsidy()

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

Definition at line 854 of file validation.cpp.

Here is the call graph for this function:
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 1135 of file validation.cpp.

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

◆ GetTransaction()

bool GetTransaction ( const TxId txid,
CTransactionRef txOut,
const Consensus::Params params,
BlockHash 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 794 of file validation.cpp.

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

◆ GUARDED_BY()

ChainstateManager g_chainman GUARDED_BY ( ::cs_main  )

DEPRECATED! Please use node.chainman instead.

May only be used in validation.cpp internally

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 5954 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)

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

Definition at line 5945 of file validation.cpp.

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

◆ LoadExternalBlockFile()

bool LoadExternalBlockFile ( const Config config,
FILE *  fileIn,
FlatFilePos dbp = nullptr 
)

Import blocks from an external file.

Definition at line 5242 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 5238 of file validation.cpp.

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

◆ LoadMempool()

bool LoadMempool ( const Config config,
CTxMemPool pool 
)

Load the mempool from disk.

Definition at line 5780 of file validation.cpp.

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

◆ LookupBlockIndex()

CBlockIndex* LookupBlockIndex ( const BlockHash hash)

Definition at line 145 of file validation.cpp.

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

◆ PreciousBlock()

bool PreciousBlock ( const Config config,
BlockValidationState state,
CBlockIndex pindex 
)

Mark a block as precious and reorganize.

May not be called in a validationinterface callback.

Definition at line 3157 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 4559 of file validation.cpp.

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

◆ ResetBlockFailureFlags()

void ResetBlockFailureFlags ( CBlockIndex pindex)

Remove invalidity status from a block and its descendants.

Definition at line 3488 of file validation.cpp.

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

◆ SpendCoins()

void SpendCoins ( CCoinsViewCache view,
const CTransaction tx,
CTxUndo txundo,
int  nHeight 
)

Mark all the coins corresponding to a given transaction inputs as spent.

Definition at line 1080 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 params,
const CBlock block,
CBlockIndex pindexPrev,
BlockValidationOptions  validationOptions 
)

Check a block is completely valid from start to finish (only works on top of our current best block)

Definition at line 4425 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 183 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 1491 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 1276 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 4516 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 5169 of file validation.cpp.

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

◆ UnparkBlock()

void UnparkBlock ( CBlockIndex pindex)

Remove parked status from a block.

Definition at line 3513 of file validation.cpp.

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

◆ UnparkBlockAndChildren()

void UnparkBlockAndChildren ( CBlockIndex pindex)

Remove parked status from a block and its descendants.

Definition at line 3509 of file validation.cpp.

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

◆ UpdateCoins() [1/3]

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

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

Here is the caller graph for this function:

◆ UpdateCoins() [2/3]

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

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

Definition at line 1101 of file validation.cpp.

Here is the call graph for this function:

◆ UpdateCoins() [3/3]

void UpdateCoins ( CCoinsViewCache view,
const CTransaction tx,
CTxUndo txundo,
int  nHeight 
)

Definition at line 1095 of file validation.cpp.

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

◆ VersionBitsBlockState()

ThresholdState VersionBitsBlockState ( const Consensus::Params params,
Consensus::DeploymentPos  pos,
const CBlockIndex pindex 
)

Get the BIP9 state for a given deployment at a given block.

Definition at line 5758 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 5752 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 5771 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 5765 of file validation.cpp.

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

Variable Documentation

◆ cs_main

RecursiveMutex cs_main

Global state.

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

◆ DEFAULT_BLOCKFILTERINDEX

const char* const DEFAULT_BLOCKFILTERINDEX = "0"
static

Definition at line 85 of file validation.h.

◆ DEFAULT_CHECKBLOCKS

const signed int DEFAULT_CHECKBLOCKS = 6
static

Definition at line 110 of file validation.h.

◆ DEFAULT_CHECKLEVEL

const unsigned int DEFAULT_CHECKLEVEL = 3
static

Definition at line 111 of file validation.h.

◆ DEFAULT_CHECKPOINTS_ENABLED

const bool DEFAULT_CHECKPOINTS_ENABLED = true
static

Definition at line 83 of file validation.h.

◆ DEFAULT_FEEFILTER

const bool DEFAULT_FEEFILTER = true
static

Default for using fee filter.

Definition at line 90 of file validation.h.

◆ DEFAULT_MAX_REORG_DEPTH

const int DEFAULT_MAX_REORG_DEPTH = 10
static

Default for -maxreorgdepth.

Definition at line 97 of file validation.h.

◆ DEFAULT_MAX_TIP_AGE

const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60
static

Definition at line 82 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 75 of file validation.h.

◆ DEFAULT_MIN_FINALIZATION_DELAY

const int64_t DEFAULT_MIN_FINALIZATION_DELAY = 2 * 60 * 60
static

Default for -finalizationdelay This is the minimum time between a block header reception and the block finalization.

This value should be >> block propagation and validation time

Definition at line 104 of file validation.h.

◆ DEFAULT_PEERBLOOMFILTERS

const bool DEFAULT_PEERBLOOMFILTERS = true
static

Definition at line 92 of file validation.h.

◆ DEFAULT_PERSIST_MEMPOOL

const bool DEFAULT_PERSIST_MEMPOOL = true
static

Default for -persistmempool.

Definition at line 88 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 81 of file validation.h.

◆ DEFAULT_STOPATHEIGHT

const int DEFAULT_STOPATHEIGHT = 0
static

Default for -stopatheight.

Definition at line 95 of file validation.h.

◆ DEFAULT_TXINDEX

const bool DEFAULT_TXINDEX = false
static

Definition at line 84 of file validation.h.

◆ DEFAULT_UTXO_FEE

const Amount DEFAULT_UTXO_FEE = Amount::zero()
static

Default for -excessutxocharge for transactions transactions.

Definition at line 70 of file validation.h.

◆ fCheckBlockIndex

bool fCheckBlockIndex

Definition at line 106 of file validation.cpp.

◆ fCheckpointsEnabled

bool fCheckpointsEnabled

Definition at line 107 of file validation.cpp.

◆ fHavePruned

bool fHavePruned

Pruning-related variables and constants.

True if any block files have ever been pruned.

Definition at line 103 of file validation.cpp.

◆ fImporting

std::atomic_bool fImporting

◆ fPruneMode

bool fPruneMode

True if we're running in -prune mode.

Definition at line 104 of file validation.cpp.

◆ fReindex

std::atomic_bool fReindex

◆ fRequireStandard

bool fRequireStandard

Definition at line 105 of file validation.cpp.

◆ g_best_block

uint256 g_best_block

Definition at line 100 of file validation.cpp.

◆ g_best_block_cv

std::condition_variable g_best_block_cv

Definition at line 99 of file validation.cpp.

◆ g_best_block_mutex

Mutex g_best_block_mutex

Definition at line 98 of file validation.cpp.

◆ g_mempool

CTxMemPool g_mempool

Definition at line 117 of file validation.cpp.

◆ hashAssumeValid

BlockHash hashAssumeValid

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

Definition at line 112 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 77 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 79 of file validation.h.

◆ 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 109 of file validation.h.

◆ MIN_DISK_SPACE_FOR_BLOCK_FILES

const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024
static

Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat) At 1MB per block, 288 blocks = 288MB.

Add 15% for Undo data = 331MB Add 20% for Orphan block rate = 397MB We want the low water mark after pruning to be at least 397 MB and since we prune in full block file chunks, we need the high water mark which triggers the prune to be one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB Setting the target to >= 550 MiB will make it likely we can respect the target.

Definition at line 125 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 115 of file validation.cpp.

◆ nCoinCacheUsage

size_t nCoinCacheUsage

Definition at line 108 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 110 of file validation.cpp.

◆ nMinimumChainWork

arith_uint256 nMinimumChainWork

Minimum work we will assume exists on some valid chain.

Definition at line 113 of file validation.cpp.

◆ nPruneTarget

uint64_t nPruneTarget

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

Definition at line 109 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 171 of file validation.cpp.

◆ pcoinsTip

std::unique_ptr<CCoinsViewCache> pcoinsTip

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

◆ pindexBestHeader

CBlockIndex* pindexBestHeader

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

Definition at line 97 of file validation.cpp.