Fabcoin Core  0.16.2
P2P Digital Currency
Classes | Namespaces | Typedefs | Functions | Variables
validation.h File Reference
#include <amount.h>
#include <coins.h>
#include <fs.h>
#include <protocol.h>
#include <policy/feerate.h>
#include <script/script_error.h>
#include <sync.h>
#include <versionbits.h>
#include <algorithm>
#include <exception>
#include <map>
#include <set>
#include <stdint.h>
#include <string>
#include <utility>
#include <vector>
#include <atomic>
#include <boost/unordered_map.hpp>
#include <boost/filesystem/path.hpp>
#include <consensus/consensus.h>
#include <fasc/fascstate.h>
#include <fasc/fascDGP.h>
#include <libethereum/ChainParams.h>
#include <libethashseal/Ethash.h>
#include <libethashseal/GenesisInfo.h>
#include <script/standard.h>
#include <fasc/storageresults.h>
Include dependency graph for validation.h:

Go to the source code of this file.

Classes

struct  BlockHasher
 
struct  CHeightTxIndexIteratorKey
 
struct  CHeightTxIndexKey
 
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  EthTransactionParams
 
struct  ByteCodeExecResult
 
class  FascTxConverter
 
class  ByteCodeExec
 

Namespaces

 Consensus
 

Typedefs

using valtype = std::vector< unsigned char >
 
using ExtractFascTX = std::pair< std::vector< FascTransaction >, std::vector< EthTransactionParams >>
 
typedef std::unordered_map< uint256, CBlockIndex *, BlockHasherBlockMap
 

Functions

int64_t FutureDrift (uint32_t nTime)
 
bool ProcessNewBlock (const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock)
 Process an incoming block. More...
 
bool ProcessNewBlockHeaders (const std::vector< CBlockHeader > &block, CValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=nullptr, CBlockHeader *first_invalid=nullptr)
 Process incoming block headers. More...
 
bool CheckDiskSpace (uint64_t nAdditionalBytes=0)
 Check whether enough disk space is available for an incoming block. More...
 
FILE * OpenBlockFile (const CDiskBlockPos &pos, bool fReadOnly=false)
 Open a block file (blk?????.dat) More...
 
fs::path GetBlockPosFilename (const CDiskBlockPos &pos, const char *prefix)
 Translation to a filesystem path. More...
 
bool LoadExternalBlockFile (const CChainParams &chainparams, FILE *fileIn, CDiskBlockPos *dbp=nullptr)
 Import blocks from an external file. More...
 
bool InitBlockIndex (const CChainParams &chainparams)
 Initialize a new block tree database + block data on disk. 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)
 Load the block tree and coins database from disk, initializing state if we're running with -reindex. More...
 
bool LoadChainTip (const CChainParams &chainparams)
 Update the chain tip based on database information. More...
 
void UnloadBlockIndex ()
 Unload database information. More...
 
void ThreadScriptCheck ()
 Run an instance of the script checking thread. More...
 
bool IsInitialBlockDownload ()
 Check whether we are doing an initial block download (synchronizing from disk or network) More...
 
std::string GetWarnings (const std::string &strFor)
 Format a string that describes several potential problems detected by the core. More...
 
bool GetTransaction (const uint256 &hash, CTransactionRef &tx, const Consensus::Params &params, uint256 &hashBlock, bool fAllowSlow=false)
 Retrieve a transaction (from memory pool, or from disk, if possible) More...
 
bool ActivateBestChain (CValidationState &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, CBlockIndex *pindex)
 Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip). More...
 
void PruneOneBlockFile (const int fileNumber)
 Mark one block file as pruned. More...
 
void UnlinkPrunedFiles (const std::set< int > &setFilesToPrune)
 Actually unlink the specified files. More...
 
CBlockIndexInsertBlockIndex (uint256 hash)
 Create a new block index entry for a given block hash. More...
 
