Bitcoin ABC  0.22.12
P2P Digital Currency
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 // Copyright (c) 2017-2020 The Bitcoin 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/bitcoin-config.h>
12 #endif
13 
14 #include <amount.h>
15 #include <blockfileinfo.h>
17 #include <coins.h>
18 #include <consensus/consensus.h>
19 #include <disconnectresult.h>
20 #include <flatfile.h>
21 #include <fs.h>
22 #include <protocol.h> // For CMessageHeader::MessageMagic
23 #include <script/script_error.h>
24 #include <script/script_metrics.h>
25 #include <sync.h>
26 #include <txdb.h>
27 #include <txmempool.h> // For CTxMemPool::cs
28 #include <versionbits.h>
29 
30 #include <atomic>
31 #include <cstdint>
32 #include <map>
33 #include <memory>
34 #include <optional>
35 #include <set>
36 #include <utility>
37 #include <vector>
38 
40 class CBlockIndex;
41 class CBlockTreeDB;
42 class CBlockUndo;
43 class CChainParams;
44 class CChain;
45 class CConnman;
46 class CInv;
47 class ChainstateManager;
48 class Config;
49 class CScriptCheck;
50 class CTxMemPool;
51 class CTxUndo;
53 class TxValidationState;
54 
55 struct ChainTxData;
56 struct FlatFilePos;
58 struct LockPoints;
59 
60 namespace Consensus {
61 struct Params;
62 }
63 
64 #define MIN_TRANSACTION_SIZE \
65  (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))
66 
75 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
77 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
78 
80 static const int MAX_SCRIPTCHECK_THREADS = 15;
82 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
86 static const int MAX_BLOCKS_IN_TRANSIT_PER_PEER = 16;
91 static const unsigned int BLOCK_STALLING_TIMEOUT = 2;
97 static const unsigned int MAX_HEADERS_RESULTS = 2000;
102 static const int MAX_CMPCTBLOCK_DEPTH = 5;
106 static const int MAX_BLOCKTXN_DEPTH = 10;
114 static const unsigned int BLOCK_DOWNLOAD_WINDOW = 1024;
116 static const unsigned int DATABASE_WRITE_INTERVAL = 60 * 60;
118 static const unsigned int DATABASE_FLUSH_INTERVAL = 24 * 60 * 60;
121 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE = 1000000;
125 static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER = 500000;
126 
127 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
132 static const int64_t MAX_FEE_ESTIMATION_TIP_AGE = 3 * 60 * 60;
133 
134 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
135 static const bool DEFAULT_TXINDEX = false;
136 static const char *const DEFAULT_BLOCKFILTERINDEX = "0";
137 
139 static const bool DEFAULT_PERSIST_MEMPOOL = true;
141 static const bool DEFAULT_FEEFILTER = true;
142 
147 static const unsigned int MAX_BLOCKS_TO_ANNOUNCE = 8;
148 
150 static const int MAX_UNCONNECTING_HEADERS = 10;
151 
152 static const bool DEFAULT_PEERBLOOMFILTERS = true;
153 
155 static const int DEFAULT_STOPATHEIGHT = 0;
157 static const int DEFAULT_MAX_REORG_DEPTH = 10;
164 static const int64_t DEFAULT_MIN_FINALIZATION_DELAY = 2 * 60 * 60;
165 
168 
169 extern RecursiveMutex cs_main;
170 extern CTxMemPool g_mempool;
171 typedef std::unordered_map<BlockHash, CBlockIndex *, BlockHasher> BlockMap;
173 extern std::condition_variable g_best_block_cv;
174 extern uint256 g_best_block;
175 extern std::atomic_bool fImporting;
176 extern std::atomic_bool fReindex;
177 extern bool fRequireStandard;
178 extern bool fCheckBlockIndex;
179 extern bool fCheckpointsEnabled;
180 extern size_t nCoinCacheUsage;
181 
186 extern CFeeRate minRelayTxFee;
191 extern int64_t nMaxTipAge;
192 
198 
203 
208 
211 extern bool fHavePruned;
213 extern bool fPruneMode;
215 extern uint64_t nPruneTarget;
220 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
222 static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS = 288;
223 
224 static const signed int DEFAULT_CHECKBLOCKS = 6;
225 static const unsigned int DEFAULT_CHECKLEVEL = 3;
226 
240 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
241 
243 private:
245  bool checkPoW : 1;
246  bool checkMerkleRoot : 1;
247 
248 public:
249  // Do full validation by default
250  explicit BlockValidationOptions(const Config &config);
251  explicit BlockValidationOptions(uint64_t _excessiveBlockSize,
252  bool _checkPow = true,
253  bool _checkMerkleRoot = true)
254  : excessiveBlockSize(_excessiveBlockSize), checkPoW(_checkPow),
255  checkMerkleRoot(_checkMerkleRoot) {}
256 
257  BlockValidationOptions withCheckPoW(bool _checkPoW = true) const {
258  BlockValidationOptions ret = *this;
259  ret.checkPoW = _checkPoW;
260  return ret;
261  }
262 
264  withCheckMerkleRoot(bool _checkMerkleRoot = true) const {
265  BlockValidationOptions ret = *this;
266  ret.checkMerkleRoot = _checkMerkleRoot;
267  return ret;
268  }
269 
270  bool shouldValidatePoW() const { return checkPoW; }
271  bool shouldValidateMerkleRoot() const { return checkMerkleRoot; }
272  uint64_t getExcessiveBlockSize() const { return excessiveBlockSize; }
273 };
274 
278 bool LoadExternalBlockFile(const Config &config, FILE *fileIn,
279  FlatFilePos *dbp = nullptr);
280 
285 bool LoadGenesisBlock(const CChainParams &chainparams);
286 
290 void UnloadBlockIndex();
291 
295 void ThreadScriptCheck(int worker_num);
296 
300 bool GetTransaction(const TxId &txid, CTransactionRef &txOut,
301  const Consensus::Params &params, BlockHash &hashBlock,
302  const CBlockIndex *const blockIndex = nullptr);
303 
310 bool ActivateBestChain(
311  const Config &config, BlockValidationState &state,
312  std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
313 Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams);
314 
319 double GuessVerificationProgress(const ChainTxData &data,
320  const CBlockIndex *pindex);
321 
325 uint64_t CalculateCurrentUsage();
326 
330 void UnlinkPrunedFiles(const std::set<int> &setFilesToPrune);
331 
333 void PruneBlockFilesManual(int nManualPruneHeight);
334 
338 bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool,
339  TxValidationState &state, const CTransactionRef &tx,
340  bool bypass_limits, const Amount nAbsurdFee,
341  bool test_accept = false)
342  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
343 
349 protected:
350  std::atomic<int64_t> remaining;
351 
352 public:
353  explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {}
354 
355  bool consume_and_check(int consumed) {
356  auto newvalue = (remaining -= consumed);
357  return newvalue >= 0;
358  }
359 
360  bool check() { return remaining >= 0; }
361 };
362 
364 public:
366 
367  // Let's make this bad boy copiable.
369  : CheckInputsLimiter(rhs.remaining.load()) {}
370 
372  remaining = rhs.remaining.load();
373  return *this;
374  }
375 
377  TxSigCheckLimiter txLimiter;
378  // Historically, there has not been a transaction with more than 20k sig
379  // checks on testnet or mainnet, so this effectively disable sigchecks.
380  txLimiter.remaining = 20000;
381  return txLimiter;
382  }
383 };
384 
385 class ConnectTrace;
386 
416 bool CheckInputScripts(const CTransaction &tx, TxValidationState &state,
417  const CCoinsViewCache &view, const uint32_t flags,
418  bool sigCacheStore, bool scriptCacheStore,
419  const PrecomputedTransactionData &txdata,
420  int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks,
421  CheckInputsLimiter *pBlockLimitSigChecks,
422  std::vector<CScriptCheck> *pvChecks)
423  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
424 
428 static inline bool
430  const CCoinsViewCache &view, const uint32_t flags,
431  bool sigCacheStore, bool scriptCacheStore,
432  const PrecomputedTransactionData &txdata, int &nSigChecksOut)
433  EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
434  TxSigCheckLimiter nSigChecksTxLimiter;
435  return CheckInputScripts(tx, state, view, flags, sigCacheStore,
436  scriptCacheStore, txdata, nSigChecksOut,
437  nSigChecksTxLimiter, nullptr, nullptr);
438 }
439 
443 
447  const CBlockIndex *pindex);
448 
455 
462 
464 void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight);
465 
469 void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
470  int nHeight);
471 
475 void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, int nHeight);
476 void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
477  int nHeight);
478 
484  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
485 
497 bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx,
498  int flags, LockPoints *lp = nullptr,
499  bool useExistingLockPoints = false)
500  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
501 
510 private:
513  unsigned int nIn;
514  uint32_t nFlags;
521 
522 public:
524  : ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false),
525  error(ScriptError::UNKNOWN), txdata(), pTxLimitSigChecks(nullptr),
526  pBlockLimitSigChecks(nullptr) {}
527 
528  CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn,
529  unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn,
530  const PrecomputedTransactionData &txdataIn,
531  TxSigCheckLimiter *pTxLimitSigChecksIn = nullptr,
532  CheckInputsLimiter *pBlockLimitSigChecksIn = nullptr)
533  : m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn),
534  cacheStore(cacheIn), error(ScriptError::UNKNOWN), txdata(txdataIn),
535  pTxLimitSigChecks(pTxLimitSigChecksIn),
536  pBlockLimitSigChecks(pBlockLimitSigChecksIn) {}
537 
538  bool operator()();
539 
540  void swap(CScriptCheck &check) {
541  std::swap(ptxTo, check.ptxTo);
542  std::swap(m_tx_out, check.m_tx_out);
543  std::swap(nIn, check.nIn);
544  std::swap(nFlags, check.nFlags);
545  std::swap(cacheStore, check.cacheStore);
546  std::swap(error, check.error);
547  std::swap(metrics, check.metrics);
548  std::swap(txdata, check.txdata);
549  std::swap(pTxLimitSigChecks, check.pTxLimitSigChecks);
550  std::swap(pBlockLimitSigChecks, check.pBlockLimitSigChecks);
551  }
552 
553  ScriptError GetScriptError() const { return error; }
554 
556 };
557 
558 bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex);
559 
568 bool CheckBlock(const CBlock &block, BlockValidationState &state,
569  const Consensus::Params &params,
570  BlockValidationOptions validationOptions);
571 
579  const CTransaction &tx,
580  TxValidationState &state,
581  int flags = -1);
582 
587 bool TestBlockValidity(BlockValidationState &state, const CChainParams &params,
588  const CBlock &block, CBlockIndex *pindexPrev,
589  BlockValidationOptions validationOptions)
590  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
591 
596 class CVerifyDB {
597 public:
598  CVerifyDB();
599  ~CVerifyDB();
600  bool VerifyDB(const Config &config, CCoinsView *coinsview, int nCheckLevel,
601  int nCheckDepth);
602 };
603 
605  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
606 
609  const CBlockLocator &locator)
610  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
611 
613 enum class FlushStateMode { NONE, IF_NEEDED, PERIODIC, ALWAYS };
614 
617 extern std::unique_ptr<CCoinsViewCache> pcoinsTip;
618 
627 public:
628  BlockMap m_block_index GUARDED_BY(cs_main);
629 
649  std::set<CBlockIndex *> m_failed_blocks;
650 
656  std::multimap<CBlockIndex *, CBlockIndex *> m_blocks_unlinked;
657 
666  bool LoadBlockIndex(const Consensus::Params &consensus_params,
667  CBlockTreeDB &blocktree,
668  std::set<CBlockIndex *, CBlockIndexWorkComparator>
669  &block_index_candidates)
670  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
671 
673  void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
674 
675  CBlockIndex *AddToBlockIndex(const CBlockHeader &block)
676  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
678  CBlockIndex *InsertBlockIndex(const BlockHash &hash)
679  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
680 
686  bool AcceptBlockHeader(const Config &config, const CBlockHeader &block,
687  BlockValidationState &state, CBlockIndex **ppindex)
688  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
689 };
690 
700 class CoinsViews {
701 public:
704  CCoinsViewDB m_dbview GUARDED_BY(cs_main);
705 
708  CCoinsViewErrorCatcher m_catcherview GUARDED_BY(cs_main);
709 
712  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
713 
722  CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory,
723  bool should_wipe);
724 
726  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
727 };
728 
731  CRITICAL = 2,
733  LARGE = 1,
734  OK = 0
735 };
736 
751 class CChainState {
752 private:
759 
765  std::atomic<int32_t> nBlockSequenceId{1};
767  int32_t nBlockReverseSequenceId = -1;
769  arith_uint256 nLastPreciousChainwork = 0;
770 
777  mutable std::atomic<bool> m_cached_finished_ibd{false};
778 
783 
786  std::unique_ptr<CoinsViews> m_coins_views;
787 
792  const CBlockIndex *m_finalizedBlockIndex GUARDED_BY(cs_main) = nullptr;
793 
794 public:
795  explicit CChainState(BlockManager &blockman,
796  BlockHash from_snapshot_blockhash = BlockHash());
797 
804  void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe,
805  std::string leveldb_name = "chainstate");
806 
809  void InitCoinsCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
810 
814  bool CanFlushToDisk() EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
815  return m_coins_views && m_coins_views->m_cacheview;
816  }
817 
821 
828  const BlockHash m_from_snapshot_blockhash{};
829 
836  std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates;
837 
839  CCoinsViewCache &CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
840  assert(m_coins_views->m_cacheview);
841  return *m_coins_views->m_cacheview.get();
842  }
843 
845  CCoinsViewDB &CoinsDB() { return m_coins_views->m_dbview; }
846 
850  EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
851  return m_coins_views->m_catcherview;
852  }
853 
855  void ResetCoinsViews() { m_coins_views.reset(); }
856 
868  bool FlushStateToDisk(const CChainParams &chainparams,
870  int nManualPruneHeight = 0);
871 
873  void ForceFlushStateToDisk();
874 
877  void PruneAndFlush();
878 
893  bool ActivateBestChain(
894  const Config &config, BlockValidationState &state,
895  std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>())
896  LOCKS_EXCLUDED(cs_main);
897 
898  bool AcceptBlock(const Config &config,
899  const std::shared_ptr<const CBlock> &pblock,
900  BlockValidationState &state, bool fRequested,
901  const FlatFilePos *dbp, bool *fNewBlock)
902  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
903 
904  // Block (dis)connection on a given view:
905  DisconnectResult DisconnectBlock(const CBlock &block,
906  const CBlockIndex *pindex,
907  CCoinsViewCache &view);
908  bool ConnectBlock(const CBlock &block, BlockValidationState &state,
909  CBlockIndex *pindex, CCoinsViewCache &view,
910  const CChainParams &params,
911  BlockValidationOptions options, bool fJustCheck = false)
912  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
913 
914  // Block disconnection on our pcoinsTip:
915  bool DisconnectTip(const CChainParams &params, BlockValidationState &state,
916  DisconnectedBlockTransactions *disconnectpool)
917  EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::g_mempool.cs);
918 
919  // Manual block validity manipulation:
920  bool PreciousBlock(const Config &config, BlockValidationState &state,
921  CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main);
923  bool InvalidateBlock(const Config &config, BlockValidationState &state,
924  CBlockIndex *pindex)
925  LOCKS_EXCLUDED(cs_main, m_cs_chainstate);
927  bool ParkBlock(const Config &config, BlockValidationState &state,
928  CBlockIndex *pindex)
929  LOCKS_EXCLUDED(cs_main, m_cs_chainstate);
930 
935  bool FinalizeBlock(const Config &config, BlockValidationState &state,
936  CBlockIndex *pindex)
937  LOCKS_EXCLUDED(cs_main, m_cs_chainstate);
939  const CBlockIndex *GetFinalizedBlock() const
940  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
944  bool IsBlockFinalized(const CBlockIndex *pindex) const
945  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
946 
947  void ResetBlockFailureFlags(CBlockIndex *pindex)
948  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
949  template <typename F>
950  bool UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f)
951  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
952  template <typename F, typename C, typename AC>
953  void UpdateFlags(CBlockIndex *pindex, CBlockIndex *&pindexReset, F f,
954  C fChild, AC fAncestorWasChanged)
955  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
957  void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren)
958  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
959 
961  bool ReplayBlocks(const Consensus::Params &params);
962  bool LoadGenesisBlock(const CChainParams &chainparams);
963 
964  void PruneBlockIndexCandidates();
965 
966  void UnloadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
967 
972  bool IsInitialBlockDownload() const;
973 
980  void CheckBlockIndex(const Consensus::Params &consensusParams);
981 
984  bool LoadChainTip(const CChainParams &chainparams)
985  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
986 
990  CoinsCacheSizeState GetCoinsCacheSizeState(const CTxMemPool &tx_pool)
991  EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
992 
993  CoinsCacheSizeState GetCoinsCacheSizeState(
994  const CTxMemPool &tx_pool, size_t max_coins_cache_size_bytes,
995  size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
996 
997  std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
998 
999 private:
1000  bool ActivateBestChainStep(const Config &config,
1001  BlockValidationState &state,
1002  CBlockIndex *pindexMostWork,
1003  const std::shared_ptr<const CBlock> &pblock,
1004  bool &fInvalidFound, ConnectTrace &connectTrace)
1005  EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::g_mempool.cs);
1006  bool ConnectTip(const Config &config, BlockValidationState &state,
1007  CBlockIndex *pindexNew,
1008  const std::shared_ptr<const CBlock> &pblock,
1009  ConnectTrace &connectTrace,
1010  DisconnectedBlockTransactions &disconnectpool)
1011  EXCLUSIVE_LOCKS_REQUIRED(cs_main, ::g_mempool.cs);
1012  void InvalidBlockFound(CBlockIndex *pindex,
1013  const BlockValidationState &state)
1014  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1015  void InvalidChainFound(CBlockIndex *pindexNew)
1016  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1017  CBlockIndex *FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1018  bool MarkBlockAsFinal(BlockValidationState &state,
1019  const CBlockIndex *pindex)
1020  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1021  void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew,
1022  const FlatFilePos &pos)
1023  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1024 
1025  bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs,
1026  const Consensus::Params &params)
1027  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1028  bool UnwindBlock(const Config &config, BlockValidationState &state,
1029  CBlockIndex *pindex, bool invalidate)
1030  EXCLUSIVE_LOCKS_REQUIRED(m_cs_chainstate);
1031 
1033 };
1034 
1040 bool PreciousBlock(const Config &config, BlockValidationState &state,
1041  CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main);
1042 
1044 void ResetBlockFailureFlags(CBlockIndex *pindex)
1045  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1046 
1048 void UnparkBlockAndChildren(CBlockIndex *pindex)
1049  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1050 
1052 void UnparkBlock(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1053 
1087 class ChainstateManager {
1088 private:
1106  std::unique_ptr<CChainState> m_ibd_chainstate;
1107 
1119  std::unique_ptr<CChainState> m_snapshot_chainstate;
1120 
1132  CChainState *m_active_chainstate{nullptr};
1133 
1136  bool m_snapshot_validated{false};
1137 
1138  // For access to m_active_chainstate.
1139  friend CChainState &ChainstateActive();
1140  friend CChain &ChainActive();
1141 
1142 public:
1145  BlockManager m_blockman GUARDED_BY(::cs_main);
1146 
1152  CChainState &
1153  InitializeChainstate(const BlockHash &snapshot_blockhash = BlockHash())
1154  EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1155 
1157  std::vector<CChainState *> GetAll();
1158 
1160  CChain &ActiveChain() const;
1161  int ActiveHeight() const { return ActiveChain().Height(); }
1162  CBlockIndex *ActiveTip() const { return ActiveChain().Tip(); }
1163 
1164  BlockMap &BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
1165  return m_blockman.m_block_index;
1166  }
1167 
1168  bool IsSnapshotActive() const;
1169 
1170  std::optional<BlockHash> SnapshotBlockhash() const;
1171 
1173  bool IsSnapshotValidated() const { return m_snapshot_validated; }
1174 
1177  bool IsBackgroundIBD(CChainState *chainstate) const;
1178 
1183  CChainState &ValidatedChainstate() const;
1184 
1185  CChain &ValidatedChain() const { return ValidatedChainstate().m_chain; }
1186  CBlockIndex *ValidatedTip() const { return ValidatedChain().Tip(); }
1187 
1211  bool ProcessNewBlock(const Config &config,
1212  const std::shared_ptr<const CBlock> pblock,
1213  bool fForceProcessing, bool *fNewBlock)
1214  LOCKS_EXCLUDED(cs_main);
1215 
1230  bool ProcessNewBlockHeaders(const Config &config,
1231  const std::vector<CBlockHeader> &block,
1232  BlockValidationState &state,
1233  const CBlockIndex **ppindex = nullptr)
1234  LOCKS_EXCLUDED(cs_main);
1235 
1237  void PruneOneBlockFile(const int fileNumber)
1238  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1239 
1242  bool LoadBlockIndex(const Consensus::Params &params)
1243  EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1244 
1246  void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1247 
1249  void Reset();
1250 };
1251 
1256 extern ChainstateManager g_chainman GUARDED_BY(::cs_main);
1257 
1260 
1262 CChain &ChainActive();
1263 
1265 BlockMap &BlockIndex();
1266 
1270 extern std::unique_ptr<CBlockTreeDB> pblocktree;
1271 
1278 int GetSpendHeight(const CCoinsViewCache &inputs);
1279 
1283 int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev,
1284  const Consensus::Params &params);
1285 
1287 CBlockFileInfo *GetBlockFileInfo(size_t n);
1288 
1290 bool DumpMempool(const CTxMemPool &pool);
1291 
1293 bool LoadMempool(const Config &config, CTxMemPool &pool);
1294 
1296 bool IsBlockPruned(const CBlockIndex *pblockindex);
1297 
1298 #endif // BITCOIN_VALIDATION_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:338
bool shouldValidatePoW() const
Definition: validation.h:270
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:82
static const Amount DEFAULT_UTXO_FEE
Default for -excessutxocharge for transactions transactions.
Definition: validation.h:70
Display status of an in-progress BIP9 softfork.
Definition: versionbits.h:44
size_t nCoinCacheUsage
Definition: validation.cpp:103
static const int MAX_BLOCKTXN_DEPTH
Maximum depth of blocks we&#39;re willing to respond to GETBLOCKTXN requests for.
Definition: validation.h:106
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
Definition: validation.h:77
TxSigCheckLimiter(const TxSigCheckLimiter &rhs)
Definition: validation.h:368
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:105
static constexpr Amount zero()
Definition: amount.h:35
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:167
bool shouldValidateMerkleRoot() const
Definition: validation.h:271
std::unordered_map< BlockHash, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:171
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:820
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:110
uint64_t getExcessiveBlockSize() const
Definition: validation.h:272
void swap(CScriptCheck &check)
Definition: validation.h:540
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: validation.h:626
void ThreadScriptCheck(int worker_num)
Run an instance of the script checking thread.
Definition: block.h:62
The cache is at >= 90% capacity.
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:700
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1087
An in-memory indexed chain of blocks.
Definition: chain.h:152
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
void UnparkBlock(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove parked status from a block.
static void pool cs
static const int64_t DEFAULT_MAX_TIP_AGE
Definition: validation.h:127
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
Inv(ventory) message data.
Definition: protocol.h:493
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_BASE
Block download timeout base, expressed in millionths of the block interval (i.e.
Definition: validation.h:121
CBlockIndex * pindexBestHeader
Best header we&#39;ve seen so far (used for getheaders queries&#39; starting points).
Definition: validation.cpp:92
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 pr...
Definition: validation.h:220
Precompute sighash midstate to avoid quadratic hashing.
Definition: transaction.h:348
unsigned int nHeight
CChain & ValidatedChain() const
Definition: validation.h:1185
uint64_t excessiveBlockSize
Definition: validation.h:244
Definition: amount.h:17
bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp=nullptr, bool useExistingLockPoints=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check if transaction will be BIP 68 final in the next block to be created.
Definition: validation.cpp:197
The coins cache is in immediate need of a flush.
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:855
CChainState stores and provides an API to update our local knowledge of the current best chain...
Definition: validation.h:751
static constexpr Amount SATOSHI
Definition: amount.h:151
bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, TxValidationState &state, const CTransactionRef &tx, bool bypass_limits, const Amount nAbsurdFee, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
(try to) add transaction to memory pool
Definition: validation.cpp:776
static const uint64_t MAX_TX_SIGCHECKS
Allowed number of signature check operations per transaction.
Definition: consensus.h:22
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:47
ScriptError error
Definition: validation.h:516
CCoinsViewDB & CoinsDB()
Definition: validation.h:845
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
Definition: versionbits.h:26
ScriptError
Definition: script_error.h:9
void ResetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove invalidity status from a block and its descendants.
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:515
bool LoadMempool(const Config &config, CTxMemPool &pool)
Load the mempool from disk.
CTxOut m_tx_out
Definition: validation.h:511
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...
BlockValidationOptions withCheckMerkleRoot(bool _checkMerkleRoot=true) const
Definition: validation.h:264
Called by RandAddPeriodic()
TxSigCheckLimiter & operator=(const TxSigCheckLimiter &rhs)
Definition: validation.h:371
CBlockIndex * LookupBlockIndex(const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:140
CheckInputsLimiter * pBlockLimitSigChecks
Definition: validation.h:520
std::multimap< CBlockIndex *, CBlockIndex * > m_blocks_unlinked
All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
Definition: validation.h:656
static const int64_t DEFAULT_MIN_FINALIZATION_DELAY
Default for -finalizationdelay This is the minimum time between a block header reception and the bloc...
Definition: validation.h:164
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for itself and all ancestors) and a...
Definition: validation.h:836
static const Amount DEFAULT_MIN_RELAY_TX_FEE_PER_KB(1000 *SATOSHI)
Default for -minrelaytxfee, minimum relay fee for transactions.
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:67
static const bool DEFAULT_PERSIST_MEMPOOL
Default for -persistmempool.
Definition: validation.h:139
Struct for holding cumulative results from executing a script or a sequence of scripts.
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:152
static const int64_t BLOCK_DOWNLOAD_TIMEOUT_PER_PEER
Additional block download timeout per parallel downloading peer (i.e.
Definition: validation.h:125
static TxSigCheckLimiter getDisabled()
Definition: validation.h:376
Simple class for regulating resource usage during CheckInputScripts (and CScriptCheck), atomic so as to be compatible with parallel validation.
Definition: validation.h:348
static const unsigned int NODE_NETWORK_LIMITED_MIN_BLOCKS
Minimum blocks required to signal NODE_NETWORK_LIMITED.
Definition: validation.h:222
bool ContextualCheckTransactionForCurrentBlock(const Consensus::Params &params, const CTransaction &tx, TxValidationState &state, int flags=-1)
This is a variant of ContextualCheckTransaction which computes the contextual check for a transaction...
bool LoadExternalBlockFile(const Config &config, FILE *fileIn, FlatFilePos *dbp=nullptr)
Import blocks from an external file.
Definition: config.h:19
Access to the block database (blocks/index/)
Definition: txdb.h:96
Abstract view on the open txout dataset.
Definition: coins.h:148
RecursiveMutex m_cs_chainstate
the ChainState CriticalSection A lock that must be held when modifying this ChainState - held in Acti...
Definition: validation.h:758
DeploymentPos
Definition: params.h:16
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
bool consume_and_check(int consumed)
Definition: validation.h:355
bool fHavePruned
Pruning-related variables and constants.
Definition: validation.cpp:98
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:132
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:86
bool IsSnapshotValidated() const
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1173
FlushStateMode
Definition: validation.h:613
bool ActivateBestChain(const Config &config, BlockValidationState &state, 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.
static const unsigned int MAX_HEADERS_RESULTS
Number of headers sent in one getheaders result.
Definition: validation.h:97
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:596
CChain & ChainActive()
Definition: validation.cpp:73
int ActiveHeight() const
Definition: validation.h:1161
bool TestLockPointValidity(const LockPoints *lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Test whether the LockPoints height and time are still valid on the current chain. ...
Definition: validation.cpp:178
ThresholdState VersionBitsBlockState(const Consensus::Params &params, Consensus::DeploymentPos pos, const CBlockIndex *pindex)
Get the BIP9 state for a given deployment at a given block.
Holds various statistics on transactions within a chain.
Definition: chainparams.h:34
static const unsigned int DEFAULT_MEMPOOL_EXPIRY
Default for -mempoolexpiry, expiration time for mempool transactions in hours.
Definition: validation.h:75
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:155
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &params, BlockValidationOptions validationOptions)
Functions for validating blocks and updating the block tree.
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
Definition: validation.cpp:108
static const bool DEFAULT_FEEFILTER
Default for using fee filter.
Definition: validation.h:141
Definition: net.h:177
ChainstateManager g_chainman
Definition: validation.cpp:65
bool PreciousBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
Mark a block as precious and reorganize.
An output of a transaction.
Definition: transaction.h:141
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
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:786
Parameters that influence chain consensus.
Definition: params.h:59
static const char *const DEFAULT_BLOCKFILTERINDEX
Definition: validation.h:136
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Determine what nVersion a new block should use.
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:116
uint64_t nPruneTarget
Number of MiB of block files that we&#39;re trying to stay below.
Definition: validation.cpp:104
uint256 g_best_block
Definition: validation.cpp:95
PrecomputedTransactionData txdata
Definition: validation.h:518
Closure representing one script verification.
Definition: validation.h:509
static const int MAX_UNCONNECTING_HEADERS
Maximum number of unconnecting headers announcements before DoS score.
Definition: validation.h:150
DisconnectResult
int flags
Definition: bitcoin-tx.cpp:529
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation) ...
Definition: validation.cpp:110
std::condition_variable g_best_block_cv
Definition: validation.cpp:94
std::atomic_bool fReindex
256-bit opaque blob.
Definition: uint256.h:120
CoinsCacheSizeState
Definition: validation.h:729
const CTransaction * ptxTo
Definition: validation.h:512
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:134
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
bool CheckInputScripts(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &view, const uint32_t flags, bool sigCacheStore, bool scriptCacheStore, const PrecomputedTransactionData &txdata, int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks, CheckInputsLimiter *pBlockLimitSigChecks, std::vector< CScriptCheck > *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check whether all of this transaction&#39;s input scripts succeed.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:468
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:55
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:90
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
BlockValidationOptions withCheckPoW(bool _checkPoW=true) const
Definition: validation.h:257
CTxMemPool g_mempool
Definition: validation.cpp:112
bool fRequireStandard
Definition: validation.cpp:100
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: blockindex.h:23
const CChainParams & Params()
Return the currently selected parameters.
bool IsBlockPruned(const CBlockIndex *pblockindex)
Check whether the block associated with this index entry is pruned or not.
Undo information for a CBlock.
Definition: undo.h:73
std::unique_ptr< CChainState > m_snapshot_chainstate
A chainstate initialized on the basis of a UTXO snapshot.
Definition: validation.h:1119
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:224
Restore the UTXO in a Coin at a given COutPoint.
Definition: undo.h:62
A TxId is the identifier of a transaction.
Definition: txid.h:14
ChainstateManager g_chainman GUARDED_BY(::cs_main)
DEPRECATED! Please use node.chainman instead.
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:49
std::unique_ptr< CChainState > m_ibd_chainstate
The chainstate used under normal operation (i.e.
Definition: validation.h:1106
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
std::atomic< int64_t > remaining
Definition: validation.h:350
CChainState &InitializeChainstate(const BlockHash &snapshot_blockhash=BlockHash()) EXCLUSIVE_LOCKS_REQUIRED(std::vector< CChainState * > GetAll()
Instantiate a new chainstate and assign it based upon whether it is from a snapshot.
Definition: validation.h:1157
static const unsigned int MAX_BLOCKS_TO_ANNOUNCE
Maximum number of headers to announce when relaying blocks with headers message.
Definition: validation.h:147
bool DumpMempool(const CTxMemPool &pool)
Dump the mempool to disk.
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all CChainState instances...
Definition: validation.h:782
static const int DEFAULT_MAX_REORG_DEPTH
Default for -maxreorgdepth.
Definition: validation.h:157
CBlockIndex * ValidatedTip() const
Definition: validation.h:1186
bool GetTransaction(const TxId &txid, CTransactionRef &txOut, const Consensus::Params &params, BlockHash &hashBlock, const CBlockIndex *const blockIndex=nullptr)
Retrieve a transaction (from memory pool, or from disk, if possible).
Definition: validation.cpp:789
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:839
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Find the last common block between the parameter chain and a locator.
Definition: validation.cpp:146
unsigned int nIn
Definition: validation.h:513
CChainState & ChainstateActive()
Definition: validation.cpp:67
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:91
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:102
bool TestBlockValidity(BlockValidationState &state, const CChainParams &params, const CBlock &block, CBlockIndex *pindexPrev, BlockValidationOptions validationOptions) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check a block is completely valid from start to finish (only works on top of our current best block) ...
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:211
ScriptExecutionMetrics GetScriptExecutionMetrics() const
Definition: validation.h:555
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn, const PrecomputedTransactionData &txdataIn, TxSigCheckLimiter *pTxLimitSigChecksIn=nullptr, CheckInputsLimiter *pBlockLimitSigChecksIn=nullptr)
Definition: validation.h:528
bool fPruneMode
True if we&#39;re running in -prune mode.
Definition: validation.cpp:99
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:204
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev...
Definition: validation.h:240
static const unsigned int DATABASE_FLUSH_INTERVAL
Time to wait (in seconds) between flushing chainstate to disk.
Definition: validation.h:118
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...
bool fCheckpointsEnabled
Definition: validation.cpp:102
bool LoadGenesisBlock(const CChainParams &chainparams)
Ensures we have a genesis block in the block tree, possibly writing one to disk.
ScriptExecutionMetrics metrics
Definition: validation.h:517
std::set< CBlockIndex * > m_failed_blocks
In order to efficiently track invalidity of headers, we keep the set of blocks which we tried to conn...
Definition: validation.h:649
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate...
Definition: coins.h:334
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
ScriptError GetScriptError() const
Definition: validation.h:553
BlockHash hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:107
void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
Mark all the coins corresponding to a given transaction inputs as spent.
TxSigCheckLimiter * pTxLimitSigChecks
Definition: validation.h:519
bool error(const char *fmt, const Args &... args)
Definition: system.h:47
std::unique_ptr< CBlockTreeDB > pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: validation.cpp:166
static const bool DEFAULT_TXINDEX
Definition: validation.h:135
void UnloadBlockIndex()
Unload database information.
BlockValidationOptions(uint64_t _excessiveBlockSize, bool _checkPow=true, bool _checkMerkleRoot=true)
Definition: validation.h:251
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:22
static const unsigned int BLOCK_DOWNLOAD_WINDOW
Size of the "block download window": how far ahead of our current height do we fetch ...
Definition: validation.h:114
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:849
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:225
uint32_t nFlags
Definition: validation.h:514
bool fCheckBlockIndex
Definition: validation.cpp:101
BlockMap & BlockIndex()
Definition: validation.cpp:926
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:80
void UnparkBlockAndChildren(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove parked status from a block and its descendants.
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
Definition: validation.cpp:849
CBlockIndex * ActiveTip() const
Definition: validation.h:1162
LockPoints lp
Used to track blocks whose transactions were applied to the UTXO state as a part of a single Activate...
Mutex g_best_block_mutex
Definition: validation.cpp:93
CheckInputsLimiter(int64_t limit)
Definition: validation.h:353
BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1164