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 <chain.h>
19 #include <common/bloom.h>
20 #include <config.h>
21 #include <consensus/amount.h>
22 #include <consensus/consensus.h>
23 #include <deploymentstatus.h>
24 #include <disconnectresult.h>
25 #include <flatfile.h>
26 #include <kernel/chainparams.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/fs.h>
40 #include <util/result.h>
41 #include <util/translation.h>
42 
43 #include <atomic>
44 #include <cstdint>
45 #include <map>
46 #include <memory>
47 #include <optional>
48 #include <set>
49 #include <string>
50 #include <thread>
51 #include <utility>
52 #include <vector>
53 
55 class CChainParams;
56 class Chainstate;
57 class ChainstateManager;
58 class CScriptCheck;
59 class CTxMemPool;
60 class CTxUndo;
62 
63 struct ChainTxData;
64 struct FlatFilePos;
66 struct LockPoints;
67 struct AssumeutxoData;
68 namespace node {
69 class SnapshotMetadata;
70 } // namespace node
71 namespace Consensus {
72 struct Params;
73 } // namespace Consensus
74 namespace avalanche {
75 class Processor;
76 } // namespace avalanche
77 
78 #define MIN_TRANSACTION_SIZE \
79  (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))
80 
82 static const int MAX_SCRIPTCHECK_THREADS = 15;
84 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
85 
86 static const bool DEFAULT_PEERBLOOMFILTERS = true;
87 
89 static const int DEFAULT_STOPATHEIGHT = 0;
94 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
95 static const signed int DEFAULT_CHECKBLOCKS = 6;
96 static constexpr int DEFAULT_CHECKLEVEL{3};
110 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
111 
114 
116 extern std::condition_variable g_best_block_cv;
118 extern const CBlockIndex *g_best_block;
119 
121 extern const std::vector<std::string> CHECKLEVEL_DOC;
122 
124 private:
126  bool checkPoW : 1;
127  bool checkMerkleRoot : 1;
128 
129 public:
130  // Do full validation by default
131  explicit BlockValidationOptions(const Config &config);
132  explicit BlockValidationOptions(uint64_t _excessiveBlockSize,
133  bool _checkPow = true,
134  bool _checkMerkleRoot = true)
135  : excessiveBlockSize(_excessiveBlockSize), checkPoW(_checkPow),
136  checkMerkleRoot(_checkMerkleRoot) {}
137 
138  BlockValidationOptions withCheckPoW(bool _checkPoW = true) const {
139  BlockValidationOptions ret = *this;
140  ret.checkPoW = _checkPoW;
141  return ret;
142  }
143 
145  withCheckMerkleRoot(bool _checkMerkleRoot = true) const {
146  BlockValidationOptions ret = *this;
147  ret.checkMerkleRoot = _checkMerkleRoot;
148  return ret;
149  }
150 
151  bool shouldValidatePoW() const { return checkPoW; }
152  bool shouldValidateMerkleRoot() const { return checkMerkleRoot; }
153  uint64_t getExcessiveBlockSize() const { return excessiveBlockSize; }
154 };
155 
159 void StartScriptCheckWorkerThreads(int threads_num);
160 
165 
166 Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams);
167 
168 bool AbortNode(BlockValidationState &state, const std::string &strMessage,
169  const bilingual_str &userMessage = bilingual_str{});
170 
175 double GuessVerificationProgress(const ChainTxData &data,
176  const CBlockIndex *pindex);
177 
179 void PruneBlockFilesManual(Chainstate &active_chainstate,
180  int nManualPruneHeight);
181 
182 // clang-format off
205 // clang-format on
208  enum class ResultType {
210  VALID,
212  INVALID,
215  };
218 
221 
226  const std::optional<int64_t> m_vsize;
228  const std::optional<Amount> m_base_fees;
236  const std::optional<CFeeRate> m_effective_feerate;
243  const std::optional<std::vector<TxId>> m_txids_fee_calculations;
244 
246  return MempoolAcceptResult(state);
247  }
248 
249  static MempoolAcceptResult
250  FeeFailure(TxValidationState state, CFeeRate effective_feerate,
251  const std::vector<TxId> &txids_fee_calculations) {
252  return MempoolAcceptResult(state, effective_feerate,
253  txids_fee_calculations);
254  }
255 
257  static MempoolAcceptResult
258  Success(int64_t vsize, Amount fees, CFeeRate effective_feerate,
259  const std::vector<TxId> &txids_fee_calculations) {
260  return MempoolAcceptResult(ResultType::VALID, vsize, fees,
261  effective_feerate, txids_fee_calculations);
262  }
263 
268  static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees) {
269  return MempoolAcceptResult(vsize, fees);
270  }
271 
272  // Private constructors. Use static methods MempoolAcceptResult::Success,
273  // etc. to construct.
274 private:
277  : m_result_type(ResultType::INVALID), m_state(state),
278  m_base_fees(std::nullopt) {
279  // Can be invalid or error
280  Assume(!state.IsValid());
281  }
282 
285  ResultType result_type, int64_t vsize, Amount fees,
286  CFeeRate effective_feerate,
287  const std::vector<TxId> &txids_fee_calculations)
288  : m_result_type(result_type), m_vsize{vsize}, m_base_fees(fees),
289  m_effective_feerate(effective_feerate),
290  m_txids_fee_calculations(txids_fee_calculations) {}
291 
294  TxValidationState state, CFeeRate effective_feerate,
295  const std::vector<TxId> &txids_fee_calculations)
296  : m_result_type(ResultType::INVALID), m_state(state),
297  m_effective_feerate(effective_feerate),
298  m_txids_fee_calculations(txids_fee_calculations) {}
299 
301  explicit MempoolAcceptResult(int64_t vsize, Amount fees)
302  : m_result_type(ResultType::MEMPOOL_ENTRY), m_vsize{vsize},
303  m_base_fees(fees) {}
304 };
305 
318  std::map<TxId, MempoolAcceptResult> m_tx_results;
319 
322  std::map<TxId, MempoolAcceptResult> &&results)
323  : m_state{state}, m_tx_results(std::move(results)) {}
324 
329  explicit PackageMempoolAcceptResult(const TxId &txid,
330  const MempoolAcceptResult &result)
331  : m_tx_results{{txid, result}} {}
332 };
333 
357 AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx,
358  int64_t accept_time, bool bypass_limits,
359  bool test_accept = false, unsigned int heightOverride = 0)
361 
374 ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool,
375  const Package &txns, bool test_accept)
377 
383 protected:
384  std::atomic<int64_t> remaining;
385 
386 public:
387  explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {}
388 
389  bool consume_and_check(int consumed) {
390  auto newvalue = (remaining -= consumed);
391  return newvalue >= 0;
392  }
393 
394  bool check() { return remaining >= 0; }
395 };
396 
398 public:
400 
401  // Let's make this bad boy copiable.
403  : CheckInputsLimiter(rhs.remaining.load()) {}
404 
406  remaining = rhs.remaining.load();
407  return *this;
408  }
409 
411  TxSigCheckLimiter txLimiter;
412  // Historically, there has not been a transaction with more than 20k sig
413  // checks on testnet or mainnet, so this effectively disable sigchecks.
414  txLimiter.remaining = 20000;
415  return txLimiter;
416  }
417 };
418 
419 class ConnectTrace;
420 
450 bool CheckInputScripts(const CTransaction &tx, TxValidationState &state,
451  const CCoinsViewCache &view, const uint32_t flags,
452  bool sigCacheStore, bool scriptCacheStore,
453  const PrecomputedTransactionData &txdata,
454  int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks,
455  CheckInputsLimiter *pBlockLimitSigChecks,
456  std::vector<CScriptCheck> *pvChecks)
458 
462 static inline bool
464  const CCoinsViewCache &view, const uint32_t flags,
465  bool sigCacheStore, bool scriptCacheStore,
466  const PrecomputedTransactionData &txdata, int &nSigChecksOut)
468  TxSigCheckLimiter nSigChecksTxLimiter;
469  return CheckInputScripts(tx, state, view, flags, sigCacheStore,
470  scriptCacheStore, txdata, nSigChecksOut,
471  nSigChecksTxLimiter, nullptr, nullptr);
472 }
473 
477 void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
478  int nHeight);
479 
483 void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
484  int nHeight);
485 
504 std::optional<LockPoints> CalculateLockPointsAtTip(CBlockIndex *tip,
505  const CCoinsView &coins_view,
506  const CTransaction &tx);
507 
517 bool CheckSequenceLocksAtTip(CBlockIndex *tip, const LockPoints &lock_points);
518 
527 private:
530  unsigned int nIn;
531  uint32_t nFlags;
538 
539 public:
540  CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn,
541  unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn,
542  const PrecomputedTransactionData &txdataIn,
543  TxSigCheckLimiter *pTxLimitSigChecksIn = nullptr,
544  CheckInputsLimiter *pBlockLimitSigChecksIn = nullptr)
545  : m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn),
546  cacheStore(cacheIn), txdata(txdataIn),
547  pTxLimitSigChecks(pTxLimitSigChecksIn),
548  pBlockLimitSigChecks(pBlockLimitSigChecksIn) {}
549 
550  CScriptCheck(const CScriptCheck &) = delete;
551  CScriptCheck &operator=(const CScriptCheck &) = delete;
552  CScriptCheck(CScriptCheck &&) = default;
554 
555  bool operator()();
556 
557  ScriptError GetScriptError() const { return error; }
558 
560 };
561 
570 bool CheckBlock(const CBlock &block, BlockValidationState &state,
571  const Consensus::Params &params,
572  BlockValidationOptions validationOptions);
573 
581  const CBlockIndex &active_chain_tip, const Consensus::Params &params,
582  const CTransaction &tx, TxValidationState &state)
584 
590  BlockValidationState &state, const CChainParams &params,
591  Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev,
592  const std::function<NodeClock::time_point()> &adjusted_time_callback,
594 
598 bool HasValidProofOfWork(const std::vector<CBlockHeader> &headers,
599  const Consensus::Params &consensusParams);
600 
602 arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader> &headers);
603 
604 enum class VerifyDBResult {
605  SUCCESS,
607  INTERRUPTED,
610 };
611 
616 class CVerifyDB {
617 private:
619 
620 public:
622 
623 public:
624  explicit CVerifyDB(kernel::Notifications &notifications);
625  ~CVerifyDB();
626 
627  [[nodiscard]] VerifyDBResult VerifyDB(Chainstate &chainstate,
628  CCoinsView &coinsview,
629  int nCheckLevel, int nCheckDepth)
631 };
632 
635 
645 class CoinsViews {
646 public:
650 
654 
657  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
658 
667  CoinsViews(DBParams db_params, CoinsViewOptions options);
668 
670  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
671 };
672 
675  CRITICAL = 2,
677  LARGE = 1,
678  OK = 0
679 };
680 
695 class Chainstate {
696 protected:
702 
708  std::atomic<int32_t> nBlockSequenceId{1};
710  int32_t nBlockReverseSequenceId = -1;
712  arith_uint256 nLastPreciousChainwork = 0;
713 
720  mutable std::atomic<bool> m_cached_finished_ibd{false};
721 
725 
728  std::unique_ptr<CoinsViews> m_coins_views;
729 
742  bool m_disabled GUARDED_BY(::cs_main){false};
743 
745 
750  const CBlockIndex *m_avalancheFinalizedBlockIndex
751  GUARDED_BY(cs_avalancheFinalizedBlockIndex) = nullptr;
752 
759  CRollingBloomFilter m_filterParkingPoliciesApplied =
760  CRollingBloomFilter{1000, 0.000001};
761 
762  CBlockIndex const *m_best_fork_tip = nullptr;
763  CBlockIndex const *m_best_fork_base = nullptr;
764 
765 public:
769 
774 
775  explicit Chainstate(
776  CTxMemPool *mempool, node::BlockManager &blockman,
777  ChainstateManager &chainman,
778  std::optional<BlockHash> from_snapshot_blockhash = std::nullopt);
779 
786  void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe,
787  std::string leveldb_name = "chainstate");
788 
791  void InitCoinsCache(size_t cache_size_bytes)
793 
797  bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
799  return m_coins_views && m_coins_views->m_cacheview;
800  }
801 
805 
812  const std::optional<BlockHash> m_from_snapshot_blockhash{};
813 
817  return m_from_snapshot_blockhash.has_value();
818  }
819 
827  std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates;
828 
832  Assert(m_coins_views);
833  return *Assert(m_coins_views->m_cacheview);
834  }
835 
839  return Assert(m_coins_views)->m_dbview;
840  }
841 
843  CTxMemPool *GetMempool() { return m_mempool; }
844 
850  return Assert(m_coins_views)->m_catcherview;
851  }
852 
854  void ResetCoinsViews() { m_coins_views.reset(); }
855 
857  bool HasCoinsViews() const { return (bool)m_coins_views; }
858 
860  size_t m_coinsdb_cache_size_bytes{0};
861 
863  size_t m_coinstip_cache_size_bytes{0};
864 
867  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
869 
901  void LoadExternalBlockFile(FILE *fileIn, FlatFilePos *dbp = nullptr,
902  std::multimap<BlockHash, FlatFilePos>
903  *blocks_with_unknown_parent = nullptr,
904  avalanche::Processor *const avalanche = nullptr)
905  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
906  !cs_avalancheFinalizedBlockIndex);
907 
919  bool FlushStateToDisk(BlockValidationState &state, FlushStateMode mode,
920  int nManualPruneHeight = 0);
921 
923  void ForceFlushStateToDisk();
924 
927  void PruneAndFlush();
928 
955  bool ActivateBestChain(BlockValidationState &state,
956  std::shared_ptr<const CBlock> pblock = nullptr,
957  avalanche::Processor *const avalanche = nullptr,
958  bool skip_checkblockindex = false)
959  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
960  !cs_avalancheFinalizedBlockIndex)
962 
963  bool AcceptBlock(const std::shared_ptr<const CBlock> &pblock,
964  BlockValidationState &state, bool fRequested,
965  const FlatFilePos *dbp, bool *fNewBlock,
966  bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
967 
968  // Block (dis)connection on a given view:
969  DisconnectResult DisconnectBlock(const CBlock &block,
970  const CBlockIndex *pindex,
971  CCoinsViewCache &view)
973  bool ConnectBlock(const CBlock &block, BlockValidationState &state,
974  CBlockIndex *pindex, CCoinsViewCache &view,
975  BlockValidationOptions options,
976  Amount *blockFees = nullptr, bool fJustCheck = false)
978 
979  // Apply the effects of a block disconnection on the UTXO set.
980  bool DisconnectTip(BlockValidationState &state,
981  DisconnectedBlockTransactions *disconnectpool)
983 
984  // Manual block validity manipulation:
990  bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex,
991  avalanche::Processor *const avalanche = nullptr)
992  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
993  !cs_avalancheFinalizedBlockIndex)
996  bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex)
998  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
999  !cs_avalancheFinalizedBlockIndex);
1001  bool ParkBlock(BlockValidationState &state, CBlockIndex *pindex)
1003  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
1004  !cs_avalancheFinalizedBlockIndex);
1005 
1009  bool AvalancheFinalizeBlock(CBlockIndex *pindex,
1010  avalanche::Processor &avalanche)
1011  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
1012 
1016  void ClearAvalancheFinalizedBlock()
1017  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
1018 
1022  bool IsBlockAvalancheFinalized(const CBlockIndex *pindex) const
1023  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
1024 
1026  void ResetBlockFailureFlags(CBlockIndex *pindex)
1028  template <typename F>
1029  bool UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f)
1031  template <typename F, typename C, typename AC>
1032  void UpdateFlags(CBlockIndex *pindex, CBlockIndex *&pindexReset, F f,
1033  C fChild, AC fAncestorWasChanged)
1035 
1037  void UnparkBlockAndChildren(CBlockIndex *pindex)
1039 
1041  void UnparkBlock(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1042 
1044  bool ReplayBlocks();
1045 
1050  bool LoadGenesisBlock();
1051 
1052  void PruneBlockIndexCandidates();
1053 
1054  void UnloadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1055 
1060  bool IsInitialBlockDownload() const;
1061 
1063  const CBlockIndex *FindForkInGlobalIndex(const CBlockLocator &locator) const
1065 
1072  void CheckBlockIndex();
1073 
1075  void
1076  LoadMempool(const fs::path &load_path,
1077  fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
1078 
1081  bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1082 
1086  CoinsCacheSizeState GetCoinsCacheSizeState()
1088 
1090  GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes,
1091  size_t max_mempool_size_bytes)
1093 
1095 
1098  RecursiveMutex *MempoolMutex() const LOCK_RETURNED(m_mempool->cs) {
1099  return m_mempool ? &m_mempool->cs : nullptr;
1100  }
1101 
1102 private:
1103  bool
1104  ActivateBestChainStep(BlockValidationState &state,
1105  CBlockIndex *pindexMostWork,
1106  const std::shared_ptr<const CBlock> &pblock,
1107  bool &fInvalidFound, ConnectTrace &connectTrace,
1108  const avalanche::Processor *const avalanche = nullptr)
1109  EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs,
1110  !cs_avalancheFinalizedBlockIndex);
1111  bool ConnectTip(BlockValidationState &state,
1112  BlockPolicyValidationState &blockPolicyState,
1113  CBlockIndex *pindexNew,
1114  const std::shared_ptr<const CBlock> &pblock,
1115  ConnectTrace &connectTrace,
1116  DisconnectedBlockTransactions &disconnectpool,
1117  const avalanche::Processor *const avalanche = nullptr)
1118  EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs,
1119  !cs_avalancheFinalizedBlockIndex);
1120  void InvalidBlockFound(CBlockIndex *pindex,
1121  const BlockValidationState &state)
1122  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1123  CBlockIndex *
1124  FindMostWorkChain(std::vector<const CBlockIndex *> &blocksToReconcile,
1125  bool fAutoUnpark)
1126  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1127  void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew,
1128  const FlatFilePos &pos)
1130 
1131  bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs)
1133 
1134  void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren)
1136 
1137  bool UnwindBlock(BlockValidationState &state, CBlockIndex *pindex,
1138  bool invalidate)
1139  EXCLUSIVE_LOCKS_REQUIRED(m_chainstate_mutex,
1140  !cs_avalancheFinalizedBlockIndex);
1141 
1142  void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1143  void CheckForkWarningConditionsOnNewFork(CBlockIndex *pindexNewForkTip)
1145  void InvalidChainFound(CBlockIndex *pindexNew)
1146  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1147 
1148  const CBlockIndex *FindBlockToFinalize(CBlockIndex *pindexNew)
1150 
1154  void UpdateTip(const CBlockIndex *pindexNew)
1156 
1157  std::chrono::microseconds m_last_write{0};
1158  std::chrono::microseconds m_last_flush{0};
1159 
1164  [[nodiscard]] util::Result<void> InvalidateCoinsDBOnDisk()
1166 
1168 };
1169 
1171  SUCCESS,
1172  SKIPPED,
1173 
1174  // Expected assumeutxo configuration data is not found for the height of the
1175  // base block.
1177 
1178  // Failed to generate UTXO statistics (to check UTXO set hash) for the
1179  // background chainstate.
1180  STATS_FAILED,
1181 
1182  // The UTXO set hash of the background validation chainstate does not match
1183  // the one expected by assumeutxo chainparams.
1184  HASH_MISMATCH,
1185 
1186  // The blockhash of the current tip of the background validation chainstate
1187  // does not match the one expected by the snapshot chainstate.
1189 };
1190 
1219 private:
1235  std::unique_ptr<Chainstate> m_ibd_chainstate GUARDED_BY(::cs_main);
1236 
1246  std::unique_ptr<Chainstate> m_snapshot_chainstate GUARDED_BY(::cs_main);
1247 
1257  Chainstate *m_active_chainstate GUARDED_BY(::cs_main){nullptr};
1258 
1259  CBlockIndex *m_best_invalid GUARDED_BY(::cs_main){nullptr};
1260  CBlockIndex *m_best_parked GUARDED_BY(::cs_main){nullptr};
1261 
1263  [[nodiscard]] bool
1264  PopulateAndValidateSnapshot(Chainstate &snapshot_chainstate,
1265  AutoFile &coins_file,
1266  const node::SnapshotMetadata &metadata);
1275  bool AcceptBlockHeader(
1276  const CBlockHeader &block, BlockValidationState &state,
1277  CBlockIndex **ppindex, bool min_pow_checked,
1278  const std::optional<CCheckpointData> &test_checkpoints = std::nullopt)
1280  friend Chainstate;
1281 
1283  const CBlockIndex *GetSnapshotBaseBlock() const
1285 
1288  std::optional<int> GetSnapshotBaseHeight() const
1290 
1296  bool IsUsable(const Chainstate *const pchainstate) const
1298  return pchainstate && !pchainstate->m_disabled;
1299  }
1300 
1302  SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main){};
1303 
1304 public:
1306 
1307  explicit ChainstateManager(Options options,
1308  node::BlockManager::Options blockman_options);
1309 
1310  const Config &GetConfig() const { return m_options.config; }
1311 
1312  const CChainParams &GetParams() const {
1313  return m_options.config.GetChainParams();
1314  }
1316  return m_options.config.GetChainParams().GetConsensus();
1317  }
1318  bool ShouldCheckBlockIndex() const {
1319  return *Assert(m_options.check_block_index);
1320  }
1322  return *Assert(m_options.minimum_chain_work);
1323  }
1324  const BlockHash &AssumedValidBlock() const {
1325  return *Assert(m_options.assumed_valid_block);
1326  }
1328  return m_options.notifications;
1329  };
1330 
1344  }
1345 
1347  std::thread m_load_block;
1351 
1371  std::set<CBlockIndex *> m_failed_blocks;
1372 
1377  CBlockIndex *m_best_header GUARDED_BY(::cs_main){nullptr};
1378 
1381  int64_t m_total_coinstip_cache{0};
1382  //
1385  int64_t m_total_coinsdb_cache{0};
1386 
1390  // constructor
1391  Chainstate &InitializeChainstate(CTxMemPool *mempool)
1393 
1395  std::vector<Chainstate *> GetAll();
1396 
1410  [[nodiscard]] bool ActivateSnapshot(AutoFile &coins_file,
1411  const node::SnapshotMetadata &metadata,
1412  bool in_memory);
1413 
1421  SnapshotCompletionResult MaybeCompleteSnapshotValidation(
1422  std::function<void(bilingual_str)> shutdown_fnc =
1423  [](bilingual_str msg) { AbortNode(msg.original, msg); })
1425 
1427  Chainstate &ActiveChainstate() const;
1429  return ActiveChainstate().m_chain;
1430  }
1431  int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
1432  return ActiveChain().Height();
1433  }
1435  return ActiveChain().Tip();
1436  }
1437 
1440  return m_blockman.m_block_index;
1441  }
1442 
1445  bool IsSnapshotActive() const;
1446 
1447  std::optional<BlockHash> SnapshotBlockhash() const;
1448 
1451  return m_snapshot_chainstate && m_ibd_chainstate &&
1452  m_ibd_chainstate->m_disabled;
1453  }
1454 
1482  bool ProcessNewBlock(const std::shared_ptr<const CBlock> &block,
1483  bool force_processing, bool min_pow_checked,
1484  bool *new_block,
1485  avalanche::Processor *const avalanche = nullptr)
1487 
1503  bool ProcessNewBlockHeaders(
1504  const std::vector<CBlockHeader> &block, bool min_pow_checked,
1505  BlockValidationState &state, const CBlockIndex **ppindex = nullptr,
1506  const std::optional<CCheckpointData> &test_checkpoints = std::nullopt)
1508 
1517  [[nodiscard]] MempoolAcceptResult
1518  ProcessTransaction(const CTransactionRef &tx, bool test_accept = false)
1520 
1523  bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1524 
1527  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1528 
1535  void ReportHeadersPresync(const arith_uint256 &work, int64_t height,
1536  int64_t timestamp);
1537 
1540  bool DetectSnapshotChainstate(CTxMemPool *mempool)
1542 
1543  void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1544 
1547  Chainstate &ActivateExistingSnapshot(CTxMemPool *mempool,
1548  BlockHash base_blockhash)
1550 
1560  bool ValidatedSnapshotCleanup() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1561 };
1562 
1564 template <typename DEP>
1565 bool DeploymentActiveAfter(const CBlockIndex *pindexPrev,
1566  const ChainstateManager &chainman, DEP dep) {
1567  return DeploymentActiveAfter(pindexPrev, chainman.GetConsensus(), dep);
1568 }
1569 
1570 template <typename DEP>
1572  const ChainstateManager &chainman, DEP dep) {
1573  return DeploymentActiveAt(index, chainman.GetConsensus(), dep);
1574 }
1575 
1583 const AssumeutxoData *ExpectedAssumeutxo(const int height,
1584  const CChainParams &params);
1585 
1586 #endif // BITCOIN_VALIDATION_H
int flags
Definition: bitcoin-tx.cpp:543
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:19
#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:528
uint64_t getExcessiveBlockSize() const
Definition: validation.h:153
BlockValidationOptions withCheckPoW(bool _checkPoW=true) const
Definition: validation.h:138
BlockValidationOptions(uint64_t _excessiveBlockSize, bool _checkPow=true, bool _checkMerkleRoot=true)
Definition: validation.h:132
BlockValidationOptions withCheckMerkleRoot(bool _checkMerkleRoot=true) const
Definition: validation.h:145
BlockValidationOptions(const Config &config)
Definition: validation.cpp:117
bool shouldValidatePoW() const
Definition: validation.h:151
uint64_t excessiveBlockSize
Definition: validation.h:125
bool shouldValidateMerkleRoot() const
Definition: validation.h:152
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:25
An in-memory indexed chain of blocks.
Definition: chain.h:134
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:80
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:221
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:65
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Definition: coins.h:374
Abstract view on the open txout dataset.
Definition: coins.h:163
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:115
Closure representing one script verification.
Definition: validation.h:526
CScriptCheck & operator=(CScriptCheck &&)=default
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:540
ScriptError GetScriptError() const
Definition: validation.h:557
ScriptExecutionMetrics GetScriptExecutionMetrics() const
Definition: validation.h:559
CScriptCheck(const CScriptCheck &)=delete
uint32_t nFlags
Definition: validation.h:531
TxSigCheckLimiter * pTxLimitSigChecks
Definition: validation.h:536
ScriptExecutionMetrics metrics
Definition: validation.h:534
CTxOut m_tx_out
Definition: validation.h:528
CScriptCheck(CScriptCheck &&)=default
bool cacheStore
Definition: validation.h:532
ScriptError error
Definition: validation.h:533
CScriptCheck & operator=(const CScriptCheck &)=delete
PrecomputedTransactionData txdata
Definition: validation.h:535
const CTransaction * ptxTo
Definition: validation.h:529
unsigned int nIn
Definition: validation.h:530
CheckInputsLimiter * pBlockLimitSigChecks
Definition: validation.h:537
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:616
VerifyDBResult VerifyDB(Chainstate &chainstate, CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
kernel::Notifications & m_notifications
Definition: validation.h:618
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:695
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries with either BLOCK_VALID_TRANSACTIONS (for itself and all ancestors...
Definition: validation.h:827
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:847
CTxMemPool * GetMempool()
Definition: validation.h:843
Mutex m_chainstate_mutex
The ChainState Mutex.
Definition: validation.h:701
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:804
bool HasCoinsViews() const
Does this chainstate have a UTXO set attached?
Definition: validation.h:857
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:837
Mutex cs_avalancheFinalizedBlockIndex
Definition: validation.h:742
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:724
bool reliesOnAssumedValid()
Return true if this chainstate relies on blocks that are assumed-valid.
Definition: validation.h:816
bool m_disabled GUARDED_BY(::cs_main)
This toggle exists for use when doing background validation for UTXO snapshots.
Definition: validation.h:742
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:773
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:728
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:854
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:830
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Definition: validation.h:768
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:1218
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1428
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:1257
CBlockIndex *m_best_parked GUARDED_BY(::cs_main)
Definition: validation.h:1260
const CChainParams & GetParams() const
Definition: validation.h:1312
const arith_uint256 & MinimumChainWork() const
Definition: validation.h:1321
SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main)
Most recent headers presync progress update, for rate-limiting.
Definition: validation.h:1302
bool ShouldCheckBlockIndex() const
Definition: validation.h:1318
const Config & GetConfig() const
Definition: validation.h:1310
const BlockHash & AssumedValidBlock() const
Definition: validation.h:1324
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1438
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1450
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1342
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1431
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1434
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Definition: validation.h:1259
const Options m_options
Definition: validation.h:1346
CBlockIndex *m_best_header GUARDED_BY(::cs_main)
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.h:1377
std::thread m_load_block
Definition: validation.h:1347
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
Definition: validation.h:1395
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:1371
std::unique_ptr< Chainstate > m_snapshot_chainstate GUARDED_BY(::cs_main)
A chainstate initialized on the basis of a UTXO snapshot.
kernel::Notifications & GetNotifications() const
Definition: validation.h:1327
const Consensus::Params & GetConsensus() const
Definition: validation.h:1315
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1350
Simple class for regulating resource usage during CheckInputScripts (and CScriptCheck),...
Definition: validation.h:382
bool consume_and_check(int consumed)
Definition: validation.h:389
std::atomic< int64_t > remaining
Definition: validation.h:384
CheckInputsLimiter(int64_t limit)
Definition: validation.h:387
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:645
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(DBParams db_params, CoinsViewOptions options)
This constructor initializes CCoinsViewDB and CCoinsViewErrorCatcher instances, but it does not creat...
Definition: config.h:19
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:410
TxSigCheckLimiter & operator=(const TxSigCheckLimiter &rhs)
Definition: validation.h:405
TxSigCheckLimiter(const TxSigCheckLimiter &rhs)
Definition: validation.h:402
bool IsValid() const
Definition: validation.h:117
256-bit unsigned big integer.
A base class defining functions for notifying about certain kernel events.
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:74
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:21
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
static void LoadExternalBlockFile(benchmark::Bench &bench)
The LoadExternalBlockFile() function is used during -reindex and -loadblock.
unsigned int nHeight
static void pool cs
Filesystem operations and types.
Definition: fs.h:20
Bridge operations to C stdio.
Definition: fs.cpp:28
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:30
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: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:40
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:86
Definition: amount.h:19
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:46
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:67
User-controlled performance and debug options.
Definition: txdb.h:56
Parameters that influence chain consensus.
Definition: params.h:34
Application-specific storage settings.
Definition: dbwrapper.h:32
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition: validation.h:206
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigchecks.
Definition: validation.h:226
MempoolAcceptResult(ResultType result_type, int64_t vsize, Amount fees, CFeeRate effective_feerate, const std::vector< TxId > &txids_fee_calculations)
Generic constructor for success cases.
Definition: validation.h:284
const ResultType m_result_type
Result type.
Definition: validation.h:217
const std::optional< std::vector< TxId > > m_txids_fee_calculations
Contains the txids of the transactions used for fee-related checks.
Definition: validation.h:243
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:276
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:220
MempoolAcceptResult(TxValidationState state, CFeeRate effective_feerate, const std::vector< TxId > &txids_fee_calculations)
Constructor for fee-related failure case.
Definition: validation.h:293
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:208
@ MEMPOOL_ENTRY
Valid, transaction was already in the mempool.
@ VALID
Fully validated, valid.
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:245
const std::optional< CFeeRate > m_effective_feerate
The feerate at which this transaction was considered.
Definition: validation.h:236
static MempoolAcceptResult FeeFailure(TxValidationState state, CFeeRate effective_feerate, const std::vector< TxId > &txids_fee_calculations)
Definition: validation.h:250
static MempoolAcceptResult Success(int64_t vsize, Amount fees, CFeeRate effective_feerate, const std::vector< TxId > &txids_fee_calculations)
Constructor for success case.
Definition: validation.h:258
static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees)
Constructor for already-in-mempool case.
Definition: validation.h:268
MempoolAcceptResult(int64_t vsize, Amount fees)
Constructor for already-in-mempool case.
Definition: validation.h:301
const std::optional< Amount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:228
std::chrono::time_point< NodeClock > time_point
Definition: time.h:19
Validation result for package mempool acceptance.
Definition: validation.h:309
PackageMempoolAcceptResult(const TxId &txid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a MempoolAcceptResult.
Definition: validation.h:329
PackageMempoolAcceptResult(PackageValidationState state, std::map< TxId, MempoolAcceptResult > &&results)
Definition: validation.h:320
PackageValidationState m_state
Definition: validation.h:310
std::map< TxId, MempoolAcceptResult > m_tx_results
Map from txid to finished MempoolAcceptResults.
Definition: validation.h:318
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 BlockManager, more ergonomically referred to as BlockManager::Options due to th...
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.
GlobalMutex g_best_block_mutex
Definition: validation.cpp:113
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
std::condition_variable g_best_block_cv
Definition: validation.cpp:114
static constexpr int DEFAULT_CHECKLEVEL
Definition: validation.h:96
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:110
bool CheckSequenceLocksAtTip(CBlockIndex *tip, const LockPoints &lock_points)
Check if transaction will be BIP68 final in the next block to be created on top of tip.
Definition: validation.cpp:204
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 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:94
const CBlockIndex * g_best_block
Used to notify getblocktemplate RPC of new tips.
Definition: validation.cpp:115
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.
bool DeploymentActiveAfter(const CBlockIndex *pindexPrev, const ChainstateManager &chainman, DEP dep)
Deployment* info via ChainstateManager.
Definition: validation.h:1565
SnapshotCompletionResult
Definition: validation.h:1170
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:82
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:113
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:84
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.
VerifyDBResult
Definition: validation.h:604
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:97
bool ContextualCheckTransactionForCurrentBlock(const CBlockIndex &active_chain_tip, const Consensus::Params &params, const CTransaction &tx, TxValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(bool 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:589
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
CoinsCacheSizeState
Definition: validation.h:673
@ LARGE
The cache is at >= 90% capacity.
@ CRITICAL
The coins cache is in immediate need of a flush.
std::optional< LockPoints > CalculateLockPointsAtTip(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx)
Calculate LockPoints required to check if transaction will be BIP68 final in the next block to be cre...
Definition: validation.cpp:180
bool DeploymentActiveAt(const CBlockIndex &index, const ChainstateManager &chainman, DEP dep)
Definition: validation.h:1571
void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:95
FlushStateMode
Definition: validation.h:634
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:86
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:89