Bitcoin ABC  0.26.3
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 <arith_uint256.h>
15 #include <attributes.h>
16 #include <blockfileinfo.h>
17 #include <blockindexcomparators.h>
18 #include <bloom.h>
19 #include <chain.h>
20 #include <chainparams.h>
21 #include <config.h>
22 #include <consensus/amount.h>
23 #include <consensus/consensus.h>
24 #include <disconnectresult.h>
25 #include <flatfile.h>
26 #include <fs.h>
28 #include <kernel/cs_main.h>
29 #include <node/blockstorage.h>
30 #include <policy/packages.h>
31 #include <script/script_error.h>
32 #include <script/script_metrics.h>
33 #include <shutdown.h>
34 #include <sync.h>
35 #include <txdb.h>
36 #include <txmempool.h> // For CTxMemPool::cs
37 #include <uint256.h>
38 #include <util/check.h>
39 #include <util/translation.h>
40 
41 #include <atomic>
42 #include <cstdint>
43 #include <map>
44 #include <memory>
45 #include <optional>
46 #include <set>
47 #include <string>
48 #include <thread>
49 #include <utility>
50 #include <vector>
51 
53 class CChainParams;
54 class Chainstate;
55 class ChainstateManager;
56 class CScriptCheck;
57 class CTxMemPool;
58 class CTxUndo;
60 
61 struct ChainTxData;
62 struct FlatFilePos;
64 struct LockPoints;
65 struct AssumeutxoData;
66 namespace node {
67 class SnapshotMetadata;
68 } // namespace node
69 namespace Consensus {
70 struct Params;
71 } // namespace Consensus
72 
73 namespace Consensus {
74 struct Params;
75 }
76 
77 #define MIN_TRANSACTION_SIZE \
78  (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))
79 
81 static const int MAX_SCRIPTCHECK_THREADS = 15;
83 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
84 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
85 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
86 
87 static const bool DEFAULT_PEERBLOOMFILTERS = true;
88 
90 static const int DEFAULT_STOPATHEIGHT = 0;
95 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
96 static const signed int DEFAULT_CHECKBLOCKS = 6;
97 static const unsigned int DEFAULT_CHECKLEVEL = 3;
111 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
112 
115 
117 extern std::condition_variable g_best_block_cv;
119 extern uint256 g_best_block;
120 extern bool fCheckBlockIndex;
121 extern bool fCheckpointsEnabled;
122 
127 extern int64_t nMaxTipAge;
128 
134 
139 
141 extern const std::vector<std::string> CHECKLEVEL_DOC;
142 
144 private:
146  bool checkPoW : 1;
147  bool checkMerkleRoot : 1;
148 
149 public:
150  // Do full validation by default
151  explicit BlockValidationOptions(const Config &config);
152  explicit BlockValidationOptions(uint64_t _excessiveBlockSize,
153  bool _checkPow = true,
154  bool _checkMerkleRoot = true)
155  : excessiveBlockSize(_excessiveBlockSize), checkPoW(_checkPow),
156  checkMerkleRoot(_checkMerkleRoot) {}
157 
158  BlockValidationOptions withCheckPoW(bool _checkPoW = true) const {
159  BlockValidationOptions ret = *this;
160  ret.checkPoW = _checkPoW;
161  return ret;
162  }
163 
165  withCheckMerkleRoot(bool _checkMerkleRoot = true) const {
166  BlockValidationOptions ret = *this;
167  ret.checkMerkleRoot = _checkMerkleRoot;
168  return ret;
169  }
170 
171  bool shouldValidatePoW() const { return checkPoW; }
172  bool shouldValidateMerkleRoot() const { return checkMerkleRoot; }
173  uint64_t getExcessiveBlockSize() const { return excessiveBlockSize; }
174 };
175 
179 void StartScriptCheckWorkerThreads(int threads_num);
180 
185 
186 Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams);
187 
188 bool AbortNode(BlockValidationState &state, const std::string &strMessage,
189  const bilingual_str &userMessage = bilingual_str{});
190 
195 double GuessVerificationProgress(const ChainTxData &data,
196  const CBlockIndex *pindex);
197 
199 void PruneBlockFilesManual(Chainstate &active_chainstate,
200  int nManualPruneHeight);
201 
207  enum class ResultType {
209  VALID,
211  INVALID,
214  };
217 
218  // The following fields are only present when m_result_type =
219  // ResultType::VALID or MEMPOOL_ENTRY
224  const std::optional<int64_t> m_vsize;
226  const std::optional<Amount> m_base_fees;
228  return MempoolAcceptResult(state);
229  }
230 
232  static MempoolAcceptResult Success(int64_t vsize, Amount fees) {
233  return MempoolAcceptResult(ResultType::VALID, vsize, fees);
234  }
235 
240  static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees) {
241  return MempoolAcceptResult(ResultType::MEMPOOL_ENTRY, vsize, fees);
242  }
243 
244  // Private constructors. Use static methods MempoolAcceptResult::Success,
245  // etc. to construct.
246 private:
249  : m_result_type(ResultType::INVALID), m_state(state),
250  m_base_fees(std::nullopt) {
251  // Can be invalid or error
252  Assume(!state.IsValid());
253  }
254 
256  explicit MempoolAcceptResult(ResultType result_type, int64_t vsize,
257  Amount fees)
258  : m_result_type(result_type), m_vsize{vsize}, m_base_fees(fees) {}
259 };
260 
273  std::map<const TxId, const MempoolAcceptResult> m_tx_results;
274 
277  std::map<const TxId, const MempoolAcceptResult> &&results)
278  : m_state{state}, m_tx_results(std::move(results)) {}
279 
284  explicit PackageMempoolAcceptResult(const TxId &txid,
285  const MempoolAcceptResult &result)
286  : m_tx_results{{txid, result}} {}
287 };
288 
312 AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx,
313  int64_t accept_time, bool bypass_limits,
314  bool test_accept = false, unsigned int heightOverride = 0)
316 
329 ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool,
330  const Package &txns, bool test_accept)
332 
338 protected:
339  std::atomic<int64_t> remaining;
340 
341 public:
342  explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {}
343 
344  bool consume_and_check(int consumed) {
345  auto newvalue = (remaining -= consumed);
346  return newvalue >= 0;
347  }
348 
349  bool check() { return remaining >= 0; }
350 };
351 
353 public:
355 
356  // Let's make this bad boy copiable.
358  : CheckInputsLimiter(rhs.remaining.load()) {}
359 
361  remaining = rhs.remaining.load();
362  return *this;
363  }
364 
366  TxSigCheckLimiter txLimiter;
367  // Historically, there has not been a transaction with more than 20k sig
368  // checks on testnet or mainnet, so this effectively disable sigchecks.
369  txLimiter.remaining = 20000;
370  return txLimiter;
371  }
372 };
373 
374 class ConnectTrace;
375 
405 bool CheckInputScripts(const CTransaction &tx, TxValidationState &state,
406  const CCoinsViewCache &view, const uint32_t flags,
407  bool sigCacheStore, bool scriptCacheStore,
408  const PrecomputedTransactionData &txdata,
409  int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks,
410  CheckInputsLimiter *pBlockLimitSigChecks,
411  std::vector<CScriptCheck> *pvChecks)
413 
417 static inline bool
419  const CCoinsViewCache &view, const uint32_t flags,
420  bool sigCacheStore, bool scriptCacheStore,
421  const PrecomputedTransactionData &txdata, int &nSigChecksOut)
423  TxSigCheckLimiter nSigChecksTxLimiter;
424  return CheckInputScripts(tx, state, view, flags, sigCacheStore,
425  scriptCacheStore, txdata, nSigChecksOut,
426  nSigChecksTxLimiter, nullptr, nullptr);
427 }
428 
432 void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
433  int nHeight);
434 
438 void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
439  int nHeight);
440 
459 bool CheckSequenceLocksAtTip(CBlockIndex *tip, const CCoinsView &coins_view,
460  const CTransaction &tx, LockPoints *lp = nullptr,
461  bool useExistingLockPoints = false);
462 
471 private:
474  unsigned int nIn;
475  uint32_t nFlags;
482 
483 public:
485  : ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false),
487  pBlockLimitSigChecks(nullptr) {}
488 
489  CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn,
490  unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn,
491  const PrecomputedTransactionData &txdataIn,
492  TxSigCheckLimiter *pTxLimitSigChecksIn = nullptr,
493  CheckInputsLimiter *pBlockLimitSigChecksIn = nullptr)
494  : m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn),
495  cacheStore(cacheIn), error(ScriptError::UNKNOWN), txdata(txdataIn),
496  pTxLimitSigChecks(pTxLimitSigChecksIn),
497  pBlockLimitSigChecks(pBlockLimitSigChecksIn) {}
498 
499  bool operator()();
500 
501  void swap(CScriptCheck &check) noexcept {
502  std::swap(ptxTo, check.ptxTo);
503  std::swap(m_tx_out, check.m_tx_out);
504  std::swap(nIn, check.nIn);
505  std::swap(nFlags, check.nFlags);
506  std::swap(cacheStore, check.cacheStore);
507  std::swap(error, check.error);
508  std::swap(metrics, check.metrics);
509  std::swap(txdata, check.txdata);
510  std::swap(pTxLimitSigChecks, check.pTxLimitSigChecks);
511  std::swap(pBlockLimitSigChecks, check.pBlockLimitSigChecks);
512  }
513 
514  ScriptError GetScriptError() const { return error; }
515 
517 };
518 
527 bool CheckBlock(const CBlock &block, BlockValidationState &state,
528  const Consensus::Params &params,
529  BlockValidationOptions validationOptions);
530 
538  const CBlockIndex *active_chain_tip, const Consensus::Params &params,
539  const CTransaction &tx, TxValidationState &state)
541 
547  BlockValidationState &state, const CChainParams &params,
548  Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev,
549  const std::function<NodeClock::time_point()> &adjusted_time_callback,
551 
555 bool HasValidProofOfWork(const std::vector<CBlockHeader> &headers,
556  const Consensus::Params &consensusParams);
557 
559 arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader> &headers);
560 
561 enum class VerifyDBResult {
562  SUCCESS,
564  INTERRUPTED,
567 };
568 
573 class CVerifyDB {
574 public:
575  CVerifyDB();
576 
577  ~CVerifyDB();
578 
579  [[nodiscard]] VerifyDBResult
580  VerifyDB(Chainstate &chainstate, const Config &config,
581  CCoinsView &coinsview, int nCheckLevel, int nCheckDepth)
583 };
584 
587 
597 class CoinsViews {
598 public:
602 
606 
609  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
610 
619  CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory,
620  bool should_wipe);
621 
623  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
624 };
625 
628  CRITICAL = 2,
630  LARGE = 1,
631  OK = 0
632 };
633 
648 class Chainstate {
649 protected:
655 
661  std::atomic<int32_t> nBlockSequenceId{1};
663  int32_t nBlockReverseSequenceId = -1;
665  arith_uint256 nLastPreciousChainwork = 0;
666 
673  mutable std::atomic<bool> m_cached_finished_ibd{false};
674 
678 
681  std::unique_ptr<CoinsViews> m_coins_views;
682 
695  bool m_disabled GUARDED_BY(::cs_main){false};
696 
698 
703  const CBlockIndex *m_avalancheFinalizedBlockIndex
704  GUARDED_BY(cs_avalancheFinalizedBlockIndex) = nullptr;
705 
712  CRollingBloomFilter m_filterParkingPoliciesApplied =
713  CRollingBloomFilter{1000, 0.000001};
714 
715  CBlockIndex const *m_best_fork_tip = nullptr;
716  CBlockIndex const *m_best_fork_base = nullptr;
717 
718 public:
722 
727 
728  explicit Chainstate(
729  CTxMemPool *mempool, node::BlockManager &blockman,
730  ChainstateManager &chainman,
731  std::optional<BlockHash> from_snapshot_blockhash = std::nullopt);
732 
739  void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe,
740  std::string leveldb_name = "chainstate");
741 
744  void InitCoinsCache(size_t cache_size_bytes)
746 
750  bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
752  return m_coins_views && m_coins_views->m_cacheview;
753  }
754 
758 
765  const std::optional<BlockHash> m_from_snapshot_blockhash{};
766 
770  return m_from_snapshot_blockhash.has_value();
771  }
772 
780  std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates;
781 
785  Assert(m_coins_views);
786  return *Assert(m_coins_views->m_cacheview);
787  }
788 
792  return Assert(m_coins_views)->m_dbview;
793  }
794 
796  CTxMemPool *GetMempool() { return m_mempool; }
797 
803  return Assert(m_coins_views)->m_catcherview;
804  }
805 
807  void ResetCoinsViews() { m_coins_views.reset(); }
808 
810  bool HasCoinsViews() const { return (bool)m_coins_views; }
811 
813  size_t m_coinsdb_cache_size_bytes{0};
814 
816  size_t m_coinstip_cache_size_bytes{0};
817 
820  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
822 
854  void LoadExternalBlockFile(
855  const Config &config, FILE *fileIn, FlatFilePos *dbp = nullptr,
856  std::multimap<BlockHash, FlatFilePos> *blocks_with_unknown_parent =
857  nullptr) EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
858  !cs_avalancheFinalizedBlockIndex);
859 
871  bool FlushStateToDisk(BlockValidationState &state, FlushStateMode mode,
872  int nManualPruneHeight = 0);
873 
875  void ForceFlushStateToDisk();
876 
879  void PruneAndFlush();
880 
902  bool ActivateBestChain(BlockValidationState &state,
903  std::shared_ptr<const CBlock> pblock = nullptr)
904  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
905  !cs_avalancheFinalizedBlockIndex)
907 
908  bool AcceptBlock(const Config &config,
909  const std::shared_ptr<const CBlock> &pblock,
910  BlockValidationState &state, bool fRequested,
911  const FlatFilePos *dbp, bool *fNewBlock,
912  bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
913 
914  // Block (dis)connection on a given view:
915  DisconnectResult DisconnectBlock(const CBlock &block,
916  const CBlockIndex *pindex,
917  CCoinsViewCache &view)
919  bool ConnectBlock(const CBlock &block, BlockValidationState &state,
920  CBlockIndex *pindex, CCoinsViewCache &view,
921  BlockValidationOptions options,
922  Amount *blockFees = nullptr, bool fJustCheck = false)
924 
925  // Apply the effects of a block disconnection on the UTXO set.
926  bool DisconnectTip(BlockValidationState &state,
927  DisconnectedBlockTransactions *disconnectpool)
929 
930  // Manual block validity manipulation:
936  bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex)
937  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
938  !cs_avalancheFinalizedBlockIndex)
941  bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex)
943  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
944  !cs_avalancheFinalizedBlockIndex);
946  bool ParkBlock(BlockValidationState &state, CBlockIndex *pindex)
948  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
949  !cs_avalancheFinalizedBlockIndex);
950 
954  bool AvalancheFinalizeBlock(CBlockIndex *pindex)
955  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
956 
960  void ClearAvalancheFinalizedBlock()
961  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
962 
966  bool IsBlockAvalancheFinalized(const CBlockIndex *pindex) const
967  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
968 
970  void ResetBlockFailureFlags(CBlockIndex *pindex)
972  template <typename F>
973  bool UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f)
975  template <typename F, typename C, typename AC>
976  void UpdateFlags(CBlockIndex *pindex, CBlockIndex *&pindexReset, F f,
977  C fChild, AC fAncestorWasChanged)
979 
981  void UnparkBlockAndChildren(CBlockIndex *pindex)
983 
985  void UnparkBlock(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
986 
988  bool ReplayBlocks();
989 
994  bool LoadGenesisBlock();
995 
996  void PruneBlockIndexCandidates();
997 
998  void UnloadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
999 
1004  bool IsInitialBlockDownload() const;
1005 
1007  const CBlockIndex *FindForkInGlobalIndex(const CBlockLocator &locator) const
1009 
1016  void CheckBlockIndex();
1017 
1019  void
1020  LoadMempool(const fs::path &load_path,
1021  fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
1022 
1025  bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1026 
1030  CoinsCacheSizeState GetCoinsCacheSizeState()
1032 
1034  GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes,
1035  size_t max_mempool_size_bytes)
1037 
1039 
1042  RecursiveMutex *MempoolMutex() const LOCK_RETURNED(m_mempool->cs) {
1043  return m_mempool ? &m_mempool->cs : nullptr;
1044  }
1045 
1046 private:
1047  bool ActivateBestChainStep(BlockValidationState &state,
1048  CBlockIndex *pindexMostWork,
1049  const std::shared_ptr<const CBlock> &pblock,
1050  bool &fInvalidFound, ConnectTrace &connectTrace)
1051  EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs,
1052  !cs_avalancheFinalizedBlockIndex);
1053  bool ConnectTip(BlockValidationState &state,
1054  BlockPolicyValidationState &blockPolicyState,
1055  CBlockIndex *pindexNew,
1056  const std::shared_ptr<const CBlock> &pblock,
1057  ConnectTrace &connectTrace,
1058  DisconnectedBlockTransactions &disconnectpool)
1059  EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs,
1060  !cs_avalancheFinalizedBlockIndex);
1061  void InvalidBlockFound(CBlockIndex *pindex,
1062  const BlockValidationState &state)
1063  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1064  CBlockIndex *
1065  FindMostWorkChain(std::vector<const CBlockIndex *> &blocksToReconcile)
1066  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1067  void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew,
1068  const FlatFilePos &pos)
1070 
1071  bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs)
1073 
1074  void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren)
1076 
1077  bool UnwindBlock(BlockValidationState &state, CBlockIndex *pindex,
1078  bool invalidate)
1079  EXCLUSIVE_LOCKS_REQUIRED(m_chainstate_mutex,
1080  !cs_avalancheFinalizedBlockIndex);
1081 
1082  void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1083  void CheckForkWarningConditionsOnNewFork(CBlockIndex *pindexNewForkTip)
1085  void InvalidChainFound(CBlockIndex *pindexNew)
1086  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1087 
1088  const CBlockIndex *FindBlockToFinalize(CBlockIndex *pindexNew)
1090 
1094  void UpdateTip(const CBlockIndex *pindexNew)
1096 
1097  std::chrono::microseconds m_last_write{0};
1098  std::chrono::microseconds m_last_flush{0};
1099 
1104  void InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1105 
1107 };
1108 
1110  SUCCESS,
1111  SKIPPED,
1112 
1113  // Expected assumeutxo configuration data is not found for the height of the
1114  // base block.
1116 
1117  // Failed to generate UTXO statistics (to check UTXO set hash) for the
1118  // background chainstate.
1119  STATS_FAILED,
1120 
1121  // The UTXO set hash of the background validation chainstate does not match
1122  // the one expected by assumeutxo chainparams.
1123  HASH_MISMATCH,
1124 
1125  // The blockhash of the current tip of the background validation chainstate
1126  // does not match the one expected by the snapshot chainstate.
1128 };
1129 
1158 private:
1174  std::unique_ptr<Chainstate> m_ibd_chainstate GUARDED_BY(::cs_main);
1175 
1185  std::unique_ptr<Chainstate> m_snapshot_chainstate GUARDED_BY(::cs_main);
1186 
1196  Chainstate *m_active_chainstate GUARDED_BY(::cs_main){nullptr};
1197 
1198  CBlockIndex *m_best_invalid GUARDED_BY(::cs_main){nullptr};
1199  CBlockIndex *m_best_parked GUARDED_BY(::cs_main){nullptr};
1200 
1202  [[nodiscard]] bool
1203  PopulateAndValidateSnapshot(Chainstate &snapshot_chainstate,
1204  AutoFile &coins_file,
1205  const node::SnapshotMetadata &metadata);
1214  bool AcceptBlockHeader(const Config &config, const CBlockHeader &block,
1215  BlockValidationState &state, CBlockIndex **ppindex,
1216  bool min_pow_checked)
1218  friend Chainstate;
1219 
1221  const CBlockIndex *GetSnapshotBaseBlock() const
1223 
1226  std::optional<int> GetSnapshotBaseHeight() const
1228 
1234  bool IsUsable(const Chainstate *const pchainstate) const
1236  return pchainstate && !pchainstate->m_disabled;
1237  }
1238 
1240  SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main){};
1241 
1242 public:
1244 
1245  explicit ChainstateManager(Options options)
1246  : m_options{std::move(options)} {
1247  Assert(m_options.adjusted_time_callback);
1248  }
1249 
1250  const Config &GetConfig() const { return m_options.config; }
1251 
1252  const CChainParams &GetParams() const {
1253  return m_options.config.GetChainParams();
1254  }
1256  return m_options.config.GetChainParams().GetConsensus();
1257  }
1258 
1272  }
1273 
1275  std::thread m_load_block;
1279 
1299  std::set<CBlockIndex *> m_failed_blocks;
1300 
1305  CBlockIndex *m_best_header GUARDED_BY(::cs_main){nullptr};
1306 
1309  int64_t m_total_coinstip_cache{0};
1310  //
1313  int64_t m_total_coinsdb_cache{0};
1314 
1318  // constructor
1319  Chainstate &InitializeChainstate(CTxMemPool *mempool)
1321 
1323  std::vector<Chainstate *> GetAll();
1324 
1338  [[nodiscard]] bool ActivateSnapshot(AutoFile &coins_file,
1339  const node::SnapshotMetadata &metadata,
1340  bool in_memory);
1341 
1349  SnapshotCompletionResult MaybeCompleteSnapshotValidation(
1350  std::function<void(bilingual_str)> shutdown_fnc =
1351  [](bilingual_str msg) { AbortNode(msg.original, msg); })
1353 
1355  Chainstate &ActiveChainstate() const;
1357  return ActiveChainstate().m_chain;
1358  }
1359  int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
1360  return ActiveChain().Height();
1361  }
1363  return ActiveChain().Tip();
1364  }
1365 
1368  return m_blockman.m_block_index;
1369  }
1370 
1373  bool IsSnapshotActive() const;
1374 
1375  std::optional<BlockHash> SnapshotBlockhash() const;
1376 
1379  return m_snapshot_chainstate && m_ibd_chainstate &&
1380  m_ibd_chainstate->m_disabled;
1381  }
1382 
1411  bool ProcessNewBlock(const Config &config,
1412  const std::shared_ptr<const CBlock> &block,
1413  bool force_processing, bool min_pow_checked,
1414  bool *new_block) LOCKS_EXCLUDED(cs_main);
1415 
1432  bool ProcessNewBlockHeaders(const Config &config,
1433  const std::vector<CBlockHeader> &block,
1434  bool min_pow_checked,
1435  BlockValidationState &state,
1436  const CBlockIndex **ppindex = nullptr)
1438 
1447  [[nodiscard]] MempoolAcceptResult
1448  ProcessTransaction(const CTransactionRef &tx, bool test_accept = false)
1450 
1453  bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1454 
1457  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1458 
1465  void ReportHeadersPresync(const arith_uint256 &work, int64_t height,
1466  int64_t timestamp);
1467 
1470  bool DetectSnapshotChainstate(CTxMemPool *mempool)
1472 
1473  void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1474 
1477  Chainstate &ActivateExistingSnapshot(CTxMemPool *mempool,
1478  BlockHash base_blockhash)
1480 
1490  bool ValidatedSnapshotCleanup() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1491 };
1492 
1500 const AssumeutxoData *ExpectedAssumeutxo(const int height,
1501  const CChainParams &params);
1502 
1503 #endif // BITCOIN_VALIDATION_H
int flags
Definition: bitcoin-tx.cpp:533
@ UNKNOWN
Unused.
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
Definition: check.h:84
#define Assume(val)
Assume is the identity function.
Definition: check.h:97
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:545
uint64_t getExcessiveBlockSize() const
Definition: validation.h:173
BlockValidationOptions withCheckPoW(bool _checkPoW=true) const
Definition: validation.h:158
BlockValidationOptions(uint64_t _excessiveBlockSize, bool _checkPow=true, bool _checkMerkleRoot=true)
Definition: validation.h:152
BlockValidationOptions withCheckMerkleRoot(bool _checkMerkleRoot=true) const
Definition: validation.h:165
BlockValidationOptions(const Config &config)
Definition: validation.cpp:120
bool shouldValidatePoW() const
Definition: validation.h:171
uint64_t excessiveBlockSize
Definition: validation.h:145
bool shouldValidateMerkleRoot() const
Definition: validation.h:172
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:23
Definition: block.h:60
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:26
An in-memory indexed chain of blocks.
Definition: chain.h:140
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:74
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:203
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:56
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Definition: coins.h:339
Abstract view on the open txout dataset.
Definition: coins.h:147
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:119
Closure representing one script verification.
Definition: validation.h:470
bool operator()()
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:489
ScriptError GetScriptError() const
Definition: validation.h:514
ScriptExecutionMetrics GetScriptExecutionMetrics() const
Definition: validation.h:516
uint32_t nFlags
Definition: validation.h:475
TxSigCheckLimiter * pTxLimitSigChecks
Definition: validation.h:480
ScriptExecutionMetrics metrics
Definition: validation.h:478
CTxOut m_tx_out
Definition: validation.h:472
void swap(CScriptCheck &check) noexcept
Definition: validation.h:501
bool cacheStore
Definition: validation.h:476
ScriptError error
Definition: validation.h:477
PrecomputedTransactionData txdata
Definition: validation.h:479
const CTransaction * ptxTo
Definition: validation.h:473
unsigned int nIn
Definition: validation.h:474
CheckInputsLimiter * pBlockLimitSigChecks
Definition: validation.h:481
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:192
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:209
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:296
An output of a transaction.
Definition: transaction.h:128
Restore the UTXO in a Coin at a given COutPoint.
Definition: undo.h:62
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:573
VerifyDBResult VerifyDB(Chainstate &chainstate, const Config &config, CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:648
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries with either BLOCK_VALID_TRANSACTIONS (for itself and all ancestors...
Definition: validation.h:780
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:800
CTxMemPool * GetMempool()
Definition: validation.h:796
Mutex m_chainstate_mutex
The ChainState Mutex.
Definition: validation.h:654
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:757
bool HasCoinsViews() const
Does this chainstate have a UTXO set attached?
Definition: validation.h:810
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:790
Mutex cs_avalancheFinalizedBlockIndex
Definition: validation.h:695
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:677
bool reliesOnAssumedValid()
Return true if this chainstate relies on blocks that are assumed-valid.
Definition: validation.h:769
bool m_disabled GUARDED_BY(::cs_main)
This toggle exists for use when doing background validation for UTXO snapshots.
Definition: validation.h:695
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:726
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:681
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:807
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:783
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Definition: validation.h:721
const CBlockIndex *m_avalancheFinalizedBlockIndex GUARDED_BY(cs_avalancheFinalizedBlockIndex)
The best block via avalanche voting.
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1157
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1356
std::unique_ptr< Chainstate > m_ibd_chainstate GUARDED_BY(::cs_main)
The chainstate used under normal operation (i.e.
Chainstate *m_active_chainstate GUARDED_BY(::cs_main)
Points to either the ibd or snapshot chainstate; indicates our most-work chain.
Definition: validation.h:1196
CBlockIndex *m_best_parked GUARDED_BY(::cs_main)
Definition: validation.h:1199
const CChainParams & GetParams() const
Definition: validation.h:1252
ChainstateManager(Options options)
Definition: validation.h:1245
SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main)
Most recent headers presync progress update, for rate-limiting.
Definition: validation.h:1240
const Config & GetConfig() const
Definition: validation.h:1250
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1366
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1378
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1270
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1359
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1362
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Definition: validation.h:1198
const Options m_options
Definition: validation.h:1274
CBlockIndex *m_best_header GUARDED_BY(::cs_main)
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.h:1305
std::thread m_load_block
Definition: validation.h:1275
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
Definition: validation.h:1323
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:1299
std::unique_ptr< Chainstate > m_snapshot_chainstate GUARDED_BY(::cs_main)
A chainstate initialized on the basis of a UTXO snapshot.
const Consensus::Params & GetConsensus() const
Definition: validation.h:1255
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1278
Simple class for regulating resource usage during CheckInputScripts (and CScriptCheck),...
Definition: validation.h:337
bool consume_and_check(int consumed)
Definition: validation.h:344
std::atomic< int64_t > remaining
Definition: validation.h:339
CheckInputsLimiter(int64_t limit)
Definition: validation.h:342
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:597
std::unique_ptr< CCoinsViewCache > m_cacheview GUARDED_BY(cs_main)
This is the top layer of the cache hierarchy - it keeps as many coins in memory as can fit per the db...
CCoinsViewErrorCatcher m_catcherview GUARDED_BY(cs_main)
This view wraps access to the leveldb instance and handles read errors gracefully.
CCoinsViewDB m_dbview GUARDED_BY(cs_main)
The lowest level of the CoinsViews cache hierarchy sits in a leveldb database on disk.
CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory, bool should_wipe)
This constructor initializes CCoinsViewDB and CCoinsViewErrorCatcher instances, but it does not creat...
Definition: config.h:17
Used to track blocks whose transactions were applied to the UTXO state as a part of a single Activate...
Different type to mark Mutex at global scope.
Definition: sync.h:144
static TxSigCheckLimiter getDisabled()
Definition: validation.h:365
TxSigCheckLimiter & operator=(const TxSigCheckLimiter &rhs)
Definition: validation.h:360
TxSigCheckLimiter(const TxSigCheckLimiter &rhs)
Definition: validation.h:357
bool IsValid() const
Definition: validation.h:112
256-bit unsigned big integer.
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:68
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:21
256-bit opaque blob.
Definition: uint256.h:127
static const uint64_t MAX_TX_SIGCHECKS
Allowed number of signature check operations per transaction.
Definition: consensus.h:22
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
DisconnectResult
unsigned int nHeight
LockPoints lp
static void pool cs
Filesystem operations and types.
Definition: fs.h:20
Bridge operations to C stdio.
Definition: fs.cpp:26
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:28
std::function< FILE *(const fs::path &, const char *)> FopenFn
Definition: fs.h:198
bool LoadMempool(CTxMemPool &pool, const fs::path &load_path, Chainstate &active_chainstate, FopenFn mockable_fopen_function)
Definition: init.h:28
std::unordered_map< BlockHash, CBlockIndex, BlockHasher > BlockMap
Definition: blockstorage.h:59
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:257
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:38
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
@ PERIODIC
Called by RandAddPeriodic()
ScriptError
Definition: script_error.h:11
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:87
Definition: amount.h:19
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:40
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:105
Holds various statistics on transactions within a chain.
Definition: chainparams.h:61
Parameters that influence chain consensus.
Definition: params.h:34
Validation result for a single transaction mempool acceptance.
Definition: validation.h:205
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigchecks.
Definition: validation.h:224
const ResultType m_result_type
Definition: validation.h:215
static MempoolAcceptResult Success(int64_t vsize, Amount fees)
Constructor for success case.
Definition: validation.h:232
MempoolAcceptResult(ResultType result_type, int64_t vsize, Amount fees)
Generic constructor for success cases.
Definition: validation.h:256
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:248
const TxValidationState m_state
Definition: validation.h:216
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:207
@ MEMPOOL_ENTRY
Valid, transaction was already in the mempool.
@ VALID
Fully validated, valid.
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:227
static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees)
Constructor for already-in-mempool case.
Definition: validation.h:240
const std::optional< Amount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:226
std::chrono::time_point< NodeClock > time_point
Definition: time.h:19
Validation result for package mempool acceptance.
Definition: validation.h:264
PackageMempoolAcceptResult(const TxId &txid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a MempoolAcceptResult.
Definition: validation.h:284
std::map< const TxId, const MempoolAcceptResult > m_tx_results
Map from txid to finished MempoolAcceptResults.
Definition: validation.h:273
PackageMempoolAcceptResult(PackageValidationState state, std::map< const TxId, const MempoolAcceptResult > &&results)
Definition: validation.h:275
const PackageValidationState m_state
Definition: validation.h:265
Precompute sighash midstate to avoid quadratic hashing.
Definition: transaction.h:325
Struct for holding cumulative results from executing a script or a sequence of scripts.
A TxId is the identifier of a transaction.
Definition: txid.h:14
Bilingual messages:
Definition: translation.h:17
std::string original
Definition: translation.h:18
An options struct for ChainstateManager, more ergonomically referred to as ChainstateManager::Options...
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:55
#define LOCK_RETURNED(x)
Definition: threadsafety.h:54
std::chrono::time_point< std::chrono::steady_clock, std::chrono::milliseconds > SteadyMilliseconds
Definition: time.h:31
bool ContextualCheckTransactionForCurrentBlock(const CBlockIndex *active_chain_tip, const Consensus::Params &params, const CTransaction &tx, TxValidationState &state)
AssertLockHeld(pool.cs)
void StartScriptCheckWorkerThreads(int threads_num)
Run instances of script checking worker threads.
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
Definition: validation.cpp:118
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:85
GlobalMutex g_best_block_mutex
Definition: validation.cpp:110
bool fCheckBlockIndex
Definition: validation.cpp:113
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
std::condition_variable g_best_block_cv
Definition: validation.cpp:111
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &txns, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Validate (and maybe submit) a package to the mempool.
arith_uint256 CalculateHeadersWork(const std::vector< CBlockHeader > &headers)
Return the sum of the work on a given set of headers.
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
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:111
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's input scripts succeed.
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:97
static const unsigned int MIN_BLOCKS_TO_KEEP
Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ActiveChain().Tip() will not be pr...
Definition: validation.h:95
bool HasValidProofOfWork(const std::vector< CBlockHeader > &headers, const Consensus::Params &consensusParams)
Check with the proof of work on each blockheader matches the value in nBits.
SnapshotCompletionResult
Definition: validation.h:1109
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:81
const AssumeutxoData * ExpectedAssumeutxo(const int height, const CChainParams &params)
Return the expected assumeutxo value for a given height, if one exists.
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:114
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:83
bool AbortNode(BlockValidationState &state, const std::string &strMessage, const bilingual_str &userMessage=bilingual_str{})
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept=false, unsigned int heightOverride=0) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the mempool.
void StopScriptCheckWorkerThreads()
Stop all of the script checking worker threads.
bool ContextualCheckTransactionForCurrentBlock(const CBlockIndex *active_chain_tip, const Consensus::Params &params, const CTransaction &tx, TxValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(boo TestBlockValidity)(BlockValidationState &state, const CChainParams &params, Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev, const std::function< NodeClock::time_point()> &adjusted_time_callback, BlockValidationOptions validationOptions) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
This is a variant of ContextualCheckTransaction which computes the contextual check for a transaction...
Definition: validation.h:546
VerifyDBResult
Definition: validation.h:561
void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
Mark all the coins corresponding to a given transaction inputs as spent.
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &params, BlockValidationOptions validationOptions)
Functions for validating blocks and updating the block tree.
const std::vector< std::string > CHECKLEVEL_DOC
Documentation for argument 'checklevel'.
Definition: validation.cpp:101
bool CheckSequenceLocksAtTip(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx, LockPoints *lp=nullptr, bool useExistingLockPoints=false)
Check if transaction will be BIP68 final in the next block to be created on top of tip.
Definition: validation.cpp:147
BlockHash hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:117
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
CoinsCacheSizeState
Definition: validation.h:626
@ LARGE
The cache is at >= 90% capacity.
@ CRITICAL
The coins cache is in immediate need of a flush.
static const int64_t DEFAULT_MAX_TIP_AGE
Definition: validation.h:84
void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
bool fCheckpointsEnabled
Definition: validation.cpp:114
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:96
FlushStateMode
Definition: validation.h:586
uint256 g_best_block
Used to notify getblocktemplate RPC of new tips.
Definition: validation.cpp:112
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:87
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:90
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:115