PIVX Core  5.6.99
P2P Digital Currency
Classes | Namespaces | Enumerations | Functions | Variables
validation.cpp File Reference
#include "validation.h"
#include "addrman.h"
#include "blocksignature.h"
#include "budget/budgetmanager.h"
#include "chainparams.h"
#include "checkpoints.h"
#include "checkqueue.h"
#include "consensus/consensus.h"
#include "consensus/merkle.h"
#include "consensus/tx_verify.h"
#include "consensus/validation.h"
#include "consensus/zerocoin_verify.h"
#include "evo/evodb.h"
#include "evo/specialtx_validation.h"
#include "flatfile.h"
#include "guiinterface.h"
#include "interfaces/handler.h"
#include "invalid.h"
#include "kernel.h"
#include "legacy/validation_zerocoin_legacy.h"
#include "llmq/quorums_chainlocks.h"
#include "masternode-payments.h"
#include "masternodeman.h"
#include "policy/policy.h"
#include "pow.h"
#include "reverse_iterate.h"
#include "script/sigcache.h"
#include "shutdown.h"
#include "spork.h"
#include "sporkdb.h"
#include "tiertwo/tiertwo_sync_state.h"
#include "txdb.h"
#include "undo.h"
#include "util/blockstatecatcher.h"
#include "util/system.h"
#include "util/validation.h"
#include "utilmoneystr.h"
#include "validationinterface.h"
#include "warnings.h"
#include "zpiv/zpivmodule.h"
#include <future>
#include <boost/algorithm/string/replace.hpp>
#include <boost/thread.hpp>
#include <atomic>
#include <queue>
Include dependency graph for validation.cpp:

Go to the source code of this file.

Classes

struct  PerBlockConnectTrace
 
class  ConnectTrace
 Used to track blocks whose transactions were applied to the UTXO state as a part of a single ActivateBestChainStep call. More...
 
class  CMainCleanup
 

Namespaces

 Consensus
 

Enumerations

enum  FlushStateMode { FLUSH_STATE_NONE , FLUSH_STATE_IF_NEEDED , FLUSH_STATE_PERIODIC , FLUSH_STATE_ALWAYS }
 
enum  DisconnectResult { DISCONNECT_OK , DISCONNECT_UNCLEAN , DISCONNECT_FAILED }
 

Functions

CBlockIndexFindForkInGlobalIndex (const CChain &chain, const CBlockLocator &locator)
 Find the last common block between the parameter chain and a locator. More...
 
CBlockIndexGetChainTip ()
 Return a reliable pointer (in mapBlockIndex) to the chain's tip index. More...
 
bool CheckFinalTx (const CTransactionRef &tx, int flags)
 Check if transaction will be final in the next block to be created. More...
 
void LimitMempoolSize (CTxMemPool &pool, size_t limit, unsigned long age)
 
CAmount GetMinRelayFee (const CTransaction &tx, const CTxMemPool &pool, unsigned int nBytes)
 
CAmount GetMinRelayFee (unsigned int nBytes)
 
CAmount GetShieldedTxMinFee (const CTransaction &tx)
 Return the minimum fee for a shielded tx. More...
 
bool AcceptToMemoryPoolWithTime (CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, int64_t nAcceptTime, bool fOverrideMempoolLimit, bool fRejectAbsurdFee, bool fIgnoreFees)
 (try to) add transaction to memory pool with a specified acceptance time More...
 
bool AcceptToMemoryPool (CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, bool fOverrideMempoolLimit, bool fRejectInsaneFee, bool ignoreFees)
 (try to) add transaction to memory pool More...
 
bool GetOutput (const uint256 &hash, unsigned int index, CValidationState &state, CTxOut &out)
 Retrieve an output (from memory pool, or from disk, if possible) More...
 
bool GetTransaction (const uint256 &hash, CTransactionRef &txOut, uint256 &hashBlock, bool fAllowSlow, CBlockIndex *blockIndex)
 Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock. More...
 
bool WriteBlockToDisk (const CBlock &block, FlatFilePos &pos)
 Functions for disk access for blocks. More...
 
bool ReadBlockFromDisk (CBlock &block, const FlatFilePos &pos)
 
bool ReadBlockFromDisk (CBlock &block, const CBlockIndex *pindex)
 
