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 <node/blockstorage.h>
29 #include <policy/packages.h>
30 #include <script/script_error.h>
31 #include <script/script_metrics.h>
32 #include <shutdown.h>
33 #include <sync.h>
34 #include <txdb.h>
35 #include <txmempool.h> // For CTxMemPool::cs
36 #include <uint256.h>
37 #include <util/check.h>
38 #include <util/translation.h>
39 
40 #include <atomic>
41 #include <cstdint>
42 #include <map>
43 #include <memory>
44 #include <optional>
45 #include <set>
46 #include <string>
47 #include <thread>
48 #include <utility>
49 #include <vector>
50 
52 class CChainParams;
53 class Chainstate;
54 class ChainstateManager;
55 class CScriptCheck;
56 class CTxMemPool;
57 class CTxUndo;
59 
60 struct ChainTxData;
61 struct FlatFilePos;
63 struct LockPoints;
64 struct AssumeutxoData;
65 namespace node {
66 class SnapshotMetadata;
67 } // namespace node
68 namespace Consensus {
69 struct Params;
70 } // namespace Consensus
71 
72 namespace Consensus {
73 struct Params;
74 }
75 
76 #define MIN_TRANSACTION_SIZE \
77  (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))
78 
80 static const int MAX_SCRIPTCHECK_THREADS = 15;
82 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
83 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
84 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
85 static const bool DEFAULT_TXINDEX = false;
86 static constexpr bool DEFAULT_COINSTATSINDEX{false};
87 static const char *const DEFAULT_BLOCKFILTERINDEX = "0";
88 
89 static const bool DEFAULT_PEERBLOOMFILTERS = true;
90 
92 static const int DEFAULT_STOPATHEIGHT = 0;
97 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
98 static const signed int DEFAULT_CHECKBLOCKS = 6;
99 static const unsigned int DEFAULT_CHECKLEVEL = 3;
113 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
114 
117 
118 extern RecursiveMutex cs_main;
120 extern std::condition_variable g_best_block_cv;
122 extern uint256 g_best_block;
123 extern bool fRequireStandard;
124 extern bool fCheckBlockIndex;
125 extern bool fCheckpointsEnabled;
126 
131 extern int64_t nMaxTipAge;
132 
138 
143 
145 extern const std::vector<std::string> CHECKLEVEL_DOC;
146 
148 private:
150  bool checkPoW : 1;
151  bool checkMerkleRoot : 1;
152 
153 public:
154  // Do full validation by default
155  explicit BlockValidationOptions(const Config &config);
156  explicit BlockValidationOptions(uint64_t _excessiveBlockSize,
157  bool _checkPow = true,
158  bool _checkMerkleRoot = true)
159  : excessiveBlockSize(_excessiveBlockSize), checkPoW(_checkPow),
160  checkMerkleRoot(_checkMerkleRoot) {}
161 
162  BlockValidationOptions withCheckPoW(bool _checkPoW = true) const {
163  BlockValidationOptions ret = *this;
164  ret.checkPoW = _checkPoW;
165  return ret;
166  }
167 
169  withCheckMerkleRoot(bool _checkMerkleRoot = true) const {
170  BlockValidationOptions ret = *this;
171  ret.checkMerkleRoot = _checkMerkleRoot;
172  return ret;
173  }
174 
175  bool shouldValidatePoW() const { return checkPoW; }
176  bool shouldValidateMerkleRoot() const { return checkMerkleRoot; }
177  uint64_t getExcessiveBlockSize() const { return excessiveBlockSize; }
178 };
179 
183 void StartScriptCheckWorkerThreads(int threads_num);
184 
189 
190 Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams);
191 
192 bool AbortNode(BlockValidationState &state, const std::string &strMessage,
193  const bilingual_str &userMessage = bilingual_str{});
194 
199 double GuessVerificationProgress(const ChainTxData &data,
200  const CBlockIndex *pindex);
201 
203 void PruneBlockFilesManual(Chainstate &active_chainstate,
204  int nManualPruneHeight);
205 
211  enum class ResultType {
213  VALID,
215  INVALID,
218  };
221 
222  // The following fields are only present when m_result_type =
223  // ResultType::VALID or MEMPOOL_ENTRY
228  const std::optional<int64_t> m_vsize;
230  const std::optional<Amount> m_base_fees;
232  return MempoolAcceptResult(state);
233  }
234 
236  static MempoolAcceptResult Success(int64_t vsize, Amount fees) {
237  return MempoolAcceptResult(ResultType::VALID, vsize, fees);
238  }
239 
244  static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees) {
245  return MempoolAcceptResult(ResultType::MEMPOOL_ENTRY, vsize, fees);
246  }
247 
248  // Private constructors. Use static methods MempoolAcceptResult::Success,
249  // etc. to construct.
250 private:
253  : m_result_type(ResultType::INVALID), m_state(state),
254  m_base_fees(std::nullopt) {
255  // Can be invalid or error
256  Assume(!state.IsValid());
257  }
258 
260  explicit MempoolAcceptResult(ResultType result_type, int64_t vsize,
261  Amount fees)
262  : m_result_type(result_type), m_vsize{vsize}, m_base_fees(fees) {}
263 };
264 
277  std::map<const TxId, const MempoolAcceptResult> m_tx_results;
278 
281  std::map<const TxId, const MempoolAcceptResult> &&results)
282  : m_state{state}, m_tx_results(std::move(results)) {}
283 
288  explicit PackageMempoolAcceptResult(const TxId &txid,
289  const MempoolAcceptResult &result)
290  : m_tx_results{{txid, result}} {}
291 };
292 
317 AcceptToMemoryPool(const Config &config, Chainstate &active_chainstate,
318  const CTransactionRef &tx, int64_t accept_time,
319  bool bypass_limits, bool test_accept = false,
320  unsigned int heightOverride = 0)
322 
335 ProcessNewPackage(const Config &config, Chainstate &active_chainstate,
336  CTxMemPool &pool, const Package &txns, bool test_accept)
338 
344 protected:
345  std::atomic<int64_t> remaining;
346 
347 public:
348  explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {}
349 
350  bool consume_and_check(int consumed) {
351  auto newvalue = (remaining -= consumed);
352  return newvalue >= 0;
353  }
354 
355  bool check() { return remaining >= 0; }
356 };
357 
359 public:
361 
362  // Let's make this bad boy copiable.
364  : CheckInputsLimiter(rhs.remaining.load()) {}
365 
367  remaining = rhs.remaining.load();
368  return *this;
369  }
370 
372  TxSigCheckLimiter txLimiter;
373  // Historically, there has not been a transaction with more than 20k sig
374  // checks on testnet or mainnet, so this effectively disable sigchecks.
375  txLimiter.remaining = 20000;
376  return txLimiter;
377  }
378 };
379 
380 class ConnectTrace;
381 
411 bool CheckInputScripts(const CTransaction &tx, TxValidationState &state,
412  const CCoinsViewCache &view, const uint32_t flags,
413  bool sigCacheStore, bool scriptCacheStore,
414  const PrecomputedTransactionData &txdata,
415  int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks,
416  CheckInputsLimiter *pBlockLimitSigChecks,
417  std::vector<CScriptCheck> *pvChecks)
419 
423 static inline bool
425  const CCoinsViewCache &view, const uint32_t flags,
426  bool sigCacheStore, bool scriptCacheStore,
427  const PrecomputedTransactionData &txdata, int &nSigChecksOut)
429  TxSigCheckLimiter nSigChecksTxLimiter;
430  return CheckInputScripts(tx, state, view, flags, sigCacheStore,
431  scriptCacheStore, txdata, nSigChecksOut,
432  nSigChecksTxLimiter, nullptr, nullptr);
433 }
434 
438 void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
439  int nHeight);
440 
444 void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
445  int nHeight);
446 
465 bool CheckSequenceLocksAtTip(CBlockIndex *tip, const CCoinsView &coins_view,
466  const CTransaction &tx, LockPoints *lp = nullptr,
467  bool useExistingLockPoints = false);
468 
477 private:
480  unsigned int nIn;
481  uint32_t nFlags;
488 
489 public:
491  : ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false),
493  pBlockLimitSigChecks(nullptr) {}
494 
495  CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn,
496  unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn,
497  const PrecomputedTransactionData &txdataIn,
498  TxSigCheckLimiter *pTxLimitSigChecksIn = nullptr,
499  CheckInputsLimiter *pBlockLimitSigChecksIn = nullptr)
500  : m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn),
501  cacheStore(cacheIn), error(ScriptError::UNKNOWN), txdata(txdataIn),
502  pTxLimitSigChecks(pTxLimitSigChecksIn),
503  pBlockLimitSigChecks(pBlockLimitSigChecksIn) {}
504 
505  bool operator()();
506 
507  void swap(CScriptCheck &check) noexcept {
508  std::swap(ptxTo, check.ptxTo);
509  std::swap(m_tx_out, check.m_tx_out);
510  std::swap(nIn, check.nIn);
511  std::swap(nFlags, check.nFlags);
512  std::swap(cacheStore, check.cacheStore);
513  std::swap(error, check.error);
514  std::swap(metrics, check.metrics);
515  std::swap(txdata, check.txdata);
516  std::swap(pTxLimitSigChecks, check.pTxLimitSigChecks);
517  std::swap(pBlockLimitSigChecks, check.pBlockLimitSigChecks);
518  }
519 
520  ScriptError GetScriptError() const { return error; }
521 
523 };
524 
533 bool CheckBlock(const CBlock &block, BlockValidationState &state,
534  const Consensus::Params &params,
535  BlockValidationOptions validationOptions);
536 
544  const CBlockIndex *active_chain_tip, const Consensus::Params &params,
545  const CTransaction &tx, TxValidationState &state)
547 
553  BlockValidationState &state, const CChainParams &params,
554  Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev,
555  const std::function<NodeClock::time_point()> &adjusted_time_callback,
557 
561 bool HasValidProofOfWork(const std::vector<CBlockHeader> &headers,
562  const Consensus::Params &consensusParams);
563 
565 arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader> &headers);
566 
567 enum class VerifyDBResult {
568  SUCCESS,
570  INTERRUPTED,
573 };
574 
579 class CVerifyDB {
580 public:
581  CVerifyDB();
582 
583  ~CVerifyDB();
584 
585  [[nodiscard]] VerifyDBResult
586  VerifyDB(Chainstate &chainstate, const Config &config,
587  CCoinsView &coinsview, int nCheckLevel, int nCheckDepth)
589 };
590 
593 
603 class CoinsViews {
604 public:
608 
612 
615  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
616 
625  CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory,
626  bool should_wipe);
627 
629  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
630 };
631 
634  CRITICAL = 2,
636  LARGE = 1,
637  OK = 0
638 };
639 
654 class Chainstate {
655 protected:
661 
667  std::atomic<int32_t> nBlockSequenceId{1};
669  int32_t nBlockReverseSequenceId = -1;
671  arith_uint256 nLastPreciousChainwork = 0;
672 
679  mutable std::atomic<bool> m_cached_finished_ibd{false};
680 
684 
687  std::unique_ptr<CoinsViews> m_coins_views;
688 
701  bool m_disabled GUARDED_BY(::cs_main){false};
702 
704 
709  const CBlockIndex *m_avalancheFinalizedBlockIndex
710  GUARDED_BY(cs_avalancheFinalizedBlockIndex) = nullptr;
711 
718  CRollingBloomFilter m_filterParkingPoliciesApplied =
719  CRollingBloomFilter{1000, 0.000001};
720 
721  CBlockIndex const *m_best_fork_tip = nullptr;
722  CBlockIndex const *m_best_fork_base = nullptr;
723 
724 public:
728 
733 
734  explicit Chainstate(
735  CTxMemPool *mempool, node::BlockManager &blockman,
736  ChainstateManager &chainman,
737  std::optional<BlockHash> from_snapshot_blockhash = std::nullopt);
738 
745  void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe,
746  std::string leveldb_name = "chainstate");
747 
750  void InitCoinsCache(size_t cache_size_bytes)
752 
756  bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
758  return m_coins_views && m_coins_views->m_cacheview;
759  }
760 
764 
771  const std::optional<BlockHash> m_from_snapshot_blockhash{};
772 
776  return m_from_snapshot_blockhash.has_value();
777  }
778 
786  std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates;
787 
791  Assert(m_coins_views);
792  return *Assert(m_coins_views->m_cacheview);
793  }
794 
798  return Assert(m_coins_views)->m_dbview;
799  }
800 
802  CTxMemPool *GetMempool() { return m_mempool; }
803 
809  return Assert(m_coins_views)->m_catcherview;
810  }
811 
813  void ResetCoinsViews() { m_coins_views.reset(); }
814 
816  bool HasCoinsViews() const { return (bool)m_coins_views; }
817 
819  size_t m_coinsdb_cache_size_bytes{0};
820 
822  size_t m_coinstip_cache_size_bytes{0};
823 
826  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
828 
860  void LoadExternalBlockFile(
861  const Config &config, FILE *fileIn, FlatFilePos *dbp = nullptr,
862  std::multimap<BlockHash, FlatFilePos> *blocks_with_unknown_parent =
863  nullptr) EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
864  !cs_avalancheFinalizedBlockIndex);
865 
877  bool FlushStateToDisk(BlockValidationState &state, FlushStateMode mode,
878  int nManualPruneHeight = 0);
879 
881  void ForceFlushStateToDisk();
882 
885  void PruneAndFlush();
886 
908  bool ActivateBestChain(const Config &config, BlockValidationState &state,
909  std::shared_ptr<const CBlock> pblock = nullptr)
910  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
911  !cs_avalancheFinalizedBlockIndex)
913 
914  bool AcceptBlock(const Config &config,
915  const std::shared_ptr<const CBlock> &pblock,
916  BlockValidationState &state, bool fRequested,
917  const FlatFilePos *dbp, bool *fNewBlock,
918  bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
919 
920  // Block (dis)connection on a given view:
921  DisconnectResult DisconnectBlock(const CBlock &block,
922  const CBlockIndex *pindex,
923  CCoinsViewCache &view)
925  bool ConnectBlock(const CBlock &block, BlockValidationState &state,
926  CBlockIndex *pindex, CCoinsViewCache &view,
927  BlockValidationOptions options,
928  Amount *blockFees = nullptr, bool fJustCheck = false)
930 
931  // Apply the effects of a block disconnection on the UTXO set.
932  bool DisconnectTip(BlockValidationState &state,
933  DisconnectedBlockTransactions *disconnectpool)
935 
936  // Manual block validity manipulation:
942  bool PreciousBlock(const Config &config, BlockValidationState &state,
943  CBlockIndex *pindex)
944  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
945  !cs_avalancheFinalizedBlockIndex)
948  bool InvalidateBlock(const Config &config, BlockValidationState &state,
950  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
951  !cs_avalancheFinalizedBlockIndex);
953  bool ParkBlock(const Config &config, BlockValidationState &state,
955  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
956  !cs_avalancheFinalizedBlockIndex);
957 
961  bool AvalancheFinalizeBlock(CBlockIndex *pindex)
962  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
963 
967  void ClearAvalancheFinalizedBlock()
968  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
969 
973  bool IsBlockAvalancheFinalized(const CBlockIndex *pindex) const
974  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
975 
977  void ResetBlockFailureFlags(CBlockIndex *pindex)
979  template <typename F>
980  bool UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f)
982  template <typename F, typename C, typename AC>
983  void UpdateFlags(CBlockIndex *pindex, CBlockIndex *&pindexReset, F f,
984  C fChild, AC fAncestorWasChanged)
986 
988  void UnparkBlockAndChildren(CBlockIndex *pindex)
990 
992  void UnparkBlock(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
993 
995  bool ReplayBlocks();
996 
1001  bool LoadGenesisBlock();
1002 
1003  void PruneBlockIndexCandidates();
1004 
1005  void UnloadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1006 
1011  bool IsInitialBlockDownload() const;
1012 
1014  const CBlockIndex *FindForkInGlobalIndex(const CBlockLocator &locator) const
1016 
1023  void CheckBlockIndex();
1024 
1026  void
1027  LoadMempool(const Config &config, const fs::path &load_path,
1028  fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
1029 
1032  bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1033 
1037  CoinsCacheSizeState GetCoinsCacheSizeState()
1039 
1041  GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes,
1042  size_t max_mempool_size_bytes)
1044 
1046 
1049  RecursiveMutex *MempoolMutex() const LOCK_RETURNED(m_mempool->cs) {
1050  return m_mempool ? &m_mempool->cs : nullptr;
1051  }
1052 
1053 private:
1054  bool ActivateBestChainStep(const Config &config,
1055  BlockValidationState &state,
1056  CBlockIndex *pindexMostWork,
1057  const std::shared_ptr<const CBlock> &pblock,
1058  bool &fInvalidFound, ConnectTrace &connectTrace)
1059  EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs,
1060  !cs_avalancheFinalizedBlockIndex);
1061  bool ConnectTip(const Config &config, BlockValidationState &state,
1062  BlockPolicyValidationState &blockPolicyState,
1063  CBlockIndex *pindexNew,
1064  const std::shared_ptr<const CBlock> &pblock,
1065  ConnectTrace &connectTrace,
1066  DisconnectedBlockTransactions &disconnectpool)
1067  EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs,
1068  !cs_avalancheFinalizedBlockIndex);
1069  void InvalidBlockFound(CBlockIndex *pindex,
1070  const BlockValidationState &state)
1071  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1072  CBlockIndex *
1073  FindMostWorkChain(std::vector<const CBlockIndex *> &blocksToReconcile)
1074  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1075  void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew,
1076  const FlatFilePos &pos)
1078 
1079  bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs)
1081 
1082  void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren)
1084 
1085  bool UnwindBlock(const Config &config, BlockValidationState &state,
1086  CBlockIndex *pindex, bool invalidate)
1087  EXCLUSIVE_LOCKS_REQUIRED(m_chainstate_mutex,
1088  !cs_avalancheFinalizedBlockIndex);
1089 
1090  void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1091  void CheckForkWarningConditionsOnNewFork(CBlockIndex *pindexNewForkTip)
1093  void InvalidChainFound(CBlockIndex *pindexNew)
1094  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1095 
1096  const CBlockIndex *FindBlockToFinalize(CBlockIndex *pindexNew)
1098 
1102  void UpdateTip(const CBlockIndex *pindexNew)
1104 
1105  std::chrono::microseconds m_last_write{0};
1106  std::chrono::microseconds m_last_flush{0};
1107 
1112  void InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1113 
1115 };
1116 
1118  SUCCESS,
1119  SKIPPED,
1120 
1121  // Expected assumeutxo configuration data is not found for the height of the
1122  // base block.
1124 
1125  // Failed to generate UTXO statistics (to check UTXO set hash) for the
1126  // background chainstate.
1127  STATS_FAILED,
1128 
1129  // The UTXO set hash of the background validation chainstate does not match
1130  // the one expected by assumeutxo chainparams.
1131  HASH_MISMATCH,
1132 
1133  // The blockhash of the current tip of the background validation chainstate
1134  // does not match the one expected by the snapshot chainstate.
1136 };
1137 
1166 private:
1182  std::unique_ptr<Chainstate> m_ibd_chainstate GUARDED_BY(::cs_main);
1183 
1193  std::unique_ptr<Chainstate> m_snapshot_chainstate GUARDED_BY(::cs_main);
1194 
1204  Chainstate *m_active_chainstate GUARDED_BY(::cs_main){nullptr};
1205 
1206  CBlockIndex *m_best_invalid GUARDED_BY(::cs_main){nullptr};
1207  CBlockIndex *m_best_parked GUARDED_BY(::cs_main){nullptr};
1208 
1210  [[nodiscard]] bool
1211  PopulateAndValidateSnapshot(Chainstate &snapshot_chainstate,
1212  AutoFile &coins_file,
1213  const node::SnapshotMetadata &metadata);
1222  bool AcceptBlockHeader(const Config &config, const CBlockHeader &block,
1223  BlockValidationState &state, CBlockIndex **ppindex,
1224  bool min_pow_checked)
1226  friend Chainstate;
1227 
1229  const CBlockIndex *GetSnapshotBaseBlock() const
1231 
1234  std::optional<int> GetSnapshotBaseHeight() const
1236 
1242  bool IsUsable(const Chainstate *const pchainstate) const
1244  return pchainstate && !pchainstate->m_disabled;
1245  }
1246 
1248  SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main){};
1249 
1250 public:
1252 
1253  explicit ChainstateManager(Options options)
1254  : m_options{std::move(options)} {
1255  Assert(m_options.adjusted_time_callback);
1256  }
1257 
1258  const CChainParams &GetParams() const {
1259  return m_options.config.GetChainParams();
1260  }
1262  return m_options.config.GetChainParams().GetConsensus();
1263  }
1264 
1278  }
1279 
1281  std::thread m_load_block;
1285 
1305  std::set<CBlockIndex *> m_failed_blocks;
1306 
1311  CBlockIndex *m_best_header GUARDED_BY(::cs_main){nullptr};
1312 
1315  int64_t m_total_coinstip_cache{0};
1316  //
1319  int64_t m_total_coinsdb_cache{0};
1320 
1324  // constructor
1325  Chainstate &InitializeChainstate(CTxMemPool *mempool)
1327 
1329  std::vector<Chainstate *> GetAll();
1330 
1344  [[nodiscard]] bool ActivateSnapshot(AutoFile &coins_file,
1345  const node::SnapshotMetadata &metadata,
1346  bool in_memory);
1347 
1355  SnapshotCompletionResult MaybeCompleteSnapshotValidation(
1356  std::function<void(bilingual_str)> shutdown_fnc =
1357  [](bilingual_str msg) { AbortNode(msg.original, msg); })
1359 
1361  Chainstate &ActiveChainstate() const;
1363  return ActiveChainstate().m_chain;
1364  }
1365  int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
1366  return ActiveChain().Height();
1367  }
1369  return ActiveChain().Tip();
1370  }
1371 
1374  return m_blockman.m_block_index;
1375  }
1376 
1379  bool IsSnapshotActive() const;
1380 
1381  std::optional<BlockHash> SnapshotBlockhash() const;
1382 
1385  return m_snapshot_chainstate && m_ibd_chainstate &&
1386  m_ibd_chainstate->m_disabled;
1387  }
1388 
1417  bool ProcessNewBlock(const Config &config,
1418  const std::shared_ptr<const CBlock> &block,
1419  bool force_processing, bool min_pow_checked,
1420  bool *new_block) LOCKS_EXCLUDED(cs_main);
1421 
1438  bool ProcessNewBlockHeaders(const Config &config,
1439  const std::vector<CBlockHeader> &block,
1440  bool min_pow_checked,
1441  BlockValidationState &state,
1442  const CBlockIndex **ppindex = nullptr)
1444 
1453  [[nodiscard]] MempoolAcceptResult
1454  ProcessTransaction(const CTransactionRef &tx, bool test_accept = false)
1456 
1459  bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1460 
1463  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1464 
1471  void ReportHeadersPresync(const arith_uint256 &work, int64_t height,
1472  int64_t timestamp);
1473 
1476  bool DetectSnapshotChainstate(CTxMemPool *mempool)
1478 
1479  void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1480 
1483  Chainstate &ActivateExistingSnapshot(CTxMemPool *mempool,
1484  BlockHash base_blockhash)
1486 
1496  bool ValidatedSnapshotCleanup() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1497 };
1498 
1506 const AssumeutxoData *ExpectedAssumeutxo(const int height,
1507  const CChainParams &params);
1508 
1509 #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:177
BlockValidationOptions withCheckPoW(bool _checkPoW=true) const
Definition: validation.h:162
BlockValidationOptions(uint64_t _excessiveBlockSize, bool _checkPow=true, bool _checkMerkleRoot=true)
Definition: validation.h:156
BlockValidationOptions withCheckMerkleRoot(bool _checkMerkleRoot=true) const
Definition: validation.h:169
BlockValidationOptions(const Config &config)
Definition: validation.cpp:132
bool shouldValidatePoW() const
Definition: validation.h:175
uint64_t excessiveBlockSize
Definition: validation.h:149
bool shouldValidateMerkleRoot() const
Definition: validation.h:176
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:27
An in-memory indexed chain of blocks.
Definition: chain.h:141
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:59
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:476
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:495
ScriptError GetScriptError() const
Definition: validation.h:520
ScriptExecutionMetrics GetScriptExecutionMetrics() const
Definition: validation.h:522
uint32_t nFlags
Definition: validation.h:481
TxSigCheckLimiter * pTxLimitSigChecks
Definition: validation.h:486
ScriptExecutionMetrics metrics
Definition: validation.h:484
CTxOut m_tx_out
Definition: validation.h:478
void swap(CScriptCheck &check) noexcept
Definition: validation.h:507
bool cacheStore
Definition: validation.h:482
ScriptError error
Definition: validation.h:483
PrecomputedTransactionData txdata
Definition: validation.h:485
const CTransaction * ptxTo
Definition: validation.h:479
unsigned int nIn
Definition: validation.h:480
CheckInputsLimiter * pBlockLimitSigChecks
Definition: validation.h:487
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:354
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:441
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:579
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:654
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries with either BLOCK_VALID_TRANSACTIONS (for itself and all ancestors...
Definition: validation.h:786
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:806
CTxMemPool * GetMempool()
Definition: validation.h:802
Mutex m_chainstate_mutex
The ChainState Mutex.
Definition: validation.h:660
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:763
bool HasCoinsViews() const
Does this chainstate have a UTXO set attached?
Definition: validation.h:816
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:796
Mutex cs_avalancheFinalizedBlockIndex
Definition: validation.h:701
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:683
bool reliesOnAssumedValid()
Return true if this chainstate relies on blocks that are assumed-valid.
Definition: validation.h:775
bool m_disabled GUARDED_BY(::cs_main)
This toggle exists for use when doing background validation for UTXO snapshots.
Definition: validation.h:701
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:732
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:687
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:813
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:789
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Definition: validation.h:727
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:1165
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1362
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:1204
CBlockIndex *m_best_parked GUARDED_BY(::cs_main)
Definition: validation.h:1207
const CChainParams & GetParams() const
Definition: validation.h:1258
ChainstateManager(Options options)
Definition: validation.h:1253
SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main)
Most recent headers presync progress update, for rate-limiting.
Definition: validation.h:1248
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1372
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1384
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1276
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1365
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1368
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Definition: validation.h:1206
const Options m_options
Definition: validation.h:1280
CBlockIndex *m_best_header GUARDED_BY(::cs_main)
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.h:1311
std::thread m_load_block
Definition: validation.h:1281
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
Definition: validation.h:1329
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:1305
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:1261
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1284
Simple class for regulating resource usage during CheckInputScripts (and CScriptCheck),...
Definition: validation.h:343
bool consume_and_check(int consumed)
Definition: validation.h:350
std::atomic< int64_t > remaining
Definition: validation.h:345
CheckInputsLimiter(int64_t limit)
Definition: validation.h:348
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:603
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:371
TxSigCheckLimiter & operator=(const TxSigCheckLimiter &rhs)
Definition: validation.h:366
TxSigCheckLimiter(const TxSigCheckLimiter &rhs)
Definition: validation.h:363
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:69
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:23
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
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(const Config &config, 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:60
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:209
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigchecks.
Definition: validation.h:228
const ResultType m_result_type
Definition: validation.h:219
static MempoolAcceptResult Success(int64_t vsize, Amount fees)
Constructor for success case.
Definition: validation.h:236
MempoolAcceptResult(ResultType result_type, int64_t vsize, Amount fees)
Generic constructor for success cases.
Definition: validation.h:260
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:252
const TxValidationState m_state
Definition: validation.h:220
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:211
@ MEMPOOL_ENTRY
Valid, transaction was already in the mempool.
@ VALID
Fully validated, valid.
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:231
static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees)
Constructor for already-in-mempool case.
Definition: validation.h:244
const std::optional< Amount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:230
std::chrono::time_point< NodeClock > time_point
Definition: time.h:19
Validation result for package mempool acceptance.
Definition: validation.h:268
PackageMempoolAcceptResult(const TxId &txid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a MempoolAcceptResult.
Definition: validation.h:288
std::map< const TxId, const MempoolAcceptResult > m_tx_results
Map from txid to finished MempoolAcceptResults.
Definition: validation.h:277
PackageMempoolAcceptResult(PackageValidationState state, std::map< const TxId, const MempoolAcceptResult > &&results)
Definition: validation.h:279
const PackageValidationState m_state
Definition: validation.h:269
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:130
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:84
GlobalMutex g_best_block_mutex
Definition: validation.cpp:121
bool fCheckBlockIndex
Definition: validation.cpp:125
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
std::condition_variable g_best_block_cv
Definition: validation.cpp:122
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:113
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:99
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:97
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:1117
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:80
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:116
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:82
bool AbortNode(BlockValidationState &state, const std::string &strMessage, const bilingual_str &userMessage=bilingual_str{})
static const char *const DEFAULT_BLOCKFILTERINDEX
Definition: validation.h:87
void StopScriptCheckWorkerThreads()
Stop all of the script checking worker threads.
MempoolAcceptResult AcceptToMemoryPool(const Config &config, 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.
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:552
VerifyDBResult
Definition: validation.h:567
static constexpr bool DEFAULT_COINSTATSINDEX
Definition: validation.h:86
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:98
PackageMempoolAcceptResult ProcessNewPackage(const Config &config, 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.
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:159
BlockHash hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:129
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
CoinsCacheSizeState
Definition: validation.h:632
@ LARGE
The cache is at >= 90% capacity.
@ CRITICAL
The coins cache is in immediate need of a flush.
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:119
static const int64_t DEFAULT_MAX_TIP_AGE
Definition: validation.h:83
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:126
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:98
FlushStateMode
Definition: validation.h:592
uint256 g_best_block
Used to notify getblocktemplate RPC of new tips.
Definition: validation.cpp:123
bool fRequireStandard
Definition: validation.cpp:124
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:89
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:92
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:127
static const bool DEFAULT_TXINDEX
Definition: validation.h:85