bool FlushStateToDisk ()
 Flush all state, indexes and buffers to disk. More...
 
void PruneAndFlush ()
 Prune block files and flush state to disk. More...
 
void PruneBlockFilesManual (int nManualPruneHeight)
 Prune block files up to a given height. More...
 
bool IsConfirmedInNPrevBlocks (const CDiskTxPos &txindex, const CBlockIndex *pindexFrom, int nMaxDepth, int &nActualDepth)
 Check if the transaction is confirmed in N previous blocks. More...
 
bool AcceptToMemoryPool (CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced=nullptr, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0, bool rawTx=false)
 (try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions replaced from mempool More...
 
bool AcceptToMemoryPoolWithTime (CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, int64_t nAcceptTime, std::list< CTransactionRef > *plTxnReplaced=NULL, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0, bool rawTx=false)
 (try to) add transaction to memory pool with a specified acceptance time More...
 
std::string FormatStateMessage (const CValidationState &state)
 Convert CValidationState to a human-readable message for logging. 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...
 
unsigned int GetLegacySigOpCount (const CTransaction &tx)
 Count ECDSA signature operations the old-fashioned (pre-0.6) way. More...
 
unsigned int GetP2SHSigOpCount (const CTransaction &tx, const CCoinsViewCache &mapInputs)
 Count ECDSA signature operations in pay-to-script-hash inputs. More...
 
int64_t GetTransactionSigOpCost (const CTransaction &tx, const CCoinsViewCache &inputs, int flags)
 Compute total signature operation cost of a transaction. More...
 
bool CheckInputs (const CTransaction &tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks, unsigned int flags, bool cacheStore, PrecomputedTransactionData &txdata, std::vector< CScriptCheck > *pvChecks=NULL)
 Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts) This does not modify the UTXO set. More...
 
bool CheckTransaction (const CTransaction &tx, CValidationState &state, bool fCheckDuplicateInputs)
 Transaction validation functions. More...
 
bool Consensus::CheckTxInputs (const CTransaction &tx, CValidationState &state, const CCoinsViewCache &inputs, int nSpendHeight)
 Check whether all inputs of this transaction are valid (no double spends and amounts) This does not modify the UTXO set. More...
 
bool CheckTransactionTimestamp (const CTransaction &tx, const uint32_t &nTimeBlock, CBlockTreeDB &txdb)
 Check if coinstake transaction timestamp is bigger than the previous. More...
 
bool IsFinalTx (const CTransaction &tx, int nBlockHeight, int64_t nBlockTime)
 Check if transaction is final and can be included in a block with the specified height and time. More...
 
bool CheckFinalTx (const CTransaction &tx, int flags=-1)
 Check if transaction will be final in the next block to be created. More...
 
bool TestLockPointValidity (const LockPoints *lp)
 Test whether the LockPoints height and time are still valid on the current chain. More...
 
bool SequenceLocks (const CTransaction &tx, int flags, std::vector< int > *prevHeights, const CBlockIndex &block)
 Check if transaction is final per BIP 68 sequence numbers and can be included in a block. More...
 