double ConvertBitsToDouble (unsigned int nBits)
 
CAmount GetBlockValue (int nHeight)
 
int64_t GetMasternodePayment (int nHeight)
 
bool IsInitialBlockDownload ()
 Check whether we are doing an initial block download (synchronizing from disk or network) More...
 
void CheckForkWarningConditions ()
 
void CheckForkWarningConditionsOnNewFork (CBlockIndex *pindexNewForkTip)
 
void UpdateCoins (const CTransaction &tx, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, bool fSkipInvalid)
 
void UpdateCoins (const CTransaction &tx, CCoinsViewCache &inputs, int nHeight, bool fSkipInvalid)
 Apply the effects of this transaction on the UTXO set represented by view. More...
 
int GetSpendHeight (const CCoinsViewCache &inputs)
 Return the spend height, which is one more than the inputs.GetBestBlock(). More...
 
bool Consensus::CheckTxInputs (const CTransaction &tx, CValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight)
 
bool CheckInputs (const CTransaction &tx, CValidationState &state, const CCoinsViewCache &inputs, bool fScriptChecks, unsigned int flags, bool cacheStore, PrecomputedTransactionData &precomTxData, std::vector< CScriptCheck > *pvChecks)
 Check transaction inputs, and make sure any pay-to-script-hash transactions are evaluating IsStandard scripts. More...
 
int ApplyTxInUndo (Coin &&undo, CCoinsViewCache &view, const COutPoint &out)
 Restore the UTXO in a Coin at a given COutPoint. More...
 
DisconnectResult DisconnectBlock (CBlock &block, const CBlockIndex *pindex, CCoinsViewCache &view)
 Undo the effects of this block (with given index) on the UTXO set represented by coins. More...
 
bool FindUndoPos (CValidationState &state, int nFile, FlatFilePos &pos, unsigned int nAddSize)
 
void ThreadScriptCheck ()
 Run an instance of the script checking thread. More...
 
void FlushStateToDisk ()
 Flush all state, indexes and buffers to disk. More...
 
bool ActivateBestChain (CValidationState &state, std::shared_ptr< const CBlock > pblock)
 Make the best chain active, in multiple steps. More...
 
bool InvalidateBlock (CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex)
 Mark a block as invalid. More...
 
bool ReconsiderBlock (CValidationState &state, CBlockIndex *pindex)
 Remove invalidity status from a block and its descendants. More...
 
bool ReceivedBlockTransactions (const CBlock &block, CValidationState &state, CBlockIndex *pindexNew, const FlatFilePos &pos)
 Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS). More...
 
bool FindBlockPos (CValidationState &state, FlatFilePos &pos, unsigned int nAddSize, unsigned int nHeight, uint64_t nTime, bool fKnown=false)
 
bool CheckColdStakeFreeOutput (const CTransaction &tx, const int nHeight)
 
bool CheckBlock (const CBlock &block, CValidationState &state, bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckSig)
 Functions for validating blocks and updating the block tree. More...
 
bool CheckWork (const CBlock &block, const CBlockIndex *const pindexPrev)
 
bool CheckBlockTime (const CBlockHeader &block, CValidationState &state, CBlockIndex *const pindexPrev)
 
bool ContextualCheckBlockHeader (const CBlockHeader &block, CValidationState &state, CBlockIndex *const pindexPrev)
 Context-dependent validity checks. More...
 
bool ContextualCheckBlock (const CBlock &block, CValidationState &state, CBlockIndex *const pindexPrev)
 
bool AcceptBlockHeader (const CBlock &block, CValidationState &state, CBlockIndex **ppindex, CBlockIndex *pindexPrev)
 
bool ProcessNewBlock (const std::shared_ptr< const CBlock > &pblock, const FlatFilePos *dbp)
 Process an incoming block. More...
 
bool TestBlockValidity (CValidationState &state, const CBlock &block, CBlockIndex *const pindexPrev, bool fCheckPOW, bool fCheckMerkleRoot, bool fCheckBlockSig)
 Check a block is completely valid from start to finish (only works on top of our current best block, with cs_main held) More...
 
FILE * OpenBlockFile (const FlatFilePos &pos, bool fReadOnly)
 Open a block file (blk?????.dat) More...
 
FILE * OpenUndoFile (const FlatFilePos &pos, bool fReadOnly)
 Open an undo file (rev?????.dat) More...
 
