Dash Core Source Documentation (0.16.0.1)
Find detailed information regarding the Dash Core source code.
validation.h
Go to the documentation of this file.
114 static const int64_t DEFAULT_MAX_TIP_AGE = 6 * 60 * 60; // ~144 blocks behind -> 2 x fork detection time, was 24 * 60 * 60 in bitcoin
243 bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock);
256 bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex=nullptr, CBlockHeader *first_invalid=nullptr);
265 bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = nullptr);
280 bool GetTransaction(const uint256& hash, CTransactionRef& tx, const Consensus::Params& params, uint256& hashBlock, bool fAllowSlow = false, CBlockIndex* blockIndex = nullptr);
282 bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
285 CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params& consensusParams, bool fSuperblockPartOnly = false);
286 CAmount GetMasternodePayment(int nHeight, CAmount blockValue, int nReallocActivationHeight = std::numeric_limits<int>::max() /* not activated */);
315 static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx,
327 ThresholdState VersionBitsTipState(const Consensus::Params& params, Consensus::DeploymentPos pos);
330 BIP9Stats VersionBitsTipStatistics(const Consensus::Params& params, Consensus::DeploymentPos pos);
333 int VersionBitsTipStateSinceHeight(const Consensus::Params& params, Consensus::DeploymentPos pos);
365 bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false);
383 CScriptCheck(): ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
384 CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
385 m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
402 bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &hashes);
414 bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
415 bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
420 bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
423 bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
430 bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
443 bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
472 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params, bool fCheckMasternodesUpgraded = false);
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT
Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors.
Definition: validation.h:66
CTxMemPool mempool
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:85
Definition: versionbits.h:42
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
Definition: validation.cpp:2526
static const int MAX_BLOCKTXN_DEPTH
Maximum depth of blocks we're willing to respond to GETBLOCKTXN requests for.
Definition: validation.h:97
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
Definition: validation.h:76
static const unsigned int DEFAULT_DESCENDANT_LIMIT
Default for -limitdescendantcount, max number of in-mempool descendants.
Definition: validation.h:68
Definition: chain.h:85
int64_t nMaxTipAge
If the tip is older than this (in seconds), the node is considered to be in initial block download...
Definition: validation.cpp:238
std::condition_variable CConditionVariable
Just a typedef for std::condition_variable, can be wrapped later if desired.
Definition: sync.h:106
static const bool DEFAULT_PERMIT_BAREMULTISIG
Default for -permitbaremultisig.
Definition: validation.h:119
bool LoadExternalBlockFile(const CChainParams &chainparams, FILE *fileIn, CDiskBlockPos *dbp=nullptr)
Import blocks from an external file.
Definition: validation.cpp:4576
Definition: txmempool.h:40
enum ScriptError_t ScriptError
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:127
void PruneOneBlockFile(const int fileNumber)
Mark one block file as pruned.
Definition: validation.cpp:3886
Definition: script_error.h:12
Definition: block.h:72
bool VerifyDB(const CChainParams &chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
Definition: validation.cpp:4253
static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE
Maximum kilobytes for transactions to store for processing during reorg.
Definition: validation.h:74
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
Definition: validation.cpp:3874
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
Definition: validation.cpp:3953
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE
Block download timeout base, expressed in millionths of the block interval (i.e.
Definition: validation.h:110
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.cpp:218
static const unsigned int MIN_BLOCKS_TO_KEEP
Block files containing a block-height within MIN_BLOCKS_TO_KEEP of chainActive.Tip() will not be prun...
Definition: validation.h:207
static const unsigned int DEFAULT_ANCESTOR_LIMIT
Default for -limitancestorcount, max number of in-mempool ancestors.
Definition: validation.h:64
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.
Definition: validation.cpp:3417
Definition: interpreter.h:102
bool ResetBlockFailureFlags(CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
Definition: validation.cpp:3218
static const unsigned int MAX_REJECT_MESSAGE_LENGTH
Maximum length of reject messages.
Definition: validation.h:108
bool ProcessNewBlock(const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock)
Process an incoming block.
Definition: validation.cpp:3803
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator)
Find the last common block between the parameter chain and a locator.
Definition: validation.cpp:284
bool PreciousBlock(CValidationState &state, const CChainParams ¶ms, CBlockIndex *pindex)
Mark a block as precious and reorganize.
Definition: validation.cpp:3104
std::unordered_multimap< uint256, CBlockIndex *, BlockHasher > PrevBlockMap
Definition: validation.h:153
bool ProcessNewBlockHeaders(const std::vector< CBlockHeader > &block, CValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=nullptr, CBlockHeader *first_invalid=nullptr)
Process incoming block headers.
Definition: validation.cpp:3682
CChainParams defines various tweakable parameters of a given instance of the Dash system...
Definition: chainparams.h:41
static const uint64_t nMinDiskSpace
Minimum disk space required - used in CheckDiskSpace()
Definition: validation.h:197
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
Definition: validation.cpp:5035
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, int nReallocActivationHeight=std::numeric_limits< int >::max())
Definition: validation.cpp:1158
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.
Definition: validation.cpp:3072
BIP9Stats VersionBitsTipStatistics(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the numerical statistics for the BIP9 state for a given deployment at the current tip...
Definition: validation.cpp:4895
bool CheckFinalTx(const CTransaction &tx, int flags=-1)
Transaction validation functions.
Definition: validation.cpp:317
static bool AcceptToMemoryPoolWithTime(const CChainParams &chainparams, CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, int64_t nAcceptTime, bool bypass_limits, const CAmount nAbsurdFee, bool fDryRun=false)
CChain & chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:217
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:384
bool GetSpentIndex(CSpentIndexKey &key, CSpentIndexValue &value)
Definition: validation.cpp:908
static const unsigned int REJECT_INTERNAL
Reject codes greater or equal to this can be returned by AcceptToMemPool for transactions, to signal internal conditions.
Definition: validation.h:484
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...
Definition: validation.cpp:3837
bool InvalidateBlock(CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex)
Mark a block as invalid.
Definition: validation.cpp:3180
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
Definition: validation.cpp:1043
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER
Additional block download timeout per parallel downloading peer (i.e.
Definition: validation.h:112
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS
Minimum blocks required to signal NODE_NETWORK_LIMITED.
Definition: validation.h:209
Definition: versionbits.h:70
static const unsigned int BLOCKFILE_CHUNK_SIZE
The pre-allocation chunk size for blk?????.dat files (since 0.8)
Definition: validation.h:78
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params ¶ms, uint256 &hashBlock, bool fAllowSlow=false, CBlockIndex *blockIndex=nullptr)
Retrieve a transaction (from memory pool, or from disk, if possible)
Definition: validation.cpp:950
void InitScriptExecutionCache()
Initializes the script-execution cache.
Definition: validation.cpp:1409
static const int64_t MAX_FEE_ESTIMATION_TIP_AGE
Maximum age of our tip in seconds for us to be considered current for fee estimation.
Definition: validation.h:116
We want to be able to estimate feerates that are needed on tx's to be included in a certain number of...
Definition: fees.h:138
static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER
Number of blocks that can be requested at any given time from a single peer.
Definition: validation.h:87
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, bool bypass_limits, const CAmount nAbsurdFee, bool fDryRun=false)
(try to) add transaction to memory pool
Definition: validation.cpp:890
static const unsigned int DEFAULT_BYTES_PER_SIGOP
Definition: validation.h:120
fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
Translation to a filesystem path.
Definition: validation.cpp:4065
static const unsigned int MAX_HEADERS_RESULTS
Number of headers sent in one getheaders result.
Definition: validation.h:92
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:426
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE
Default for -minrelaytxfee, minimum relay fee for transactions.
Definition: validation.h:56
static const unsigned int UNDOFILE_CHUNK_SIZE
The pre-allocation chunk size for rev?????.dat files (since 0.8)
Definition: validation.h:80
Definition: chainparams.h:28
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT
Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.
Definition: validation.h:70
bool LoadBlockIndex(const CChainParams &chainparams)
Load the block tree and coins database from disk, initializing state if we're running with -reindex...
Definition: validation.cpp:4490
static const unsigned int DEFAULT_MEMPOOL_EXPIRY
Default for -mempoolexpiry, expiration time for mempool transactions in hours.
Definition: validation.h:72
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
Definition: validation.cpp:244
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain. ...
Definition: validation.cpp:349
ThresholdState VersionBitsTipState(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment at the current tip.
Definition: validation.cpp:4889
std::atomic_bool fImporting
bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector< uint256 > &hashes)
Definition: validation.cpp:897
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.
Definition: validation.cpp:513
bool ReplayBlocks(const CChainParams ¶ms, CCoinsView *view)
Replay blocks that aren't fully applied to the database.
Definition: validation.cpp:4451
static const unsigned int DATABASE_WRITE_INTERVAL
Time to wait (in seconds) between writing blocks/block index to disk.
Definition: validation.h:104
bool GetAddressUnspent(uint160 addressHash, int type, std::vector< std::pair< CAddressUnspentKey, CAddressUnspentValue > > &unspentOutputs)
Definition: validation.cpp:934
uint64_t nPruneTarget
Number of MiB of block files that we're trying to stay below.
Definition: validation.cpp:237
Definition: spentindex.h:42
Closure representing one script verification Note that this stores references to the spending transac...
Definition: validation.h:371
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.
Definition: validation.cpp:367
static const int MAX_UNCONNECTING_HEADERS
Maximum number of unconnecting headers announcements before DoS score.
Definition: validation.h:136
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
Definition: validation.cpp:246
Definition: validation.h:143
std::atomic_bool fReindex
bool GetBlockHash(uint256 &hashRet, int nBlockHeight=-1)
Return true if hash can be found in chainActive at nBlockHeight height.
Definition: validation.cpp:1894
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:121
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:442
FILE * OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly=false)
Open a block file (blk?????.dat)
Definition: validation.cpp:4056
Template mixin that adds -Wthread-safety locking annotations to a subset of the mutex API...
Definition: sync.h:54
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, bool fCheckMasternodesUpgraded=false)
Determine what nVersion a new block should use.
Definition: validation.cpp:1874
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
CAmount maxTxFee
Absolute maximum transaction fee (in duffs) used by wallet and mempool (rejects high fee in sendrawtr...
Definition: validation.cpp:247
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
Definition: validation.cpp:1386
uint256 hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:243
bool CheckDiskSpace(uint64_t nAdditionalBytes=0)
Check whether enough disk space is available for an incoming block.
Definition: validation.cpp:4022
static const CAmount HIGH_TX_FEE_PER_KB
Discourage users to set fees higher than this amount (in duffs) per kB.
Definition: validation.h:60
CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params &consensusParams, bool fSuperblockPartOnly=false)
Definition: validation.cpp:1108
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE
Maximum number of headers to announce when relaying blocks with headers message.
Definition: validation.h:133
std::unique_ptr< CCoinsViewDB > pcoinsdbview
Global variable that points to the coins database (protected by cs_main)
Definition: validation.cpp:299
Definition: spentindex.h:14
void ThreadScriptCheck()
Run an instance of the script checking thread.
Definition: validation.cpp:1866
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
Definition: validation.cpp:1219
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
Definition: validation.cpp:255
static const unsigned int DEFAULT_BANSCORE_THRESHOLD
Definition: validation.h:126
static const unsigned int BLOCK_STALLING_TIMEOUT
Timeout in seconds during which a peer must stall block download progress before being disconnected...
Definition: validation.h:89
static const int MAX_CMPCTBLOCK_DEPTH
Maximum depth of blocks we're willing to serve as compact blocks to peers when requested.
Definition: validation.h:95
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:198
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:152
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:201
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:222
int GetUTXOConfirmations(const COutPoint &outpoint)
Definition: validation.cpp:456
static const unsigned int DATABASE_FLUSH_INTERVAL
Time to wait (in seconds) between flushing chainstate to disk.
Definition: validation.h:106
int GetSpendHeight(const CCoinsViewCache &inputs)
Return the spend height, which is one more than the inputs.GetBestBlock().
Definition: validation.cpp:1398
int VersionBitsTipStateSinceHeight(const Consensus::Params ¶ms, Consensus::DeploymentPos pos)
Get the block height at which the BIP9 deployment switched into the state for the block building on t...
Definition: validation.cpp:4901
uint64_t GetCheapHash() const
A cheap hash function that just returns 64 bits from the result, it can be used when the contents are...
Definition: uint256.h:133
bool GetAddressIndex(uint160 addressHash, int type, std::vector< std::pair< CAddressIndexKey, CAmount > > &addressIndex, int start=0, int end=0)
Definition: validation.cpp:922
bool LoadGenesisBlock(const CChainParams &chainparams)
Ensures we have a genesis block in the block tree, possibly writing one to disk.
Definition: validation.cpp:4571
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: validation.h:54
Definition: chain.h:31
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
Definition: validation.cpp:4882
std::unique_ptr< CBlockTreeDB > pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: validation.cpp:301
bool LoadChainTip(const CChainParams &chainparams)
Update the chain tip based on database information.
Definition: validation.cpp:4214
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:20
static const unsigned int BLOCK_DOWNLOAD_WINDOW
Size of the "block download window": how far ahead of our current height do we fetch? Larger windows tolerate larger download speed differences between peer, but increase the potential degree of disordering of blocks on disk (which make reindexing and pruning harder).
Definition: validation.h:102
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
Definition: validation.cpp:3920
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: validation.cpp:300
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
Definition: sync.h:94
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of script-checking threads allowed.
Definition: validation.h:83
static const CAmount HIGH_MAX_TX_FEE
-maxtxfee will warn if called with a higher fee than this amount (in duffs)
Definition: validation.h:62