bool CheckSequenceLocks (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. More...
 
void InitScriptExecutionCache ()
 Initializes the script-execution cache. More...
 
template<typename Block >
bool ReadBlockFromDisk (Block &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
 Functions for disk access for blocks. More...
 
bool ReadBlockFromDisk (CBlock &block, const CBlockIndex *pindex, const Consensus::Params &consensusParams)
 
bool ReadFromDisk (CBlockHeader &block, unsigned int nFile, unsigned int nBlockPos)
 
bool ReadFromDisk (CMutableTransaction &tx, CDiskTxPos &txindex, CBlockTreeDB &txdb, COutPoint prevout)
 
bool CheckBlock (const CBlock &block, CValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
 Functions for validating blocks and updating the block tree. More...
 
bool GetBlockPublicKey (const CBlock &block, std::vector< unsigned char > &vchPubKey)
 
bool SignBlock (std::shared_ptr< CBlock > pblock, CWallet &wallet, const CAmount &nTotalFees, uint32_t nTime)
 
bool CheckCanonicalBlockSignature (const std::shared_ptr< const CBlock > pblock)
 
bool CheckIndexProof (const CBlockIndex &block, const Consensus::Params &consensusParams)
 
bool ContextualCheckBlockHeader (const CBlockHeader &block, CValidationState &state, const Consensus::Params &consensusParams, const CBlockIndex *pindexPrev, int64_t nAdjustedTime)
 Context-dependent validity checks. More...
 
bool TestBlockValidity (CValidationState &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, with cs_main held) More...
 
bool IsWitnessEnabled (const CBlockIndex *pindexPrev, const Consensus::Params &params)
 Check whether witness commitments are required for block. More...
 
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. More...
 
void UpdateUncommittedBlockStructures (CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
 Update uncommitted block structures (currently: only the witness nonce). 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...
 
bool ReplayBlocks (const CChainParams &params, CCoinsView *view)
 Replay blocks that aren't fully applied to the database. More...
 
CBlockIndexFindForkInGlobalIndex (const CChain &chain, const CBlockLocator &locator)
 Find the last common block between the parameter chain and a locator. More...
 
bool PreciousBlock (CValidationState &state, const CChainParams &params, CBlockIndex *pindex)
 Mark a block as precious and reorganize. More...
 
bool InvalidateBlock (CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex)
 Mark a block as invalid. More...
 
bool ResetBlockFailureFlags (CBlockIndex *pindex)
 Remove invalidity status from a block and its descendants. More...
 
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...
 
void DumpMempool ()
 Dump the mempool to disk. More...
 
bool LoadMempool ()
 Load the mempool from disk. More...
 
bool CheckReward (const CBlock &block, CValidationState &state, int nHeight, const Consensus::Params &consensusParams, CAmount nFees, CAmount gasRefunds, const std::vector< CTxOut > &vouts)
 
std::vector< ResultExecuteCallContract (const dev::Address &addrContract, std::vector< unsigned char > opcode, const dev::Address &sender=dev::Address(), uint64_t gasLimit=0)
 
bool CheckSenderScript (const CCoinsViewCache &view, const CTransaction &tx)
 
bool CheckMinGasPrice (std::vector< EthTransactionParams > &etps, const uint64_t &minGasPrice)
 
void EnforceContractVoutLimit (ByteCodeExecResult &bcer, ByteCodeExecResult &bcerOut, const dev::h256 &oldHashFascRoot, const dev::h256 &oldHashStateRoot, const std::vector< FascTransaction > &transactions)
 
void writeVMlog (const std::vector< ResultExecute > &res, const CTransaction &tx=CTransaction(), const CBlock &block=CBlock())
 

Variables

std::unique_ptr< FascStateglobalState
 Global state. More...
 
std::shared_ptr< dev::eth::SealEngineFaceglobalSealEngine
 
bool fRecordLogOpcodes
 
bool fIsVMlogFile
 
bool fGettingValuesDGP
 
CScript COINBASE_FLAGS
 Constant stuff for coinbase transactions we create: More...
 
CCriticalSection cs_main
 
CBlockPolicyEstimator feeEstimator
 
CTxMemPool mempool
 
BlockMap mapBlockIndex
 
uint64_t nLastBlockTx
 
uint64_t nLastBlockWeight
 
const std::string strMessageMagic
 
CWaitableCriticalSection csBestBlock
 
CConditionVariable cvBlockChange
 
std::atomic_bool fImporting
 
bool fReindex
 
bool fLogEvents
 
int nScriptCheckThreads
 
bool fTxIndex
 
bool fIsBareMultisigStd
 
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...
 
CAmount maxTxFee
 Absolute maximum transaction fee (in liu) used by wallet and mempool (rejects high fee in sendrawtransaction) More...
 
int64_t nMaxTipAge
 If the tip is older than this (in seconds), the node is considered to be in initial block download. More...
 
bool fEnableReplacement
 
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...
 
CChain chainActive
 The currently-connected chain of blocks (protected by cs_main). More...
 
CCoinsViewDBpcoinsdbview
 Global variable that points to the coins database (protected by cs_main) More...
 
CCoinsViewCachepcoinsTip
 Global variable that points to the active CCoinsView (protected by cs_main) More...
 
CBlockTreeDBpblocktree
 Global variable that points to the active block tree (protected by cs_main) More...
 
StorageResultspstorageresult
 
VersionBitsCache versionbitscache
 

Typedef Documentation

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

Definition at line 198 of file validation.h.

using ExtractFascTX = std::pair<std::vector<FascTransaction>, std::vector<EthTransactionParams>>

Definition at line 50 of file validation.h.

using valtype = std::vector<unsigned char>

Definition at line 49 of file validation.h.

Function Documentation

bool AcceptToMemoryPool ( CTxMemPool pool,
CValidationState state,
const CTransactionRef tx,
bool  fLimitFree,
bool *  pfMissingInputs,
std::list< CTransactionRef > *  plTxnReplaced = nullptr,
bool  fOverrideMempoolLimit = false,
const CAmount  nAbsurdFee = 0,
bool  rawTx = false 
)

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

Definition at line 1096 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool AcceptToMemoryPoolWithTime ( CTxMemPool pool,
CValidationState state,
const CTransactionRef tx,
bool  fLimitFree,
bool *  pfMissingInputs,
int64_t  nAcceptTime,
std::list< CTransactionRef > *  plTxnReplaced = NULL,
bool  fOverrideMempoolLimit = false,
const CAmount  nAbsurdFee = 0,
bool  rawTx = false 
)

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

Here is the caller graph for this function:

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

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

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

Here is the call graph for this function:

Here is the caller graph for this function:

std::vector<ResultExecute> CallContract ( const dev::Address addrContract,
std::vector< unsigned char >  opcode,
const dev::Address sender = dev::Address(),
uint64_t  gasLimit = 0 
)

Definition at line 2689 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckBlock ( const CBlock block,
CValidationState 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 3770 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckCanonicalBlockSignature ( const std::shared_ptr< const CBlock pblock)

Definition at line 4250 of file validation.cpp.

Here is the caller graph for this function:

bool CheckDiskSpace ( uint64_t  nAdditionalBytes = 0)

Check whether enough disk space is available for an incoming block.

Definition at line 4485 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckFinalTx ( const CTransaction 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 271 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckIndexProof ( const CBlockIndex block,
const Consensus::Params consensusParams 
)

Here is the caller graph for this function:

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

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 NULL, script checks are pushed onto it instead of being performed inline.

Here is the caller graph for this function:

bool CheckMinGasPrice ( std::vector< EthTransactionParams > &  etps,
const uint64_t &  minGasPrice 
)

Definition at line 2720 of file validation.cpp.

Here is the caller graph for this function:

bool CheckReward ( const CBlock block,
CValidationState state,
int  nHeight,
const Consensus::Params consensusParams,
CAmount  nFees,
CAmount  gasRefunds,
const std::vector< CTxOut > &  vouts 
)

Definition at line 2728 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckSenderScript ( const CCoinsViewCache view,
const CTransaction tx 
)

Definition at line 2681 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckSequenceLocks ( 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 321 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckTransaction ( const CTransaction tx,
CValidationState state,
bool  fCheckDuplicateInputs 
)

Transaction validation functions.

Context-independent validity checks

!!? if (GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)

Definition at line 161 of file tx_verify.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool CheckTransactionTimestamp ( const CTransaction tx,
const uint32_t &  nTimeBlock,
CBlockTreeDB txdb 
)

Check if coinstake transaction timestamp is bigger than the previous.

Here is the caller graph for this function:

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

Determine what nVersion a new block should use.

Definition at line 1820 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ContextualCheckBlockHeader ( const CBlockHeader block,
CValidationState state,
const Consensus::Params consensusParams,
const CBlockIndex pindexPrev,
int64_t  nAdjustedTime 
)

Context-dependent validity checks.

By "context", we mean only the previous block headers, but not the UTXO set; UTXO-related validity checks are done in ConnectBlock().

Here is the caller graph for this function:

void DumpMempool ( )

Dump the mempool to disk.

Definition at line 5543 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void EnforceContractVoutLimit ( ByteCodeExecResult bcer,
ByteCodeExecResult bcerOut,
const dev::h256 oldHashFascRoot,
const dev::h256 oldHashStateRoot,
const std::vector< FascTransaction > &  transactions 
)
CBlockIndex* FindForkInGlobalIndex ( const CChain chain,
const CBlockLocator locator 
)

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

Definition at line 233 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool FlushStateToDisk ( )

Flush all state, indexes and buffers to disk.

Definition at line 2543 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

std::string FormatStateMessage ( const CValidationState state)

Convert CValidationState to a human-readable message for logging.

Definition at line 407 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t FutureDrift ( uint32_t  nTime)
inline

Definition at line 258 of file validation.h.

Here is the call graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

CBlockFileInfo* GetBlockFileInfo ( size_t  n)

Get block file info entry for one block file.

Definition at line 5452 of file validation.cpp.

Here is the caller graph for this function:

fs::path GetBlockPosFilename ( const CDiskBlockPos pos,
const char *  prefix 
)

Translation to a filesystem path.

Definition at line 4528 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool GetBlockPublicKey ( const CBlock block,
std::vector< unsigned char > &  vchPubKey 
)

Here is the caller graph for this function:

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

Definition at line 1270 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned int GetLegacySigOpCount ( const CTransaction tx)

Count ECDSA signature operations the old-fashioned (pre-0.6) way.

Returns
number of sigops this transaction's outputs will produce when spent
See also
CTransaction::FetchInputs

Count ECDSA signature operations the old-fashioned (pre-0.6) way.

Count ECDSA signature operations the old-fashioned (pre-0.6) way

Returns
number of sigops this transaction's outputs will produce when spent
See also
CTransaction::FetchInputs

Definition at line 109 of file tx_verify.cpp.

Here is the caller graph for this function:

unsigned int GetP2SHSigOpCount ( const CTransaction tx,
const CCoinsViewCache mapInputs 
)

Count ECDSA signature operations in pay-to-script-hash inputs.

Parameters
[in]mapInputsMap of previous transactions that have outputs we're spending
Returns
maximum number of sigops required to validate this transaction's inputs
See also
CTransaction::FetchInputs

Definition at line 123 of file tx_verify.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool GetTransaction ( const uint256 hash,
CTransactionRef txOut,
const Consensus::Params consensusParams,
uint256 hashBlock,
bool  fAllowSlow 
)

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

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

Definition at line 1105 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

int64_t GetTransactionSigOpCost ( const CTransaction tx,
const CCoinsViewCache inputs,
int  flags 
)

Compute total signature operation cost of a transaction.

Parameters
[in]txTransaction for which we are computing the cost
[in]inputsMap of previous transactions that have outputs we're spending
[out]flagsScript verification flags
Returns
Total signature operation cost of tx

Definition at line 140 of file tx_verify.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

std::string GetWarnings ( const std::string &  strFor)

Format a string that describes several potential problems detected by the core.

strFor can have three values:

  • "rpc": get critical warnings, which should put the client in safe mode if non-empty
  • "statusbar": get all warnings
  • "gui": get all warnings, translated (where possible) for GUI This function only returns the highest priority warning of the set selected by strFor.

Definition at line 40 of file warnings.cpp.

Here is the caller graph for this function:

double GuessVerificationProgress ( const ChainTxData data,
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 5591 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool InitBlockIndex ( const CChainParams chainparams)

Initialize a new block tree database + block data on disk.

Definition at line 5067 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void InitScriptExecutionCache ( )

Initializes the script-execution cache.

Definition at line 1482 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

CBlockIndex* InsertBlockIndex ( uint256  hash)

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

Definition at line 4533 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Mark a block as invalid.

Definition at line 3471 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool IsConfirmedInNPrevBlocks ( const CDiskTxPos txindex,
const CBlockIndex pindexFrom,
int  nMaxDepth,
int &  nActualDepth 
)

Check if the transaction is confirmed in N previous blocks.

Definition at line 1083 of file validation.cpp.

Here is the caller graph for this function:

bool IsFinalTx ( const CTransaction tx,
int  nBlockHeight,
int64_t  nBlockTime 
)

Check if transaction is final and can be included in a block with the specified height and time.

Consensus critical.

Definition at line 19 of file tx_verify.cpp.

Here is the caller graph for this function:

bool IsInitialBlockDownload ( )

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

Definition at line 1295 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Check whether witness commitments are required for block.

Definition at line 3844 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool LoadChainTip ( const CChainParams chainparams)

Update the chain tip based on database information.

Definition at line 4671 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Import blocks from an external file.

Definition at line 5143 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool LoadGenesisBlock ( const CChainParams chainparams)

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

Definition at line 5111 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool LoadMempool ( )

Load the mempool from disk.

Definition at line 5477 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Definition at line 4519 of file validation.cpp.

Here is the caller graph for this function:

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

Mark a block as precious and reorganize.

Definition at line 3442 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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.

Call without cs_main held.

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
True if state.IsValid()

Definition at line 4261 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Process incoming block headers.

Call without cs_main held.

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
[out]first_invalidFirst header that fails validation, if one exists

Definition at line 4122 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void PruneAndFlush ( )

Prune block files and flush state to disk.

Definition at line 2549 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void PruneBlockFilesManual ( int  nManualPruneHeight)

Prune block files up to a given height.

Definition at line 4416 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void PruneOneBlockFile ( const int  fileNumber)

Mark one block file as pruned.

Definition at line 4351 of file validation.cpp.

Here is the caller graph for this function:

template<typename Block >
bool ReadBlockFromDisk ( Block block,
const CDiskBlockPos pos,
const Consensus::Params consensusParams 
)

Functions for disk access for blocks.

Definition at line 1191 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 1222 of file validation.cpp.

Here is the call graph for this function:

bool ReadFromDisk ( CBlockHeader block,
unsigned int  nFile,
unsigned int  nBlockPos 
)

Definition at line 1232 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ReadFromDisk ( CMutableTransaction tx,
CDiskTxPos txindex,
CBlockTreeDB txdb,
COutPoint  prevout 
)

Definition at line 1258 of file validation.cpp.

Here is the call graph for this function:

bool ReplayBlocks ( const CChainParams params,
CCoinsView view 
)

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

Definition at line 4848 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool ResetBlockFailureFlags ( CBlockIndex pindex)

Remove invalidity status from a block and its descendants.

Definition at line 3541 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

bool SequenceLocks ( const CTransaction tx,
int  flags,
std::vector< int > *  prevHeights,
const CBlockIndex block 
)

Check if transaction is final per BIP 68 sequence numbers and can be included in a block.

Consensus critical. Takes as input a list of heights at which tx's inputs (in order) confirmed.

Definition at line 104 of file tx_verify.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool SignBlock ( std::shared_ptr< CBlock pblock,
CWallet wallet,
const CAmount nTotalFees,
uint32_t  nTime 
)

Here is the caller graph for this function:

bool TestBlockValidity ( CValidationState 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, with cs_main held)

Definition at line 4304 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

bool TestLockPointValidity ( const LockPoints lp)

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

Definition at line 303 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void ThreadScriptCheck ( )

Run an instance of the script checking thread.

Definition at line 1812 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Actually unlink the specified files.

Definition at line 4383 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

void UnloadBlockIndex ( )

Unload database information.

Definition at line 5010 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

This is safe for submitted blocks.

Definition at line 3865 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

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

Definition at line 5457 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

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

Here is the call graph for this function:

Here is the caller graph for this function:

void writeVMlog ( const std::vector< ResultExecute > &  res,
const CTransaction tx = CTransaction(),
const CBlock block = CBlock() 
)

Definition at line 2830 of file validation.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

CChain chainActive

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

Definition at line 80 of file validation.cpp.

CScript COINBASE_FLAGS

Constant stuff for coinbase transactions we create:

Definition at line 113 of file validation.cpp.

Definition at line 77 of file validation.cpp.

Definition at line 82 of file validation.cpp.

CConditionVariable cvBlockChange

Definition at line 83 of file validation.cpp.

bool fCheckBlockIndex

Definition at line 93 of file validation.cpp.

bool fCheckpointsEnabled

Definition at line 94 of file validation.cpp.

CBlockPolicyEstimator feeEstimator

Definition at line 106 of file validation.cpp.

bool fEnableReplacement

Definition at line 98 of file validation.cpp.

bool fGettingValuesDGP

Definition at line 74 of file validation.cpp.

bool fHavePruned

Pruning-related variables and constants.

True if any block files have ever been pruned.

Definition at line 89 of file validation.cpp.

std::atomic_bool fImporting
bool fIsBareMultisigStd

Definition at line 91 of file validation.cpp.

bool fIsVMlogFile

Definition at line 73 of file validation.cpp.

bool fLogEvents

Definition at line 88 of file validation.cpp.

bool fPruneMode

True if we're running in -prune mode.

Definition at line 90 of file validation.cpp.

bool fRecordLogOpcodes

Definition at line 72 of file validation.cpp.

bool fReindex

Definition at line 86 of file validation.cpp.

bool fRequireStandard

Definition at line 92 of file validation.cpp.

bool fTxIndex

Definition at line 87 of file validation.cpp.

std::shared_ptr<dev::eth::SealEngineFace> globalSealEngine

Definition at line 71 of file validation.cpp.

std::unique_ptr<FascState> globalState

Global state.

Definition at line 70 of file validation.cpp.

uint256 hashAssumeValid

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

Definition at line 100 of file validation.cpp.

BlockMap mapBlockIndex

Definition at line 79 of file validation.cpp.

CAmount maxTxFee

Absolute maximum transaction fee (in liu) used by wallet and mempool (rejects high fee in sendrawtransaction)

Definition at line 104 of file validation.cpp.

CTxMemPool mempool
CFeeRate minRelayTxFee

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

Definition at line 103 of file validation.cpp.

size_t nCoinCacheUsage

Definition at line 95 of file validation.cpp.

uint64_t nLastBlockTx

Definition at line 62 of file miner.cpp.

uint64_t nLastBlockWeight

Definition at line 63 of file miner.cpp.

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

arith_uint256 nMinimumChainWork

Minimum work we will assume exists on some valid chain.

Definition at line 101 of file validation.cpp.

uint64_t nPruneTarget

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

Definition at line 96 of file validation.cpp.

int nScriptCheckThreads

Definition at line 84 of file validation.cpp.

CBlockTreeDB* pblocktree

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

Definition at line 253 of file validation.cpp.

CCoinsViewDB* pcoinsdbview

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

Definition at line 251 of file validation.cpp.

CCoinsViewCache* pcoinsTip

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

Definition at line 252 of file validation.cpp.

CBlockIndex* pindexBestHeader

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

Definition at line 81 of file validation.cpp.

StorageResults* pstorageresult

Definition at line 254 of file validation.cpp.

const std::string strMessageMagic

Definition at line 115 of file validation.cpp.

VersionBitsCache versionbitscache

Definition at line 1818 of file validation.cpp.