fs::path GetBlockPosFilename (const FlatFilePos &pos)
 Translation to a filesystem path. More...
 
CBlockIndexInsertBlockIndex (const uint256 &hash)
 Create a new block index entry for a given block hash. More...
 
bool LoadChainTip (const CChainParams &chainparams)
 Update the chain tip based on database information. More...
 
bool ReplayBlocks (const CChainParams &params, CCoinsView *view)
 Replay blocks that aren't fully applied to the database. More...
 
void UnloadBlockIndex ()
 Unload database information. More...
 
bool LoadBlockIndex (std::string &strError)
 Load the block tree and coins database from disk, initializing state if we're running with -reindex. More...
 
bool LoadGenesisBlock ()
 Ensures we have a genesis block in the block tree, possibly writing one to disk. More...
 
bool LoadExternalBlockFile (FILE *fileIn, FlatFilePos *dbp)
 Import blocks from an external file. More...
 
int ActiveProtocol ()
 See whether the protocol update is enforced for connected nodes. More...
 
CBlockFileInfoGetBlockFileInfo (size_t n)
 Get block file info entry for one block file. More...
 
bool LoadMempool (CTxMemPool &pool)
 Load the mempool from disk. More...
 
bool DumpMempool (const CTxMemPool &pool)
 Dump the mempool to disk. More...
 

Variables

RecursiveMutex cs_main
 Global state. More...
 
BlockMap mapBlockIndex
 
PrevBlockMap mapPrevBlockIndex
 
CChain chainActive
 The currently-connected chain of blocks (protected by cs_main). More...
 
CBlockIndexpindexBestHeader = nullptr
 Best header we've seen so far (used for getheaders queries' starting points). More...
 
Mutex g_best_block_mutex
 
std::condition_variable g_best_block_cv
 
uint256 g_best_block
 
int64_t g_best_block_time = 0
 
int nScriptCheckThreads = 0
 
std::atomic< bool > fImporting {false}
 
std::atomic< bool > fReindex {false}
 
bool fTxIndex = true
 
bool fRequireStandard = true
 
bool fCheckBlockIndex = false
 
size_t nCoinCacheUsage = 5000 * 300
 
int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE
 
CFeeRate minRelayTxFee = CFeeRate(10000)
 Fees smaller than this (in upiv) are considered zero fee (for relaying, mining and transaction creation) We are ~100 times smaller then bitcoin now (2015-06-23), set minRelayTxFee only 10 times higher so it's still 10 times lower comparing to bitcoin. More...
 
CTxMemPool mempool (::minRelayTxFee)
 
std::map< uint256, int64_t > mapRejectedBlocks
 
CMoneySupply MoneySupply
 
CScript COINBASE_FLAGS
 Constant stuff for coinbase transactions we create: More...
 
std::unique_ptr< CCoinsViewDBpcoinsdbview
 Global variable that points to the coins database (protected by cs_main) 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...
 
std::unique_ptr< CZerocoinDBzerocoinDB
 Global variable that points to the zerocoin database (protected by cs_main) More...
 
std::unique_ptr< CSporkDBpSporkDB
 Global variable that points to the spork database (protected by cs_main) More...
 
std::unique_ptr< AccumulatorCacheaccumulatorCache
 In-memory cache for the zerocoin accumulators. More...
 
CBlockIndexpindexBestForkTip = nullptr
 
CBlockIndexpindexBestForkBase = nullptr
 
class CMainCleanup instance_of_cmaincleanup
 

Enumeration Type Documentation

◆ DisconnectResult

Enumerator
DISCONNECT_OK 
DISCONNECT_UNCLEAN 
DISCONNECT_FAILED 

Definition at line 1241 of file validation.cpp.

◆ FlushStateMode

Enumerator
FLUSH_STATE_NONE 
FLUSH_STATE_IF_NEEDED 
FLUSH_STATE_PERIODIC 
FLUSH_STATE_ALWAYS 

Definition at line 212 of file validation.cpp.

Function Documentation

◆ AcceptBlockHeader()

bool AcceptBlockHeader ( const CBlock block,
CValidationState state,
CBlockIndex **  ppindex,
CBlockIndex pindexPrev 
)
Todo:
: ENABLE BLOCK CACHE IN SPECIFIC CASES

