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.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2015 The Bitcoin Core developers
3 // Copyright (c) 2014-2020 The Dash Core developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef BITCOIN_VALIDATION_H
8 #define BITCOIN_VALIDATION_H
9 
10 #if defined(HAVE_CONFIG_H)
11 #include <config/dash-config.h>
12 #endif
13 
14 #include <amount.h>
15 #include <coins.h>
16 #include <fs.h>
17 #include <protocol.h> // For CMessageHeader::MessageStartChars
18 #include <policy/feerate.h>
19 #include <script/script_error.h>
20 #include <sync.h>
21 #include <versionbits.h>
22 #include <spentindex.h>
23 
24 #include <algorithm>
25 #include <exception>
26 #include <map>
27 #include <memory>
28 #include <set>
29 #include <stdint.h>
30 #include <string>
31 #include <utility>
32 #include <vector>
33 
34 #include <atomic>
35 
36 class CBlockIndex;
37 class CBlockTreeDB;
38 class CChainParams;
39 class CCoinsViewDB;
40 class CInv;
41 class CConnman;
42 class CScriptCheck;
44 class CTxMemPool;
45 class CValidationState;
47 struct ChainTxData;
48 
49 struct LockPoints;
50 
52 static const bool DEFAULT_WHITELISTRELAY = true;
54 static const bool DEFAULT_WHITELISTFORCERELAY = true;
56 static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
60 static const CAmount HIGH_TX_FEE_PER_KB = 0.01 * COIN;
64 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
66 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
68 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
70 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
72 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
74 static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
76 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
78 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
80 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
81 
83 static const int MAX_SCRIPTCHECK_THREADS = 16;
85 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
87 static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
89 static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
92 static const unsigned int MAX_HEADERS_RESULTS = 2000;
95 static const int MAX_CMPCTBLOCK_DEPTH = 5;
97 static const int MAX_BLOCKTXN_DEPTH = 10;
102 static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
104 static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
106 static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
108 static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
110 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
112 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
113 
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
116 static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
117 
119 static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
120 static const unsigned int DEFAULT_BYTES_PER_SIGOP = 20;
121 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
122 static const bool DEFAULT_TXINDEX = true;
123 static const bool DEFAULT_ADDRESSINDEX = false;
124 static const bool DEFAULT_TIMESTAMPINDEX = false;
125 static const bool DEFAULT_SPENTINDEX = false;
126 static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
128 static const bool DEFAULT_PERSIST_MEMPOOL = true;
130 static const bool DEFAULT_SYNC_MEMPOOL = true;
131 
133 static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
134 
136 static const int MAX_UNCONNECTING_HEADERS = 10;
137 
138 static const bool DEFAULT_PEERBLOOMFILTERS = true;
139 
141 static const int DEFAULT_STOPATHEIGHT = 0;
142 
144 {
145  size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
146 };
147 
148 extern CScript COINBASE_FLAGS;
151 extern CTxMemPool mempool;
152 typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
153 typedef std::unordered_multimap<uint256, CBlockIndex*, BlockHasher> PrevBlockMap;
154 extern BlockMap& mapBlockIndex;
156 extern uint64_t nLastBlockTx;
157 extern uint64_t nLastBlockSize;
158 extern const std::string strMessageMagic;
161 extern uint256 g_best_block;
162 extern std::atomic_bool fImporting;
163 extern std::atomic_bool fReindex;
164 extern int nScriptCheckThreads;
165 extern bool fTxIndex;
166 extern bool fAddressIndex;
167 extern bool fTimestampIndex;
168 extern bool fSpentIndex;
169 extern bool fIsBareMultisigStd;
170 extern bool fRequireStandard;
171 extern unsigned int nBytesPerSigOp;
172 extern bool fCheckBlockIndex;
173 extern bool fCheckpointsEnabled;
174 extern size_t nCoinCacheUsage;
176 extern CFeeRate minRelayTxFee;
178 extern CAmount maxTxFee;
180 extern int64_t nMaxTipAge;
181 
182 extern bool fLargeWorkForkFound;
183 extern bool fLargeWorkInvalidChainFound;
184 
185 extern std::atomic<bool> fDIP0001ActiveAtTip;
186 
188 extern uint256 hashAssumeValid;
189 
192 
195 
197 static const uint64_t nMinDiskSpace = 52428800;
198 
201 extern bool fHavePruned;
203 extern bool fPruneMode;
205 extern uint64_t nPruneTarget;
207 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
209 static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
210 
211 static const signed int DEFAULT_CHECKBLOCKS = 6;
212 static const unsigned int DEFAULT_CHECKLEVEL = 3;
213 
214 // Require that user allocate at least 945MB for block & undo files (blk???.dat and rev???.dat)
215 // At 2MB per block, 288 blocks = 576MB.
216 // Add 15% for Undo data = 662MB
217 // Add 20% for Orphan block rate = 794MB
218 // We want the low water mark after pruning to be at least 794 MB and since we prune in
219 // full block file chunks, we need the high water mark which triggers the prune to be
220 // one 128MB block file + added 15% undo data = 147MB greater for a total of 941MB
221 // Setting the target to > than 945MB will make it likely we can respect the target.
222 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 945 * 1024 * 1024;
223 
243 bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock);
244 
256 bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex=nullptr, CBlockHeader *first_invalid=nullptr);
257 
259 bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
261 FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
263 fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
265 bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = nullptr);
267 bool LoadGenesisBlock(const CChainParams& chainparams);
270 bool LoadBlockIndex(const CChainParams& chainparams);
272 bool LoadChainTip(const CChainParams& chainparams);
274 void UnloadBlockIndex();
276 void ThreadScriptCheck();
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>());
283 
284 double ConvertBitsToDouble(unsigned int nBits);
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 */);
287 
289 double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex* pindex);
290 
292 uint64_t CalculateCurrentUsage();
293 
297 void PruneOneBlockFile(const int fileNumber);
298 
302 void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune);
303 
305 void FlushStateToDisk();
307 void PruneAndFlush();
309 void PruneBlockFilesManual(int nManualPruneHeight);
310 
312 bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx,
313  bool* pfMissingInputs, bool bypass_limits,
314  const CAmount nAbsurdFee, bool fDryRun=false);
315 static bool AcceptToMemoryPoolWithTime(const CChainParams& chainparams, CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx,
316  bool* pfMissingInputs, int64_t nAcceptTime, bool bypass_limits,
317  const CAmount nAbsurdFee, bool fDryRun = false);
318 
319 bool GetUTXOCoin(const COutPoint& outpoint, Coin& coin);
320 int GetUTXOHeight(const COutPoint& outpoint);
321 int GetUTXOConfirmations(const COutPoint& outpoint);
322 
324 std::string FormatStateMessage(const CValidationState &state);
325 
328 
331 
334 
336 void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
337 
347 bool CheckFinalTx(const CTransaction &tx, int flags = -1);
348 
352 bool TestLockPointValidity(const LockPoints* lp);
353 
365 bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false);
366 
372 {
373 private:
376  unsigned int nIn;
377  unsigned int nFlags;
381 
382 public:
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) { }
386 
387  bool operator()();
388 
389  void swap(CScriptCheck &check) {
390  std::swap(ptxTo, check.ptxTo);
391  std::swap(m_tx_out, check.m_tx_out);
392  std::swap(nIn, check.nIn);
393  std::swap(nFlags, check.nFlags);
394  std::swap(cacheStore, check.cacheStore);
395  std::swap(error, check.error);
396  std::swap(txdata, check.txdata);
397  }
398 
399  ScriptError GetScriptError() const { return error; }
400 };
401 
402 bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector<uint256> &hashes);
404 bool GetAddressIndex(uint160 addressHash, int type,
405  std::vector<std::pair<CAddressIndexKey, CAmount> > &addressIndex,
406  int start = 0, int end = 0);
407 bool GetAddressUnspent(uint160 addressHash, int type,
408  std::vector<std::pair<CAddressUnspentKey, CAddressUnspentValue> > &unspentOutputs);
411 
412 
414 bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams);
415 bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
416 
420 bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
421 
423 bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
424 
426 class CVerifyDB {
427 public:
428  CVerifyDB();
429  ~CVerifyDB();
430  bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
431 };
432 
434 bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
435 
437 CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
438 
440 bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex);
441 
443 bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
444 
446 bool ResetBlockFailureFlags(CBlockIndex *pindex);
447 
449 extern CChain& chainActive;
450 
452 extern std::unique_ptr<CCoinsViewDB> pcoinsdbview;
453 
455 extern std::unique_ptr<CCoinsViewCache> pcoinsTip;
456 
458 extern std::unique_ptr<CBlockTreeDB> pblocktree;
459 
465 int GetSpendHeight(const CCoinsViewCache& inputs);
466 
468 
472 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params, bool fCheckMasternodesUpgraded = false);
473 
478 bool GetBlockHash(uint256& hashRet, int nBlockHeight = -1);
479 
484 static const unsigned int REJECT_INTERNAL = 0x100;
486 static const unsigned int REJECT_HIGHFEE = 0x100;
487 
490 
492 bool DumpMempool();
493 
495 bool LoadMempool();
496 
497 #endif // BITCOIN_VALIDATION_H
PrevBlockMap & mapPrevBlockIndex
Definition: validation.cpp:216
bool fTimestampIndex
Definition: validation.cpp:227
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
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
size_t nCoinCacheUsage
Definition: validation.cpp:236
static const int MAX_BLOCKTXN_DEPTH
Maximum depth of blocks we&#39;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
double ConvertBitsToDouble(unsigned int nBits)
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.
enum ScriptError_t ScriptError
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:127
void PruneOneBlockFile(const int fileNumber)
Mark one block file as pruned.
bool fTxIndex
Definition: validation.cpp:225
void swap(CScriptCheck &check)
Definition: validation.h:389
A UTXO entry.
Definition: coins.h:29
Definition: block.h:72
static const CAmount DEFAULT_TRANSACTION_MAXFEE
-maxtxfee default
Definition: validation.h:58
An in-memory indexed chain of blocks.
Definition: chain.h:442
bool VerifyDB(const CChainParams &chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE
Maximum kilobytes for transactions to store for processing during reorg.
Definition: validation.h:74
bool fAddressIndex
Definition: validation.cpp:226
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
unsigned int nFlags
Definition: validation.h:377
static const int64_t DEFAULT_MAX_TIP_AGE
Definition: validation.h:114
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
inv message data
Definition: protocol.h:429
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
static const CAmount COIN
Definition: amount.h:14
CBlockIndex * pindexBestHeader
Best header we&#39;ve seen so far (used for getheaders queries&#39; 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.
const char * prefix
Definition: rest.cpp:574
bool ResetBlockFailureFlags(CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
CBlockPolicyEstimator feeEstimator
Definition: validation.cpp:249
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.
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 &params, CBlockIndex *pindex)
Mark a block as precious and reorganize.
std::unordered_multimap< uint256, CBlockIndex *, BlockHasher > PrevBlockMap
Definition: validation.h:153
sph_u32 high
Definition: keccak.c:370
CConditionVariable g_best_block_cv
Definition: validation.cpp:220
BlockMap & mapBlockIndex
Definition: validation.cpp:215
int flags
Definition: dash-tx.cpp:462
bool ProcessNewBlockHeaders(const std::vector< CBlockHeader > &block, CValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=nullptr, CBlockHeader *first_invalid=nullptr)
Process incoming block headers.
bool fSpentIndex
Definition: validation.cpp:228
CChainParams defines various tweakable parameters of a given instance of the Dash system...
Definition: chainparams.h:41
ScriptError error
Definition: validation.h:379
ThresholdState
Definition: versionbits.h:20
static const uint64_t nMinDiskSpace
Minimum disk space required - used in CheckDiskSpace()
Definition: validation.h:197
bool LoadMempool()
Load the mempool from disk.
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
bool cacheStore
Definition: validation.h:378
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:345
CAmount GetMasternodePayment(int nHeight, CAmount blockValue, int nReallocActivationHeight=std::numeric_limits< int >::max())
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.
CTxOut m_tx_out
Definition: validation.h:374
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...
bool CheckFinalTx(const CTransaction &tx, int flags=-1)
Transaction validation functions.
Definition: validation.cpp:317
static const bool DEFAULT_ADDRESSINDEX
Definition: validation.h:123
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
CCriticalSection cs_main
Definition: validation.cpp:213
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
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
unsigned int nBytesPerSigOp
Definition: validation.cpp:233
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...
bool InvalidateBlock(CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex)
Mark a block as invalid.
false
Definition: bls_dkg.cpp:168
static const bool DEFAULT_PERSIST_MEMPOOL
Default for -persistmempool.
Definition: validation.h:128
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:138
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
bool fLargeWorkForkFound
Definition: warnings.cpp:14
static const bool DEFAULT_WHITELISTRELAY
Default for -whitelistrelay.
Definition: validation.h:52
Access to the block database (blocks/index/)
Definition: txdb.h:114
static const unsigned int BLOCKFILE_CHUNK_SIZE
The pre-allocation chunk size for blk?????.dat files (since 0.8)
Definition: validation.h:78
Abstract view on the open txout dataset.
Definition: coins.h:145
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params &params, uint256 &hashBlock, bool fAllowSlow=false, CBlockIndex *blockIndex=nullptr)
Retrieve a transaction (from memory pool, or from disk, if possible)
Definition: validation.cpp:950
DeploymentPos
Definition: params.h:15
bool fHavePruned
Pruning-related variables and constants.
Definition: validation.cpp:229
void InitScriptExecutionCache()
Initializes the script-execution cache.
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&#39;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
CWaitableCriticalSection g_best_block_mutex
Definition: validation.cpp:219
fs::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
Translation to a filesystem path.
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
std::atomic< bool > fDIP0001ActiveAtTip
Definition: validation.cpp:240
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&#39;re running with -reindex...
static const unsigned int DEFAULT_MEMPOOL_EXPIRY
Default for -mempoolexpiry, expiration time for mempool transactions in hours.
Definition: validation.h:72
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:141
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
Definition: net.h:136
bool operator()()
An output of a transaction.
Definition: transaction.h:144
ThresholdState VersionBitsTipState(const Consensus::Params &params, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment at the current tip.
std::atomic_bool fImporting
bool GetTimestampIndex(const unsigned int &high, const unsigned int &low, std::vector< uint256 > &hashes)
Definition: validation.cpp:897
Parameters that influence chain consensus.
Definition: params.h:130
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
static const bool DEFAULT_SYNC_MEMPOOL
Default for -syncmempool.
Definition: validation.h:130
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.
Definition: validation.cpp:513
bool ReplayBlocks(const CChainParams &params, CCoinsView *view)
Replay blocks that aren&#39;t fully applied to the database.
size_t operator()(const uint256 &hash) const
Definition: validation.h:145
256-bit unsigned big integer.
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
int GetUTXOHeight(const COutPoint &outpoint)
Definition: validation.cpp:449
bool GetUTXOCoin(const COutPoint &outpoint, Coin &coin)
Definition: validation.cpp:439
uint64_t nPruneTarget
Number of MiB of block files that we&#39;re trying to stay below.
Definition: validation.cpp:237
uint256 g_best_block
Definition: validation.cpp:221
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
uint64_t nLastBlockSize
Definition: miner.cpp:57
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
Definition: validation.cpp:246
std::atomic_bool fReindex
bool GetBlockHash(uint256 &hashRet, int nBlockHeight=-1)
Return true if hash can be found in chainActive at nBlockHeight height.
bool fLargeWorkInvalidChainFound
Definition: warnings.cpp:15
Capture information about block/transaction validation.
Definition: validation.h:22
256-bit opaque blob.
Definition: uint256.h:123
const CTransaction * ptxTo
Definition: validation.h:375
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)
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 &params, bool fCheckMasternodesUpgraded=false)
Determine what nVersion a new block should use.
bool fRequireStandard
Definition: validation.cpp:232
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:170
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:389
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:211
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:71
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.
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.
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
static const bool DEFAULT_TIMESTAMPINDEX
Definition: validation.h:124
sph_u32 low
Definition: keccak.c:370
CAmount GetBlockSubsidy(int nBits, int nHeight, const Consensus::Params &consensusParams, bool fSuperblockPartOnly=false)
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
void PruneAndFlush()
Prune block files and flush state to disk.
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:19
160-bit opaque blob.
Definition: uint256.h:112
void ThreadScriptCheck()
Run an instance of the script checking thread.
bool fIsBareMultisigStd
Definition: validation.cpp:231
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
unsigned int nIn
Definition: validation.h:376
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 bool DEFAULT_SPENTINDEX
Definition: validation.h:125
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&#39;re willing to serve as compact blocks to peers when requested.
Definition: validation.h:95
int nScriptCheckThreads
Definition: validation.cpp:222
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
bool fPruneMode
True if we&#39;re running in -prune mode.
Definition: validation.cpp:230
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().
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 t...
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
const std::string strMessageMagic
Definition: validation.cpp:257
bool fCheckpointsEnabled
Definition: validation.cpp:235
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.
static const bool DEFAULT_WHITELISTFORCERELAY
Default for -whitelistforcerelay.
Definition: validation.h:54
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
VersionBitsCache versionbitscache
ScriptError GetScriptError() const
Definition: validation.h:399
bool DumpMempool()
Dump the mempool to disk.
uint64_t nLastBlockTx
Definition: miner.cpp:56
std::unique_ptr< CBlockTreeDB > pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: validation.cpp:301
static const bool DEFAULT_TXINDEX
Definition: validation.h:122
void UnloadBlockIndex()
Unload database information.
bool LoadChainTip(const CChainParams &chainparams)
Update the chain tip based on database information.
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.
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: validation.cpp:300
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:212
bool fCheckBlockIndex
Definition: validation.cpp:234
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
static const unsigned int REJECT_HIGHFEE
Too high fee.
Definition: validation.h:486
PrecomputedTransactionData * txdata
Definition: validation.h:380
Released under the MIT license