Bitcoin
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 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 <coins.h>
15 #include <crypto/common.h> // for ReadLE64
16 #include <fs.h>
17 #include <policy/feerate.h>
18 #include <protocol.h> // For CMessageHeader::MessageStartChars
19 #include <script/script_error.h>
20 #include <sync.h>
21 #include <txmempool.h> // For CTxMemPool::cs
22 #include <versionbits.h>
23 
24 #include <algorithm>
25 #include <atomic>
26 #include <exception>
27 #include <map>
28 #include <memory>
29 #include <set>
30 #include <stdint.h>
31 #include <string>
32 #include <utility>
33 #include <vector>
34 
35 class CChainState;
36 class CBlockIndex;
37 class CBlockTreeDB;
38 class CBlockUndo;
39 class CChainParams;
40 class CCoinsViewDB;
41 class CInv;
42 class CConnman;
43 class CScriptCheck;
45 class CTxMemPool;
46 class CValidationState;
47 struct ChainTxData;
48 
51 struct LockPoints;
52 
54 static const bool DEFAULT_WHITELISTRELAY = true;
56 static const bool DEFAULT_WHITELISTFORCERELAY = false;
58 static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
60 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
62 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
64 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
66 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
68 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
70 static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE = 20000;
72 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
74 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
76 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
77 
79 static const int MAX_SCRIPTCHECK_THREADS = 16;
81 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
83 static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
85 static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
88 static const unsigned int MAX_HEADERS_RESULTS = 2000;
91 static const int MAX_CMPCTBLOCK_DEPTH = 5;
93 static const int MAX_BLOCKTXN_DEPTH = 10;
98 static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
100 static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
102 static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
104 static const unsigned int MAX_REJECT_MESSAGE_LENGTH = 111;
106 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
109 
110 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
112 static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
113 
114 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
115 static const bool DEFAULT_TXINDEX = false;
116 static const char* const DEFAULT_BLOCKFILTERINDEX = "0";
117 static const unsigned int DEFAULT_BANSCORE_THRESHOLD = 100;
119 static const bool DEFAULT_PERSIST_MEMPOOL = true;
121 static const bool DEFAULT_FEEFILTER = true;
122 
124 static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
125 
127 static const int MAX_UNCONNECTING_HEADERS = 10;
128 
129 static const bool DEFAULT_PEERBLOOMFILTERS = true;
130 
132 static const int DEFAULT_STOPATHEIGHT = 0;
133 
135 {
136  // this used to call `GetCheapHash()` in uint256, which was later moved; the
137  // cheap hash function simply calls ReadLE64() however, so the end result is
138  // identical
139  size_t operator()(const uint256& hash) const { return ReadLE64(hash.begin()); }
140 };
141 
142 extern CScript COINBASE_FLAGS;
145 extern CTxMemPool mempool;
146 typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
148 extern std::condition_variable g_best_block_cv;
149 extern uint256 g_best_block;
150 extern std::atomic_bool fImporting;
151 extern std::atomic_bool fReindex;
152 extern int nScriptCheckThreads;
153 extern bool fRequireStandard;
154 extern bool fCheckBlockIndex;
155 extern bool fCheckpointsEnabled;
156 extern size_t nCoinCacheUsage;
158 extern CFeeRate minRelayTxFee;
160 extern int64_t nMaxTipAge;
161 
163 extern uint256 hashAssumeValid;
164 
167 
170 
173 extern bool fHavePruned;
175 extern bool fPruneMode;
177 extern uint64_t nPruneTarget;
179 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
181 static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
182 
183 static const signed int DEFAULT_CHECKBLOCKS = 6;
184 static const unsigned int DEFAULT_CHECKLEVEL = 3;
185 
186 // Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat)
187 // At 1MB per block, 288 blocks = 288MB.
188 // Add 15% for Undo data = 331MB
189 // Add 20% for Orphan block rate = 397MB
190 // We want the low water mark after pruning to be at least 397 MB and since we prune in
191 // full block file chunks, we need the high water mark which triggers the prune to be
192 // one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
193 // Setting the target to >= 550 MiB will make it likely we can respect the target.
194 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
195 
216 bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock) LOCKS_EXCLUDED(cs_main);
217 
230 bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, CValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr, CBlockHeader* first_invalid = nullptr) LOCKS_EXCLUDED(cs_main);
231 
233 FILE* OpenBlockFile(const FlatFilePos &pos, bool fReadOnly = false);
235 fs::path GetBlockPosFilename(const FlatFilePos &pos);
237 bool LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFilePos *dbp = nullptr);
239 bool LoadGenesisBlock(const CChainParams& chainparams);
246 void UnloadBlockIndex();
248 void ThreadScriptCheck(int worker_num);
250 bool GetTransaction(const uint256& hash, CTransactionRef& tx, const Consensus::Params& params, uint256& hashBlock, const CBlockIndex* const blockIndex = nullptr);
257 bool ActivateBestChain(CValidationState& state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
258 CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
259 
261 double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex* pindex);
262 
265 
269 void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
270 
274 void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune);
275 
277 void PruneBlockFilesManual(int nManualPruneHeight);
278 
281 bool AcceptToMemoryPool(CTxMemPool& pool, CValidationState &state, const CTransactionRef &tx,
282  bool* pfMissingInputs, std::list<CTransactionRef>* plTxnReplaced,
283  bool bypass_limits, const CAmount nAbsurdFee, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
284 
287 
290 
293 
294 
296 void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
297 
308 
313 
325 bool CheckSequenceLocks(const CTxMemPool& pool, const CTransaction& tx, int flags, LockPoints* lp = nullptr, bool useExistingLockPoints = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
326 
332 {
333 private:
336  unsigned int nIn;
337  unsigned int nFlags;
341 
342 public:
343  CScriptCheck(): ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
344  CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
345  m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
346 
347  bool operator()();
348 
349  void swap(CScriptCheck &check) {
350  std::swap(ptxTo, check.ptxTo);
351  std::swap(m_tx_out, check.m_tx_out);
352  std::swap(nIn, check.nIn);
353  std::swap(nFlags, check.nFlags);
354  std::swap(cacheStore, check.cacheStore);
355  std::swap(error, check.error);
356  std::swap(txdata, check.txdata);
357  }
358 
359  ScriptError GetScriptError() const { return error; }
360 };
361 
364 
365 
367 bool ReadBlockFromDisk(CBlock& block, const FlatFilePos& pos, const Consensus::Params& consensusParams);
368 bool ReadBlockFromDisk(CBlock& block, const CBlockIndex* pindex, const Consensus::Params& consensusParams);
369 bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const FlatFilePos& pos, const CMessageHeader::MessageStartChars& message_start);
370 bool ReadRawBlockFromDisk(std::vector<uint8_t>& block, const CBlockIndex* pindex, const CMessageHeader::MessageStartChars& message_start);
371 
372 bool UndoReadFromDisk(CBlockUndo& blockundo, const CBlockIndex* pindex);
373 
377 bool CheckBlock(const CBlock& block, CValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
378 
380 bool TestBlockValidity(CValidationState& state, const CChainParams& chainparams, const CBlock& block, CBlockIndex* pindexPrev, bool fCheckPOW = true, bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
381 
383 bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
384 
386 bool IsNullDummyEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
387 
390 
392 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
393 
395 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
396 
398 class CVerifyDB {
399 public:
400  CVerifyDB();
401  ~CVerifyDB();
402  bool VerifyDB(const CChainParams& chainparams, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth);
403 };
404 
406 bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
407 
409 
412 
414 {
415  DISCONNECT_OK, // All good.
416  DISCONNECT_UNCLEAN, // Rolled back, but UTXO set was inconsistent with block.
417  DISCONNECT_FAILED // Something else went wrong.
418 };
419 
420 class ConnectTrace;
421 
423 enum class FlushStateMode {
424  NONE,
425  IF_NEEDED,
426  PERIODIC,
427  ALWAYS
428 };
429 
431 {
432  bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const;
433 };
434 
443 public:
444  BlockMap m_block_index GUARDED_BY(cs_main);
445 
464  std::set<CBlockIndex*> m_failed_blocks;
465 
470  std::multimap<CBlockIndex*, CBlockIndex*> m_blocks_unlinked;
471 
480  bool LoadBlockIndex(
481  const Consensus::Params& consensus_params,
482  CBlockTreeDB& blocktree,
483  std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
485 
488 
492 
497  bool AcceptBlockHeader(
498  const CBlockHeader& block,
499  CValidationState& state,
500  const CChainParams& chainparams,
502 };
503 
518 class CChainState {
519 private:
520 
527  int32_t nBlockSequenceId = 1;
529  int32_t nBlockReverseSequenceId = -1;
531  arith_uint256 nLastPreciousChainwork = 0;
532 
538 
545  mutable std::atomic<bool> m_cached_finished_ibd{false};
546 
551 
552 public:
553  CChainState(BlockManager& blockman) : m_blockman(blockman) { }
554 
563  std::set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexCandidates;
564 
574  bool FlushStateToDisk(
575  const CChainParams& chainparams,
576  CValidationState &state,
577  FlushStateMode mode,
578  int nManualPruneHeight = 0);
579 
581  void ForceFlushStateToDisk();
582 
585  void PruneAndFlush();
586 
587  bool ActivateBestChain(CValidationState &state, const CChainParams& chainparams, std::shared_ptr<const CBlock> pblock) LOCKS_EXCLUDED(cs_main);
588 
589  bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
590 
591  // Block (dis)connection on a given view:
592  DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view);
593  bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pindex,
594  CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
595 
596  // Block disconnection on our pcoinsTip:
597  bool DisconnectTip(CValidationState& state, const CChainParams& chainparams, DisconnectedBlockTransactions* disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs);
598 
599  // Manual block validity manipulation:
600  bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
601  bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
603 
604  bool ReplayBlocks(const CChainParams& params, CCoinsView* view);
606  bool LoadGenesisBlock(const CChainParams& chainparams);
607 
608  void PruneBlockIndexCandidates();
609 
610  void UnloadBlockIndex();
611 
613  bool IsInitialBlockDownload() const;
614 
620  void CheckBlockIndex(const Consensus::Params& consensusParams);
621 
622 private:
623  bool ActivateBestChainStep(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs);
624  bool ConnectTip(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::mempool.cs);
625 
626  void InvalidBlockFound(CBlockIndex *pindex, const CValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
627  CBlockIndex* FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
628  void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
629 
630  bool RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& inputs, const CChainParams& params) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
631 
633  void EraseBlockData(CBlockIndex* index) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
634 };
635 
641 bool PreciousBlock(CValidationState& state, const CChainParams& params, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main);
642 
644 bool InvalidateBlock(CValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
645 
648 
651 
654 
657 
659 extern std::unique_ptr<CCoinsViewDB> pcoinsdbview;
660 
662 extern std::unique_ptr<CCoinsViewCache> pcoinsTip;
663 
665 extern std::unique_ptr<CBlockTreeDB> pblocktree;
666 
672 int GetSpendHeight(const CCoinsViewCache& inputs);
673 
675 
679 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params);
680 
685 static const unsigned int REJECT_INTERNAL = 0x100;
687 static const unsigned int REJECT_HIGHFEE = 0x100;
688 
691 
693 bool DumpMempool(const CTxMemPool& pool);
694 
696 bool LoadMempool(CTxMemPool& pool);
697 
699 inline bool IsBlockPruned(const CBlockIndex* pblockindex)
700 {
701  return (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
702 }
703 
704 #endif // BITCOIN_VALIDATION_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:408
bool ProcessNewBlock(const CChainParams &chainparams, const std::shared_ptr< const CBlock > pblock, bool fForceProcessing, bool *fNewBlock) LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:3450
bool cacheStore
Definition: validation.h:338
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT
Definition: validation.h:62
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: thread_annotations.h:13
Definition: validation.h:331
CTxMemPool mempool
static const int DEFAULT_SCRIPTCHECK_THREADS
Definition: validation.h:81
bool CheckFinalTx(const CTransaction &tx, int flags=-1) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:187
size_t nCoinCacheUsage
Definition: validation.cpp:114
static const int MAX_BLOCKTXN_DEPTH
Definition: validation.h:93
static const unsigned int MAX_BLOCKFILE_SIZE
Definition: validation.h:72
static const unsigned int DEFAULT_DESCENDANT_LIMIT
Definition: validation.h:64
int64_t nMaxTipAge
Definition: validation.cpp:116
Definition: flatfile.h:14
bool AcceptToMemoryPool(CTxMemPool &pool, CValidationState &state, const CTransactionRef &tx, bool *pfMissingInputs, std::list< CTransactionRef > *plTxnReplaced, bool bypass_limits, const CAmount nAbsurdFee, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:854
bool IsNullDummyEnabled(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Definition: validation.cpp:3030
CTxOut m_tx_out
Definition: validation.h:334
enum ScriptError_t ScriptError
Definition: block.h:126
Definition: script_error.h:12
CChain m_chain
Definition: validation.h:557
Definition: validation.h:134
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const
Definition: validation.cpp:62
void ThreadScriptCheck(int worker_num)
Definition: validation.cpp:1540
Definition: txmempool.h:38
CBlockIndex * AddToBlockIndex(const CBlockHeader &block) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:2798
bool InvalidateBlock(CValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:2756
Definition: interpreter.h:122
static const unsigned int MAX_DISCONNECTED_TX_POOL_SIZE
Definition: validation.h:70
uint64_t CalculateCurrentUsage()
Definition: validation.cpp:3515
static void pool cs
Definition: mempool_eviction.cpp:13
static const int64_t DEFAULT_MAX_TIP_AGE
Definition: validation.h:110
void PruneBlockFilesManual(int nManualPruneHeight)
Definition: validation.cpp:3594
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE
Definition: validation.h:106
CBlockIndex * pindexBestHeader
Definition: validation.cpp:102
static const unsigned int MIN_BLOCKS_TO_KEEP
Definition: validation.h:179
static const unsigned int DEFAULT_ANCESTOR_LIMIT
Definition: validation.h:60
bool CheckBlock(const CBlock &block, CValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
Definition: validation.cpp:2961
DisconnectResult
Definition: validation.h:413
unsigned int nHeight
Definition: mempool_eviction.cpp:15
CBlockPolicyEstimator feeEstimator
Definition: validation.cpp:123
static const unsigned int MAX_REJECT_MESSAGE_LENGTH
Definition: validation.h:104
bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp=nullptr, bool useExistingLockPoints=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:237
bool LoadChainTip(const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3839
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3527
Definition: net.h:113
Definition: validation.h:518
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Definition: validation.cpp:927
Definition: params.h:49
ScriptError error
Definition: validation.h:339
ThresholdState
Definition: versionbits.h:20
Definition: txdb.h:88
bool TestBlockValidity(CValidationState &state, const CChainParams &chainparams, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW=true, bool fCheckMerkleRoot=true) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3485
void ResetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:2794
Definition: validation.h:98
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Definition: validation.cpp:4763
Definition: undo.h:101
std::multimap< CBlockIndex *, CBlockIndex * > m_blocks_unlinked
Definition: validation.h:470
unsigned char * begin()
Definition: uint256.h:55
bool ActivateBestChain(CValidationState &state, const CChainParams &chainparams, std::shared_ptr< const CBlock > pblock=std::shared_ptr< const CBlock >())
Definition: validation.cpp:2634
bool RewindBlockIndex(const CChainParams &params) LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:4192
bool LoadBlockIndex(const Consensus::Params &consensus_params, CBlockTreeDB &blocktree, std::set< CBlockIndex *, CBlockIndexWorkComparator > &block_index_candidates) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3719
Definition: validation.h:442
BIP9Stats VersionBitsTipStatistics(const Consensus::Params &params, Consensus::DeploymentPos pos)
Definition: validation.cpp:4617
bool PreciousBlock(CValidationState &state, const CChainParams &params, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:2666
Definition: versionbits.h:59
CCriticalSection cs_main
Definition: validation.cpp:100
Definition: validation.h:430
DeploymentPos
Definition: params.h:16
static const unsigned int REJECT_INTERNAL
Definition: validation.h:685
Definition: coins.h:201
Definition: validation.h:398
int64_t CAmount
Definition: amount.h:12
Definition: feerate.h:19
Definition: validation.cpp:2239
bool LoadBlockIndex(const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:4241
static const bool DEFAULT_PERSIST_MEMPOOL
Definition: validation.h:119
Definition: validation.h:416
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:129
CCriticalSection cs_nBlockSequenceId
Definition: validation.h:525
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER
Definition: validation.h:108
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3774
Definition: chainparams.h:47
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS
Definition: validation.h:181
void UpdateUncommittedBlockStructures(CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
Definition: validation.cpp:3051
static const bool DEFAULT_WHITELISTRELAY
Definition: validation.h:54
CCriticalSection m_cs_chainstate
Definition: validation.h:537
static const unsigned int BLOCKFILE_CHUNK_SIZE
Definition: validation.h:74
bool AcceptBlockHeader(const CBlockHeader &block, CValidationState &state, const CChainParams &chainparams, CBlockIndex **ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3244
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
Definition: validation.cpp:1358
Definition: transaction.h:270
bool ReadRawBlockFromDisk(std::vector< uint8_t > &block, const FlatFilePos &pos, const CMessageHeader::MessageStartChars &message_start)
Definition: validation.cpp:967
bool fHavePruned
Definition: validation.cpp:109
void InitScriptExecutionCache()
Definition: validation.cpp:1218
static const int64_t MAX_FEE_ESTIMATION_TIP_AGE
Definition: validation.h:112
static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER
Definition: validation.h:83
fs::path GetBlockPosFilename(const FlatFilePos &pos)
Definition: validation.cpp:3694
bool LoadMempool(CTxMemPool &pool)
Definition: validation.cpp:4631
bool GetTransaction(const uint256 &hash, CTransactionRef &tx, const Consensus::Params &params, uint256 &hashBlock, const CBlockIndex *const blockIndex=nullptr)
Definition: validation.cpp:866
FlushStateMode
Definition: validation.h:423
unsigned long long uint64_t
Definition: stdint.h:22
static const unsigned int MAX_HEADERS_RESULTS
Definition: validation.h:88
void swap(CScriptCheck &check)
Definition: validation.h:349
const CTransaction * ptxTo
Definition: validation.h:335
Definition: chain.h:413
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE
Definition: validation.h:58
static const unsigned int UNDOFILE_CHUNK_SIZE
Definition: validation.h:76
CChain & ChainActive()
Definition: validation.cpp:88
bool TestLockPointValidity(const LockPoints *lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:219
Definition: txmempool.h:782
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT
Definition: validation.h:66
static const unsigned int DEFAULT_MEMPOOL_EXPIRY
Definition: validation.h:68
static const int DEFAULT_STOPATHEIGHT
Definition: validation.h:132
arith_uint256 nMinimumChainWork
Definition: validation.cpp:119
static const bool DEFAULT_FEEFILTER
Definition: validation.h:121
ThresholdState VersionBitsTipState(const Consensus::Params &params, Consensus::DeploymentPos pos)
Definition: validation.cpp:4611
std::atomic_bool fImporting
Definition: versionbits.h:33
static const char *const DEFAULT_BLOCKFILTERINDEX
Definition: validation.h:116
bool ReplayBlocks(const CChainParams &params, CCoinsView *view)
Definition: validation.cpp:4059
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
Definition: validation.cpp:1013
#define LOCKS_EXCLUDED(...)
Definition: thread_annotations.h:21
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Definition: validation.cpp:1547
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:344
Definition: arith_uint256.h:252
static const unsigned int DATABASE_WRITE_INTERVAL
Definition: validation.h:100
uint64_t nPruneTarget
Definition: validation.cpp:115
uint256 g_best_block
Definition: validation.cpp:105
static const int MAX_UNCONNECTING_HEADERS
Definition: validation.h:127
Definition: coins.h:145
int flags
Definition: bitcoin-tx.cpp:507
CFeeRate minRelayTxFee
Definition: validation.cpp:121
std::condition_variable g_best_block_cv
Definition: validation.cpp:104
std::atomic_bool fReindex
std::vector< uint8_t > data
Definition: bech32.cpp:10
Definition: uint256.h:121
bool ProcessNewBlockHeaders(const std::vector< CBlockHeader > &block, CValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=nullptr, CBlockHeader *first_invalid=nullptr) LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:3324
Definition: validation.h:415
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:114
Definition: txmempool.h:443
Definition: block.h:20
not actually invalid
Definition: chainparams.h:34
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly=false)
Definition: validation.cpp:3685
bool fRequireStandard
Definition: validation.cpp:111
bool IsWitnessEnabled(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Definition: validation.cpp:3024
const CChainParams & Params()
Definition: chainparams.cpp:399
unsigned char MessageStartChars[MESSAGE_START_SIZE]
Definition: protocol.h:38
bool IsBlockPruned(const CBlockIndex *pblockindex)
Check whether the block associated with this index entry is pruned or not.
Definition: validation.h:699
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:183
Definition: script.h:390
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight)
Definition: validation.cpp:1195
uint256 hashAssumeValid
Definition: validation.cpp:118
PrecomputedTransactionData * txdata
Definition: validation.h:340
std::set< CBlockIndex * > m_failed_blocks
Definition: validation.h:464
unsigned int nIn
Definition: validation.h:336
CBlockIndex * InsertBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3699
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE
Definition: validation.h:124
static uint64_t ReadLE64(const unsigned char *ptr)
Definition: common.h:31
std::vector< unsigned char > GenerateCoinbaseCommitment(CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
Definition: validation.cpp:3063
std::unique_ptr< CCoinsViewDB > pcoinsdbview
Definition: validation.cpp:175
bool DumpMempool(const CTxMemPool &pool)
Definition: validation.cpp:4708
Definition: protocol.h:382
size_t operator()(const uint256 &hash) const
Definition: validation.h:139
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexCandidates
Definition: validation.h:563
Definition: params.h:14
Definition: chain.h:139
signed long long int64_t
Definition: stdint.h:18
CBlockIndex * LookupBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:149
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:156
CScript COINBASE_FLAGS
Definition: validation.cpp:127
static const unsigned int DEFAULT_BANSCORE_THRESHOLD
Definition: validation.h:117
ScriptError GetScriptError() const
Definition: validation.h:359
CChainState & ChainstateActive()
Definition: validation.cpp:86
static const unsigned int BLOCK_STALLING_TIMEOUT
Definition: validation.h:85
static const int MAX_CMPCTBLOCK_DEPTH
Definition: validation.h:91
BlockManager & m_blockman
Definition: validation.h:550
int nScriptCheckThreads
Definition: validation.cpp:106
signed int int32_t
Definition: stdint.h:17
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:146
bool LoadExternalBlockFile(const CChainParams &chainparams, FILE *fileIn, FlatFilePos *dbp=nullptr)
Definition: validation.cpp:4293
bool fPruneMode
Definition: validation.cpp:110
full block available in blk*.dat
Definition: chain.h:123
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:194
static const unsigned int DATABASE_FLUSH_INTERVAL
Definition: validation.h:102
int GetSpendHeight(const CCoinsViewCache &inputs)
Definition: validation.cpp:1207
int VersionBitsTipStateSinceHeight(const Consensus::Params &params, Consensus::DeploymentPos pos)
Definition: validation.cpp:4623
CScriptCheck()
Definition: validation.h:343
bool fCheckpointsEnabled
Definition: validation.cpp:113
Definition: fees.h:131
Definition: block.h:72
BlockMap m_block_index GUARDED_BY(cs_main)
bool LoadGenesisBlock(const CChainParams &chainparams)
Definition: validation.cpp:4288
static const bool DEFAULT_WHITELISTFORCERELAY
Definition: validation.h:56
CBlockFileInfo * GetBlockFileInfo(size_t n)
Definition: validation.cpp:4604
VersionBitsCache versionbitscache
CChainState(BlockManager &blockman)
Definition: validation.h:553
bool error(const char *fmt, const Args &... args)
Definition: system.h:59
std::unique_ptr< CBlockTreeDB > pblocktree
Definition: validation.cpp:177
static const bool DEFAULT_TXINDEX
Definition: validation.h:115
void UnloadBlockIndex()
Definition: validation.cpp:4220
static const unsigned int BLOCK_DOWNLOAD_WINDOW
Definition: validation.h:98
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Definition: validation.cpp:3561
std::unique_ptr< CCoinsViewCache > pcoinsTip
Definition: validation.cpp:176
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:184
bool fCheckBlockIndex
Definition: validation.cpp:112
Definition: chain.h:40
BlockMap & BlockIndex()
Definition: validation.cpp:1055
static const int MAX_SCRIPTCHECK_THREADS
Definition: validation.h:79
Definition: txdb.h:46
static const unsigned int REJECT_HIGHFEE
Definition: validation.h:687
LockPoints lp
Definition: mempool_eviction.cpp:18
Definition: validation.h:417
Mutex g_best_block_mutex
Definition: validation.cpp:103
unsigned int nFlags
Definition: validation.h:337
Definition: transaction.h:133