Definition at line 3034 of file validation.cpp.

Here is the call graph for this function:

◆ AcceptToMemoryPool()

bool AcceptToMemoryPool ( CTxMemPool pool,
CValidationState state,
const CTransactionRef tx,
bool  fLimitFree,
bool *  pfMissingInputs,
bool  fOverrideMempoolLimit,
bool  fRejectInsaneFee,
bool  ignoreFees 
)

(try to) add transaction to memory pool

Definition at line 649 of file validation.cpp.

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

◆ AcceptToMemoryPoolWithTime()

bool AcceptToMemoryPoolWithTime ( CTxMemPool pool,
CValidationState state,
const CTransactionRef tx,
bool  fLimitFree,
bool *  pfMissingInputs,
int64_t  nAcceptTime,
bool  fOverrideMempoolLimit,
bool  fRejectAbsurdFee,
bool  fIgnoreFees 
)

(try to) add transaction to memory pool with a specified acceptance time

Definition at line 632 of file validation.cpp.

Here is the caller graph for this function:

◆ ActivateBestChain()

bool ActivateBestChain ( CValidationState state,
std::shared_ptr< const CBlock pblock 
)

Make the best chain active, in multiple steps.

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

The result is either failure or an activated best chain. pblock is either nullptr or a pointer to a block that is already loaded (to avoid loading it again from disk).

Definition at line 2280 of file validation.cpp.

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

◆ ActiveProtocol()

int ActiveProtocol ( )

See whether the protocol update is enforced for connected nodes.

Definition at line 4222 of file validation.cpp.

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

◆ ApplyTxInUndo()

int ApplyTxInUndo ( Coin &&  undo,
CCoinsViewCache view,
const COutPoint out 
)

Restore the UTXO in a Coin at a given COutPoint.

Parameters
undoThe Coin to be restored.
viewThe coins view to which to apply the changes.
outThe out point that corresponds to the tx input.
Returns
A DisconnectResult as an int

Definition at line 1255 of file validation.cpp.

Here is the call graph for this function:

◆ CheckBlock()

bool CheckBlock ( const CBlock block,
CValidationState state,
bool  fCheckPOW = true,
bool  fCheckMerkleRoot = true,
bool  fCheckSig = true 
)

Functions for validating blocks and updating the block tree.

Context-independent validity checks

Definition at line 2701 of file validation.cpp.

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

◆ CheckBlockTime()

bool CheckBlockTime ( const CBlockHeader block,
CValidationState state,
CBlockIndex *const  pindexPrev 
)

Definition at line 2865 of file validation.cpp.

Here is the call graph for this function:

◆ CheckColdStakeFreeOutput()

bool CheckColdStakeFreeOutput ( const CTransaction tx,
const int  nHeight 
)

Definition at line 2637 of file validation.cpp.

Here is the call graph for this function:

◆ CheckFinalTx()

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

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

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

◆ CheckForkWarningConditions()

void CheckForkWarningConditions ( )

Definition at line 905 of file validation.cpp.

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

◆ CheckForkWarningConditionsOnNewFork()

void CheckForkWarningConditionsOnNewFork ( CBlockIndex pindexNewForkTip)

Definition at line 947 of file validation.cpp.

Here is the call graph for this function:

◆ CheckInputs()

bool CheckInputs ( const CTransaction tx,
CValidationState state,
const CCoinsViewCache view,
bool  fScriptChecks,
unsigned int  flags,
bool  cacheStore,
PrecomputedTransactionData precomTxData,
std::vector< CScriptCheck > *  pvChecks = nullptr 
)

Check transaction inputs, and make sure any pay-to-script-hash transactions are evaluating IsStandard scripts.

Why bother? To avoid denial-of-service attacks; an attacker can submit a standard HASH... OP_EQUAL transaction, which will get accepted into blocks. The redemption script can be anything; an attacker could use a very expensive-to-check-upon-redemption script like: DUP CHECKSIG DROP ... repeated 100 times... OP_1 Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts) This does not modify the UTXO set. If pvChecks is not nullptr, script checks are pushed onto it instead of being performed inline.

Definition at line 1104 of file validation.cpp.

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

◆ CheckWork()

bool CheckWork ( const CBlock block,
const CBlockIndex *const  pindexPrev 
)

