Dogecoin Core  1.14.2
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2016 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_VALIDATION_H
7 #define BITCOIN_VALIDATION_H
8 
9 #if defined(HAVE_CONFIG_H)
10 #include "config/bitcoin-config.h"
11 #endif
12 
13 #include "amount.h"
14 #include "chain.h"
15 #include "coins.h"
16 #include "protocol.h" // For CMessageHeader::MessageStartChars
17 #include "script/script_error.h"
18 #include "sync.h"
19 #include "versionbits.h"
20 
21 #include <algorithm>
22 #include <exception>
23 #include <map>
24 #include <set>
25 #include <stdint.h>
26 #include <string>
27 #include <utility>
28 #include <vector>
29 
30 #include <atomic>
31 
32 #include <boost/unordered_map.hpp>
33 #include <boost/filesystem/path.hpp>
34 
35 class CBlockIndex;
36 class CBlockTreeDB;
37 class CBloomFilter;
38 class CChainParams;
39 class CInv;
40 class CConnman;
41 class CScriptCheck;
42 class CTxMemPool;
44 class CValidationState;
45 struct ChainTxData;
46 
48 struct LockPoints;
49 
51 static const bool DEFAULT_ALERTS = true;
53 static const bool DEFAULT_WHITELISTRELAY = true;
55 static const bool DEFAULT_WHITELISTFORCERELAY = true;
57 static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = COIN;
59 static const CAmount DEFAULT_TRANSACTION_MAXFEE = 400 * COIN;
61 static const CAmount HIGH_TX_FEE_PER_KB = 25 * COIN;
63 static const CAmount HIGH_MAX_TX_FEE = 10 * HIGH_TX_FEE_PER_KB;
65 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
67 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
69 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
71 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
73 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 24;
75 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
77 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
79 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
80 
82 static const int MAX_SCRIPTCHECK_THREADS = 16;
84 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
86 static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
88 static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
91 static const unsigned int MAX_HEADERS_RESULTS = 2000;
94 static const int MAX_CMPCTBLOCK_DEPTH = 5;
96 static const int MAX_BLOCKTXN_DEPTH = 10;
101 static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
103 static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
105 static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
107 static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
109 static const unsigned int AVG_LOCAL_ADDRESS_BROADCAST_INTERVAL = 24 * 24 * 60;
111 static const unsigned int AVG_ADDRESS_BROADCAST_INTERVAL = 30;
114 static const unsigned int INVENTORY_BROADCAST_INTERVAL = 5;
117 static const unsigned int INVENTORY_BROADCAST_MAX = 7 * INVENTORY_BROADCAST_INTERVAL;
119 static const unsigned int AVG_FEEFILTER_BROADCAST_INTERVAL = 10 * 60;
121 static const unsigned int MAX_FEEFILTER_CHANGE_DELAY = 5 * 60;
123 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 5000000;
125 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 2500000;
126 
127 static const unsigned int DEFAULT_LIMITFREERELAY = 0;
128 static const bool DEFAULT_RELAYPRIORITY = true;
129 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
131 static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
132 
134 static const bool DEFAULT_PERMIT_BAREMULTISIG = true;
135 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
136 static const bool DEFAULT_TXINDEX = false;
137 static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
138 
140 static const bool DEFAULT_ENABLE_REPLACEMENT = true;
142 static const bool DEFAULT_FEEFILTER = true;
143 
145 static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
146 
148 static const int MAX_UNCONNECTING_HEADERS = 10;
149 
150 static const bool DEFAULT_PEERBLOOMFILTERS = true;
151 
153 {
154  size_t operator()(const uint256& hash) const { return hash.GetCheapHash(); }
155 };
156 
157 extern CScript COINBASE_FLAGS;
159 extern CTxMemPool mempool;
160 typedef boost::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
161 extern BlockMap mapBlockIndex;
162 extern uint64_t nLastBlockTx;
163 extern uint64_t nLastBlockSize;
164 extern uint64_t nLastBlockWeight;
165 extern const std::string strMessageMagic;
168 extern std::atomic_bool fImporting;
169 extern bool fReindex;
170 extern int nScriptCheckThreads;
171 extern bool fTxIndex;
172 extern bool fIsBareMultisigStd;
173 extern bool fRequireStandard;
174 extern bool fCheckBlockIndex;
175 extern bool fCheckpointsEnabled;
176 extern size_t nCoinCacheUsage;
178 extern CFeeRate minRelayTxFee;
180 extern CAmount maxTxFee;
181 extern bool fAlerts;
183 extern int64_t nMaxTipAge;
184 extern bool fEnableReplacement;
185 
187 extern uint256 hashAssumeValid;
188 
191 
193 static const uint64_t nMinDiskSpace = 52428800;
194 
197 extern bool fHavePruned;
199 extern bool fPruneMode;
201 extern uint64_t nPruneTarget;
203 static const unsigned int MIN_BLOCKS_TO_KEEP = 1440;
204 
205 static const signed int DEFAULT_CHECKBLOCKS = 6;
206 static const unsigned int DEFAULT_CHECKLEVEL = 3;
207 
208 // Require that user allocate at least 22,00MB for block & undo files (blk???.dat and rev???.dat)
209 // At 1MB per block, 1,440 blocks = 1,440MB.
210 // Add 15% for Undo data = 1,656MB
211 // Add 20% for Orphan block rate = 1,987MB
212 // We want the low water mark after pruning to be at least 1987 MB and since we prune in
213 // full block file chunks, we need the high water mark which triggers the prune to be
214 // one 128MB block file + added 15% undo data = 147MB greater for a total of 2,134MB
215 // Setting the target to > than 2200MB will make it likely we can respect the target.
216 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 2200ULL * 1024 * 1024;
217 
237 bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock);
238 
249 bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex=NULL);
250 
252 bool CheckDiskSpace(uint64_t nAdditionalBytes = 0);
254 FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
256 FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false);
258 boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix);
260 bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, CDiskBlockPos *dbp = NULL);
262 bool InitBlockIndex(const CChainParams& chainparams);
264 bool LoadBlockIndex(const CChainParams& chainparams);
266 void UnloadBlockIndex();
268 void ThreadScriptCheck();
278 std::string GetWarnings(const std::string& strFor);
280 bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params& params, uint256 &hashBlock, bool fAllowSlow = false);
282 bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
283 CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
284 
286 double GuessVerificationProgress(const ChainTxData& data, CBlockIndex* pindex);
287 
289 uint64_t CalculateCurrentUsage();
290 
306 void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight);
307 
311 void PruneOneBlockFile(const int fileNumber);
312 
316 void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune);
317 
321 void FlushStateToDisk();
323 void PruneAndFlush();
325 void PruneBlockFilesManual(int nPruneUpToHeight);
326 
329 bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
330  bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced = NULL,
331  bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
332 
334 bool AcceptToMemoryPoolWithTime(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree,
335  bool* pfMissingInputs, int64_t nAcceptTime, std::list<CTransactionRef>* plTxnReplaced = NULL,
336  bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0);
337 
339 std::string FormatStateMessage(const CValidationState &state);
340 
343 
346 
352 unsigned int GetLegacySigOpCount(const CTransaction& tx);
353 
361 unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& mapInputs);
362 
370 int64_t GetTransactionSigOpCost(const CTransaction& tx, const CCoinsViewCache& inputs, int flags);
371 
377 bool CheckInputs(const CTransaction& tx, CValidationState &state, const CCoinsViewCache &view, bool fScriptChecks,
378  unsigned int flags, bool cacheStore, PrecomputedTransactionData& txdata, std::vector<CScriptCheck> *pvChecks = NULL);
379 
381 void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
382 
386 bool CheckTransaction(const CTransaction& tx, CValidationState& state, bool fCheckDuplicateInputs=true);
387 
388 namespace Consensus {
389 
395 bool CheckTxInputs(const CChainParams& params, const CTransaction& tx, CValidationState& state, const CCoinsViewCache& inputs, int nSpendHeight);
396 
397 } // namespace Consensus
398 
403 bool IsFinalTx(const CTransaction &tx, int nBlockHeight, int64_t nBlockTime);
404 
412 bool CheckFinalTx(const CTransaction &tx, int flags = -1);
413 
417 bool TestLockPointValidity(const LockPoints* lp);
418 
423 bool SequenceLocks(const CTransaction &tx, int flags, std::vector<int>* prevHeights, const CBlockIndex& block);
424 
436 bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints* lp = NULL, bool useExistingLockPoints = false);
437 
443 {
444 private:
448  unsigned int nIn;
449  unsigned int nFlags;
453 
454 public:
456  CScriptCheck(const CCoins& txFromIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
457  scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey), amount(txFromIn.vout[txToIn.vin[nInIn].prevout.n].nValue),
458  ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
459 
460  bool operator()();
461 
462  void swap(CScriptCheck &check) {
464  std::swap(ptxTo, check.ptxTo);
465  std::swap(amount, check.amount);
466  std::swap(nIn, check.nIn);
467  std::swap(nFlags, check.nFlags);
468  std::swap(cacheStore, check.cacheStore);
469  std::swap(error, check.error);
470  std::swap(txdata, check.txdata);
471  }
472 
473  ScriptError GetScriptError() const { return error; }
474 };
475 
476 
478 bool WriteBlockToDisk(const CBlock& block, CDiskBlockPos& pos, const CMessageHeader::MessageStartChars& messageStart);
479 bool ReadBlockFromDisk(CBlock& block, const CDiskBlockPos& pos, const Consensus::Params& consensusParams, bool fCheckPOW = true);
480 bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool fCheckPOW = true);
481 bool ReadBlockHeaderFromDisk(CBlockHeader& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams, bool fCheckPOW = true);
482 
486 bool CheckBlockHeader(const CBlockHeader& block, CValidationState& state, bool fCheckPOW = true);
487 bool CheckBlock(const CBlock& block, CValidationState& state, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
488 
492 bool ContextualCheckBlockHeader(const CBlockHeader& block, CValidationState& state, const CBlockIndex* pindexPrev, int64_t nAdjustedTime);
493 bool ContextualCheckBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindexPrev);
494 
498 bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex, CCoinsViewCache& coins,
499  const CChainParams& chainparams, bool fJustCheck = false);
500 
505 bool DisconnectBlock(const CBlock& block, CValidationState& state, const CBlockIndex* pindex, CCoinsViewCache& coins, bool* pfClean = NULL);
506 
508 bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
509 
511 bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
512 
514 bool RewindBlockIndex(const CChainParams& params);
515 
517 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
518 
520 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
521 
523 class CVerifyDB {
524 public:
525  CVerifyDB();
526  ~CVerifyDB();
527  bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
528 };
529 
531 CBlockIndex* FindForkInGlobalIndex(const CChain& chain, const CBlockLocator& locator);
532 
534 bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex);
535 
537 bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex *pindex);
538 
540 bool ResetBlockFailureFlags(CBlockIndex *pindex);
541 
543 extern CChain chainActive;
544 
546 extern CCoinsViewCache *pcoinsTip;
547 
549 extern CBlockTreeDB *pblocktree;
550 
556 int GetSpendHeight(const CCoinsViewCache& inputs);
557 
559 
563 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params);
564 
569 static const unsigned int REJECT_INTERNAL = 0x100;
571 static const unsigned int REJECT_HIGHFEE = 0x100;
573 static const unsigned int REJECT_ALREADY_KNOWN = 0x101;
575 static const unsigned int REJECT_CONFLICT = 0x102;
576 
579 
581 void DumpMempool();
582 
584 bool LoadMempool();
585 
586 #endif // BITCOIN_VALIDATION_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:15
int flags
Definition: bitcoin-tx.cpp:468
Template mixin that adds -Wthread-safety locking annotations to a subset of the mutex API.
Definition: sync.h:56
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:25
Definition: block.h:67
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:158
Access to the block database (blocks/index/)
Definition: txdb.h:109
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
Definition: bloom.h:45
An in-memory indexed chain of blocks.
Definition: chain.h:432
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:47
Pruned version of CTransaction: only retains metadata and unspent transaction outputs.
Definition: coins.h:75
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:372
Abstract view on the open txout dataset.
Definition: coins.h:307
Definition: net.h:125
Wrapped boost mutex: supports recursive locking, but no waiting TODO: We should move away from using ...
Definition: sync.h:93
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: amount.h:38
inv message data
Definition: protocol.h:346
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:40
Closure representing one script verification Note that this stores references to the spending transac...
Definition: validation.h:443
CScript scriptPubKey
Definition: validation.h:445
bool operator()()
ScriptError GetScriptError() const
Definition: validation.h:473
PrecomputedTransactionData * txdata
Definition: validation.h:452
void swap(CScriptCheck &check)
Definition: validation.h:462
bool cacheStore
Definition: validation.h:450
ScriptError error
Definition: validation.h:451
unsigned int nFlags
Definition: validation.h:449
const CTransaction * ptxTo
Definition: validation.h:447
unsigned int nIn
Definition: validation.h:448
CAmount amount
Definition: validation.h:446
CScriptCheck(const CCoins &txFromIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:456
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:377
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:308
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:432
Capture information about block/transaction validation.
Definition: validation.h:22
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:523
bool VerifyDB(const CChainParams &chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth)
void swap(prevector< N, T, Size, Diff > &other)
Definition: prevector.h:429
256-bit opaque blob.
Definition: uint256.h:123
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:134
bool CheckTxInputs(const CChainParams &params, 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 m...
DeploymentPos
Definition: params.h:16
const char * prefix
Definition: rest.cpp:605
enum ScriptError_t ScriptError
@ SCRIPT_ERR_UNKNOWN_ERROR
Definition: script_error.h:12
size_t operator()(const uint256 &hash) const
Definition: validation.h:154
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:130
Parameters that influence chain consensus.
Definition: params.h:39
boost::condition_variable CConditionVariable
Just a typedef for boost::condition_variable, can be wrapped later if desired.
Definition: sync.h:105
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:459
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: validation.cpp:224
bool PreciousBlock(CValidationState &state, const CChainParams &params, CBlockIndex *pindex)
Mark a block as precious and reorganize.
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Determine what nVersion a new block should use.
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)
uint256 hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:84
void FlushStateToDisk()
Flush all state, indexes and buffers to disk.
uint64_t nPruneTarget
Number of MiB of block files that we're trying to stay below.
Definition: validation.cpp:79
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,...
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: validation.cpp:223
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,...
CCriticalSection cs_main
Global state.
Definition: validation.cpp:61
bool fCheckBlockIndex
Definition: validation.cpp:76
bool WriteBlockToDisk(const CBlock &block, CDiskBlockPos &pos, const CMessageHeader::MessageStartChars &messageStart)
Functions for disk access for blocks.
bool ReadBlockFromDisk(CBlock &block, const CDiskBlockPos &pos, const Consensus::Params &consensusParams, bool fCheckPOW=true)
bool LoadExternalBlockFile(const CChainParams &chainparams, FILE *fileIn, CDiskBlockPos *dbp=NULL)
Import blocks from an external file.
int nScriptCheckThreads
Definition: validation.cpp:68
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool fLimitFree, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced=NULL, bool fOverrideMempoolLimit=false, const CAmount nAbsurdFee=0)
(try to) add transaction to memory pool plTxnReplaced will be appended to with all transactions repla...
const std::string strMessageMagic
Definition: validation.cpp:101
bool fEnableReplacement
Definition: validation.cpp:82
bool ProcessNewBlock(const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock)
Process an incoming block.
bool TestLockPointValidity(const LockPoints *lp)
Test whether the LockPoints height and time are still valid on the current chain.
Definition: validation.cpp:365
bool fAlerts
Definition: validation.cpp:80
bool RewindBlockIndex(const CChainParams &params)
When there are blocks in the active chain with missing data, rewind the chainstate and remove them fr...
boost::filesystem::path GetBlockPosFilename(const CDiskBlockPos &pos, const char *prefix)
Translation to a filesystem path.
void DumpMempool()
Dump the mempool to disk.
unsigned int GetP2SHSigOpCount(const CTransaction &tx, const CCoinsViewCache &mapInputs)
Count ECDSA signature operations in pay-to-script-hash inputs.
Definition: validation.cpp:468
uint64_t nLastBlockTx
Definition: miner.cpp:46
VersionBitsCache versionbitscache
bool ContextualCheckBlockHeader(const CBlockHeader &block, CValidationState &state, const CBlockIndex *pindexPrev, int64_t nAdjustedTime)
Context-dependent validity checks.
bool fHavePruned
Pruning-related variables and constants.
Definition: validation.cpp:72
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
std::atomic_bool fImporting
boost::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:160
bool ProcessNewBlockHeaders(const std::vector< CBlockHeader > &block, CValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=NULL)
Process incoming block headers.
void FindFilesToPrune(std::set< int > &setFilesToPrune, uint64_t nPruneAfterHeight)
Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a us...
bool ResetBlockFailureFlags(CBlockIndex *pindex)
Remove invalidity status from a block and its descendants.
FILE * OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly=false)
Open a block file (blk?????.dat)
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
Definition: validation.cpp:86
bool CheckBlockHeader(const CBlockHeader &block, CValidationState &state, bool fCheckPOW=true)
Functions for validating blocks and updating the block tree.
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
CScript COINBASE_FLAGS
Constant stuff for coinbase transactions we create:
Definition: validation.cpp:99
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network)
void PruneBlockFilesManual(int nPruneUpToHeight)
Prune block files up to a given height.
std::string GetWarnings(const std::string &strFor)
Format a string that describes several potential problems detected by the core.
Definition: warnings.cpp:51
bool fTxIndex
Definition: validation.cpp:71
bool CheckFinalTx(const CTransaction &tx, int flags=-1)
Check if transaction will be final in the next block to be created.
Definition: validation.cpp:250
bool CheckDiskSpace(uint64_t nAdditionalBytes=0)
Check whether enough disk space is available for an incoming block.
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...
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
CAmount maxTxFee
Absolute maximum transaction fee (in satoshis) used by wallet and mempool (rejects high fee in sendra...
Definition: validation.cpp:87
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.
bool DisconnectBlock(const CBlock &block, CValidationState &state, const CBlockIndex *pindex, CCoinsViewCache &coins, bool *pfClean=NULL)
Undo the effects of this block (with given index) on the UTXO set represented by coins.
std::string FormatStateMessage(const CValidationState &state)
Convert CValidationState to a human-readable message for logging.
Definition: validation.cpp:567
BlockMap mapBlockIndex
Definition: validation.cpp:63
void ThreadScriptCheck()
Run an instance of the script checking thread.
bool fReindex
Definition: validation.cpp:70
void UpdateUncommittedBlockStructures(CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
Update uncommitted block structures (currently: only the witness nonce).
int64_t GetTransactionSigOpCost(const CTransaction &tx, const CCoinsViewCache &inputs, int flags)
Compute total signature operation cost of a transaction.
Definition: validation.cpp:483
bool ReadBlockHeaderFromDisk(CBlockHeader &block, const CBlockIndex *pindex, const Consensus::Params &consensusParams, bool fCheckPOW=true)
bool ConnectBlock(const CBlock &block, CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &coins, const CChainParams &chainparams, bool fJustCheck=false)
Apply the effects of this block (with given index) on the UTXO set represented by coins.
bool CheckTransaction(const CTransaction &tx, CValidationState &state, bool fCheckDuplicateInputs=true)
Transaction validation functions.
Definition: validation.cpp:506
ThresholdState VersionBitsTipState(const Consensus::Params &params, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment at the current tip.
bool InitBlockIndex(const CChainParams &chainparams)
Initialize a new block tree database + block data on disk.
bool ContextualCheckBlock(const CBlock &block, CValidationState &state, const CBlockIndex *pindexPrev)
bool fPruneMode
True if we're running in -prune mode.
Definition: validation.cpp:73
size_t nCoinCacheUsage
Definition: validation.cpp:78
CTxMemPool mempool
void PruneOneBlockFile(const int fileNumber)
Mark one block file as pruned.
bool LoadBlockIndex(const CChainParams &chainparams)
Load the block tree and coins database from disk.
bool fIsBareMultisigStd
Definition: validation.cpp:74
CWaitableCriticalSection csBestBlock
Definition: validation.cpp:66
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...
void UnloadBlockIndex()
Unload database information.
bool IsWitnessEnabled(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Check whether witness commitments are required for block.
bool fCheckpointsEnabled
Definition: validation.cpp:77
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.cpp:65
unsigned int GetLegacySigOpCount(const CTransaction &tx)
Count ECDSA signature operations the old-fashioned (pre-0.6) way.
Definition: validation.cpp:454
int GetSpendHeight(const CCoinsViewCache &inputs)
Return the spend height, which is one more than the inputs.GetBestBlock().
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:64
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.
Definition: validation.cpp:237
FILE * OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly=false)
Open an undo file (rev?????.dat)
bool LoadMempool()
Load the mempool from disk.
bool InvalidateBlock(CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex)
Mark a block as invalid.
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)
(try to) add transaction to memory pool with a specified acceptance time
CConditionVariable cvBlockChange
Definition: validation.cpp:67
double GuessVerificationProgress(const ChainTxData &data, CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
uint64_t nLastBlockWeight
Definition: miner.cpp:48
bool CheckSequenceLocks(const CTransaction &tx, int flags, LockPoints *lp=NULL, bool useExistingLockPoints=false)
Check if transaction will be BIP 68 final in the next block to be created.
Definition: validation.cpp:383
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
bool fRequireStandard
Definition: validation.cpp:75
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
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.
Definition: validation.cpp:360
CBlockIndex * InsertBlockIndex(uint256 hash)
Create a new block index entry for a given block hash.
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator)
Find the last common block between the parameter chain and a locator.
Definition: validation.cpp:205
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:81
uint64_t nLastBlockSize
Definition: miner.cpp:47
bool CheckBlock(const CBlock &block, CValidationState &state, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
void PruneAndFlush()
Prune block files and flush state to disk.
ThresholdState
Definition: versionbits.h:20