Definition at line 2833 of file validation.cpp.

Here is the call graph for this function:

◆ ContextualCheckBlock()

bool ContextualCheckBlock ( const CBlock block,
CValidationState state,
CBlockIndex *const  pindexPrev 
)

Definition at line 2958 of file validation.cpp.

Here is the call graph for this function:

◆ ContextualCheckBlockHeader()

bool ContextualCheckBlockHeader ( const CBlockHeader block,
CValidationState state,
CBlockIndex *const  pindexPrev 
)

Context-dependent validity checks.

Definition at line 2909 of file validation.cpp.

Here is the call graph for this function:

◆ ConvertBitsToDouble()

double ConvertBitsToDouble ( unsigned int  nBits)

Definition at line 797 of file validation.cpp.

Here is the caller graph for this function:

◆ DisconnectBlock()

DisconnectResult DisconnectBlock ( CBlock block,
const CBlockIndex pindex,
CCoinsViewCache view 
)

Undo the effects of this block (with given index) on the UTXO set represented by coins.

When FAILED is returned, view is left in an indeterminate state.

Definition at line 1286 of file validation.cpp.

Here is the call graph for this function:

◆ DumpMempool()

bool DumpMempool ( const CTxMemPool pool)

Dump the mempool to disk.

Definition at line 4312 of file validation.cpp.

Here is the call graph for this function:

◆ FindBlockPos()

bool FindBlockPos ( CValidationState state,
FlatFilePos pos,
unsigned int  nAddSize,
unsigned int  nHeight,
uint64_t  nTime,
bool  fKnown = false 
)

Definition at line 2570 of file validation.cpp.

◆ FindForkInGlobalIndex()

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

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

Definition at line 181 of file validation.cpp.

Here is the call graph for this function:

◆ FindUndoPos()

bool FindUndoPos ( CValidationState state,
int  nFile,
FlatFilePos pos,
unsigned int  nAddSize 
)

Definition at line 2617 of file validation.cpp.

◆ FlushStateToDisk()

void FlushStateToDisk ( )

Flush all state, indexes and buffers to disk.

Definition at line 1848 of file validation.cpp.

◆ GetBlockFileInfo()

CBlockFileInfo* GetBlockFileInfo ( size_t  n)

Get block file info entry for one block file.

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

Here is the caller graph for this function:

◆ GetBlockValue()

CAmount GetBlockValue ( int  nHeight)

Definition at line 816 of file validation.cpp.

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

◆ GetChainTip()

CBlockIndex* GetChainTip ( )

Return a reliable pointer (in mapBlockIndex) to the chain's tip index.

Definition at line 194 of file validation.cpp.

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

◆ GetMasternodePayment()

int64_t GetMasternodePayment ( int  nHeight)

Definition at line 852 of file validation.cpp.

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

◆ GetMinRelayFee() [1/2]

CAmount GetMinRelayFee ( const CTransaction tx,
const CTxMemPool pool,
unsigned int  nBytes 
)

Definition at line 265 of file validation.cpp.

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

◆ GetMinRelayFee() [2/2]

CAmount GetMinRelayFee ( unsigned int  nBytes)

Definition at line 279 of file validation.cpp.

Here is the call graph for this function:

◆ GetOutput()

bool GetOutput ( const uint256 hash,
unsigned int  index,
CValidationState state,
CTxOut out 
)

Retrieve an output (from memory pool, or from disk, if possible)

Definition at line 656 of file validation.cpp.

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

◆ GetShieldedTxMinFee()

CAmount GetShieldedTxMinFee ( const CTransaction tx)

Return the minimum fee for a shielded tx.

Definition at line 288 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 1044 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,
uint256 hashBlock,
bool  fAllowSlow,
CBlockIndex blockIndex 
)

Return transaction in tx, and if it was found inside a block, its hash is placed in hashBlock.

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

Definition at line 671 of file validation.cpp.

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

◆ InsertBlockIndex()

CBlockIndex* InsertBlockIndex ( const uint256 hash)

Create a new block index entry for a given block hash.

Definition at line 3509 of file validation.cpp.

Here is the call graph for this function:

◆ InvalidateBlock()

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

Mark a block as invalid.

Definition at line 2376 of file validation.cpp.

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

◆ IsInitialBlockDownload()

bool IsInitialBlockDownload ( )

Check whether we are doing an initial block download (synchronizing from disk or network)

Definition at line 862 of file validation.cpp.

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

◆ LimitMempoolSize()

void LimitMempoolSize ( CTxMemPool pool,
size_t  limit,
unsigned long  age 
)

Definition at line 254 of file validation.cpp.

Here is the call graph for this function:

◆ LoadBlockIndex()

bool LoadBlockIndex ( std::string &  strError)

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

Definition at line 3903 of file validation.cpp.

◆ LoadChainTip()

bool LoadChainTip ( const CChainParams chainparams)

Update the chain tip based on database information.

Definition at line 3642 of file validation.cpp.

Here is the call graph for this function:

◆ LoadExternalBlockFile()

bool LoadExternalBlockFile ( FILE *  fileIn,
FlatFilePos dbp 
)

Import blocks from an external file.

Definition at line 3962 of file validation.cpp.

Here is the call graph for this function:

◆ LoadGenesisBlock()

bool LoadGenesisBlock ( )

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

Definition at line 3930 of file validation.cpp.

Here is the call graph for this function:

◆ LoadMempool()

bool LoadMempool ( CTxMemPool pool)

Load the mempool from disk.

Definition at line 4247 of file validation.cpp.

Here is the call graph for this function:

◆ OpenBlockFile()

FILE* OpenBlockFile ( const FlatFilePos pos,
bool  fReadOnly 
)

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

Definition at line 3494 of file validation.cpp.

Here is the caller graph for this function:

◆ OpenUndoFile()

FILE* OpenUndoFile ( const FlatFilePos pos,
bool  fReadOnly 
)

Open an undo file (rev?????.dat)

Definition at line 3499 of file validation.cpp.

◆ ProcessNewBlock()

bool ProcessNewBlock ( const std::shared_ptr< const CBlock > &  pblock,
const FlatFilePos dbp 
)

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.

Parameters
[in]pblockThe block we want to process.
[out]dbpThe already known disk position of pblock, or nullptr if not yet stored.
Returns
True if state.IsValid()

Definition at line 3412 of file validation.cpp.

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

◆ ReadBlockFromDisk() [1/2]

bool ReadBlockFromDisk ( CBlock block,
const CBlockIndex pindex 
)

Definition at line 783 of file validation.cpp.

Here is the call graph for this function:

◆ ReadBlockFromDisk() [2/2]

bool ReadBlockFromDisk ( CBlock block,
const FlatFilePos pos 
)

Definition at line 758 of file validation.cpp.

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

◆ ReceivedBlockTransactions()

bool ReceivedBlockTransactions ( const CBlock block,
CValidationState state,
CBlockIndex pindexNew,
const FlatFilePos pos 
)

Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS).

Definition at line 2504 of file validation.cpp.

Here is the call graph for this function:

◆ ReconsiderBlock()

bool ReconsiderBlock ( CValidationState state,
CBlockIndex pindex 
)

Remove invalidity status from a block and its descendants.

Definition at line 2419 of file validation.cpp.

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

◆ ReplayBlocks()

bool ReplayBlocks ( const CChainParams params,
CCoinsView view 
)

Replay blocks that aren't fully applied to the database.

Definition at line 3813 of file validation.cpp.

Here is the call graph for this function:

◆ TestBlockValidity()

bool TestBlockValidity ( CValidationState state,
const CBlock block,
CBlockIndex *const  pindexPrev,
bool  fCheckPOW,
bool  fCheckMerkleRoot,
bool  fCheckBlockSig 
)

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

Definition at line 3450 of file validation.cpp.

Here is the call graph for this function:

◆ ThreadScriptCheck()

void ThreadScriptCheck ( )

Run an instance of the script checking thread.

Definition at line 1413 of file validation.cpp.

Here is the call graph for this function:

◆ UnloadBlockIndex()

void UnloadBlockIndex ( )

Unload database information.

Definition at line 3882 of file validation.cpp.

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

◆ UpdateCoins() [1/2]

void UpdateCoins ( const CTransaction tx,
CCoinsViewCache inputs,
CTxUndo txundo,
int  nHeight,
bool  fSkipInvalid 
)

Definition at line 1014 of file validation.cpp.

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

◆ UpdateCoins() [2/2]

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

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

Definition at line 1032 of file validation.cpp.

Here is the call graph for this function:

◆ WriteBlockToDisk()

bool WriteBlockToDisk ( const CBlock block,
FlatFilePos pos 
)

Functions for disk access for blocks.

Definition at line 737 of file validation.cpp.

Here is the call graph for this function:

Variable Documentation

◆ accumulatorCache

std::unique_ptr<AccumulatorCache> accumulatorCache

In-memory cache for the zerocoin accumulators.

Definition at line 210 of file validation.cpp.

◆ chainActive

CChain chainActive

The currently-connected chain of blocks (protected by cs_main).

Definition at line 84 of file validation.cpp.

◆ COINBASE_FLAGS

CScript COINBASE_FLAGS

Constant stuff for coinbase transactions we create:

Definition at line 119 of file validation.cpp.

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

◆ fCheckBlockIndex

bool fCheckBlockIndex = false

Definition at line 98 of file validation.cpp.

◆ fImporting

std::atomic<bool> fImporting {false}

Definition at line 94 of file validation.cpp.

◆ fReindex

std::atomic<bool> fReindex {false}

Definition at line 95 of file validation.cpp.

◆ fRequireStandard

bool fRequireStandard = true

Definition at line 97 of file validation.cpp.

◆ fTxIndex

bool fTxIndex = true

Definition at line 96 of file validation.cpp.

◆ g_best_block

uint256 g_best_block

Definition at line 90 of file validation.cpp.

◆ g_best_block_cv

std::condition_variable g_best_block_cv

Definition at line 89 of file validation.cpp.

◆ g_best_block_mutex

Mutex g_best_block_mutex

Definition at line 88 of file validation.cpp.

◆ g_best_block_time

int64_t g_best_block_time = 0

Definition at line 91 of file validation.cpp.

◆ instance_of_cmaincleanup

class CMainCleanup instance_of_cmaincleanup

◆ mapBlockIndex

BlockMap mapBlockIndex

Definition at line 82 of file validation.cpp.

◆ mapPrevBlockIndex

PrevBlockMap mapPrevBlockIndex

Definition at line 83 of file validation.cpp.

◆ mapRejectedBlocks

std::map<uint256, int64_t> mapRejectedBlocks

Definition at line 112 of file validation.cpp.

◆ mempool

◆ minRelayTxFee

CFeeRate minRelayTxFee = CFeeRate(10000)

Fees smaller than this (in upiv) are considered zero fee (for relaying, mining and transaction creation) We are ~100 times smaller then bitcoin now (2015-06-23), set minRelayTxFee only 10 times higher so it's still 10 times lower comparing to bitcoin.

Definition at line 108 of file validation.cpp.

◆ MoneySupply

CMoneySupply MoneySupply

Definition at line 114 of file validation.cpp.

◆ nCoinCacheUsage

size_t nCoinCacheUsage = 5000 * 300

Definition at line 99 of file validation.cpp.

◆ nMaxTipAge

int64_t nMaxTipAge = DEFAULT_MAX_TIP_AGE

Definition at line 102 of file validation.cpp.

◆ nScriptCheckThreads

int nScriptCheckThreads = 0

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

◆ pcoinsdbview

std::unique_ptr<CCoinsViewDB> pcoinsdbview

Global variable that points to the coins database (protected by cs_main)

Definition at line 205 of file validation.cpp.

◆ pcoinsTip

std::unique_ptr<CCoinsViewCache> pcoinsTip

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

Definition at line 206 of file validation.cpp.

◆ pindexBestForkBase

CBlockIndex * pindexBestForkBase = nullptr

Definition at line 885 of file validation.cpp.

◆ pindexBestForkTip

CBlockIndex* pindexBestForkTip = nullptr

Definition at line 885 of file validation.cpp.

◆ pindexBestHeader

CBlockIndex* pindexBestHeader = nullptr

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

Definition at line 85 of file validation.cpp.

◆ pSporkDB

std::unique_ptr<CSporkDB> pSporkDB

Global variable that points to the spork database (protected by cs_main)

Definition at line 209 of file validation.cpp.

◆ zerocoinDB

std::unique_ptr<CZerocoinDB> zerocoinDB

Global variable that points to the zerocoin database (protected by cs_main)

Definition at line 208 of file validation.cpp.