Bitcoin Core  29.1.0
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2022 The Bitcoin Core developers
3 // Distributed under the MIT software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 
6 #ifndef BITCOIN_VALIDATION_H
7 #define BITCOIN_VALIDATION_H
8 
9 #include <arith_uint256.h>
10 #include <attributes.h>
11 #include <chain.h>
12 #include <checkqueue.h>
13 #include <consensus/amount.h>
14 #include <cuckoocache.h>
15 #include <deploymentstatus.h>
16 #include <kernel/chain.h>
17 #include <kernel/chainparams.h>
19 #include <kernel/cs_main.h> // IWYU pragma: export
20 #include <node/blockstorage.h>
21 #include <policy/feerate.h>
22 #include <policy/packages.h>
23 #include <policy/policy.h>
24 #include <script/script_error.h>
25 #include <script/sigcache.h>
26 #include <sync.h>
27 #include <txdb.h>
28 #include <txmempool.h> // For CTxMemPool::cs
29 #include <uint256.h>
30 #include <util/check.h>
31 #include <util/fs.h>
32 #include <util/hasher.h>
33 #include <util/result.h>
34 #include <util/translation.h>
35 #include <versionbits.h>
36 
37 #include <atomic>
38 #include <map>
39 #include <memory>
40 #include <optional>
41 #include <set>
42 #include <span>
43 #include <stdint.h>
44 #include <string>
45 #include <type_traits>
46 #include <utility>
47 #include <vector>
48 
49 class Chainstate;
50 class CTxMemPool;
51 class ChainstateManager;
52 struct ChainTxData;
55 struct LockPoints;
56 struct AssumeutxoData;
57 namespace node {
58 class SnapshotMetadata;
59 } // namespace node
60 namespace Consensus {
61 struct Params;
62 } // namespace Consensus
63 namespace util {
64 class SignalInterrupt;
65 } // namespace util
66 
68 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
69 static const signed int DEFAULT_CHECKBLOCKS = 6;
70 static constexpr int DEFAULT_CHECKLEVEL{3};
71 // Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat)
72 // At 1MB per block, 288 blocks = 288MB.
73 // Add 15% for Undo data = 331MB
74 // Add 20% for Orphan block rate = 397MB
75 // We want the low water mark after pruning to be at least 397 MB and since we prune in
76 // full block file chunks, we need the high water mark which triggers the prune to be
77 // one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
78 // Setting the target to >= 550 MiB will make it likely we can respect the target.
79 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
80 
82 static constexpr int MAX_SCRIPTCHECK_THREADS{15};
83 
88  POST_INIT
89 };
90 
92 extern const std::vector<std::string> CHECKLEVEL_DOC;
93 
94 CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
95 
96 bool FatalError(kernel::Notifications& notifications, BlockValidationState& state, const bilingual_str& message);
97 
99 void PruneBlockFilesManual(Chainstate& active_chainstate, int nManualPruneHeight);
100 
125  enum class ResultType {
126  VALID,
127  INVALID,
128  MEMPOOL_ENTRY,
130  };
133 
136 
138  const std::list<CTransactionRef> m_replaced_transactions;
140  const std::optional<int64_t> m_vsize;
142  const std::optional<CAmount> m_base_fees;
148  const std::optional<CFeeRate> m_effective_feerate;
154  const std::optional<std::vector<Wtxid>> m_wtxids_fee_calculations;
155 
157  const std::optional<Wtxid> m_other_wtxid;
158 
160  return MempoolAcceptResult(state);
161  }
162 
164  CFeeRate effective_feerate,
165  const std::vector<Wtxid>& wtxids_fee_calculations) {
166  return MempoolAcceptResult(state, effective_feerate, wtxids_fee_calculations);
167  }
168 
169  static MempoolAcceptResult Success(std::list<CTransactionRef>&& replaced_txns,
170  int64_t vsize,
171  CAmount fees,
172  CFeeRate effective_feerate,
173  const std::vector<Wtxid>& wtxids_fee_calculations) {
174  return MempoolAcceptResult(std::move(replaced_txns), vsize, fees,
175  effective_feerate, wtxids_fee_calculations);
176  }
177 
178  static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees) {
179  return MempoolAcceptResult(vsize, fees);
180  }
181 
183  return MempoolAcceptResult(other_wtxid);
184  }
185 
186 // Private constructors. Use static methods MempoolAcceptResult::Success, etc. to construct.
187 private:
190  : m_result_type(ResultType::INVALID), m_state(state) {
191  Assume(!state.IsValid()); // Can be invalid or error
192  }
193 
195  explicit MempoolAcceptResult(std::list<CTransactionRef>&& replaced_txns,
196  int64_t vsize,
197  CAmount fees,
198  CFeeRate effective_feerate,
199  const std::vector<Wtxid>& wtxids_fee_calculations)
200  : m_result_type(ResultType::VALID),
201  m_replaced_transactions(std::move(replaced_txns)),
202  m_vsize{vsize},
203  m_base_fees(fees),
204  m_effective_feerate(effective_feerate),
205  m_wtxids_fee_calculations(wtxids_fee_calculations) {}
206 
209  CFeeRate effective_feerate,
210  const std::vector<Wtxid>& wtxids_fee_calculations)
211  : m_result_type(ResultType::INVALID),
212  m_state(state),
213  m_effective_feerate(effective_feerate),
214  m_wtxids_fee_calculations(wtxids_fee_calculations) {}
215 
217  explicit MempoolAcceptResult(int64_t vsize, CAmount fees)
218  : m_result_type(ResultType::MEMPOOL_ENTRY), m_vsize{vsize}, m_base_fees(fees) {}
219 
221  explicit MempoolAcceptResult(const Wtxid& other_wtxid)
222  : m_result_type(ResultType::DIFFERENT_WITNESS), m_other_wtxid(other_wtxid) {}
223 };
224 
229 {
237  std::map<Wtxid, MempoolAcceptResult> m_tx_results;
238 
240  std::map<Wtxid, MempoolAcceptResult>&& results)
241  : m_state{state}, m_tx_results(std::move(results)) {}
242 
244  std::map<Wtxid, MempoolAcceptResult>&& results)
245  : m_state{state}, m_tx_results(std::move(results)) {}
246 
249  : m_tx_results{ {wtxid, result} } {}
250 };
251 
267  int64_t accept_time, bool bypass_limits, bool test_accept)
269 
281  const Package& txns, bool test_accept, const std::optional<CFeeRate>& client_maxfeerate)
283 
284 /* Mempool validation helper functions */
285 
289 bool CheckFinalTxAtTip(const CBlockIndex& active_chain_tip, const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
290 
309 std::optional<LockPoints> CalculateLockPointsAtTip(
310  CBlockIndex* tip,
311  const CCoinsView& coins_view,
312  const CTransaction& tx);
313 
324  const LockPoints& lock_points);
325 
331 {
332 private:
335  unsigned int nIn;
336  unsigned int nFlags;
340 
341 public:
342  CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, SignatureCache& signature_cache, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
343  m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), txdata(txdataIn), m_signature_cache(&signature_cache) { }
344 
345  CScriptCheck(const CScriptCheck&) = delete;
346  CScriptCheck& operator=(const CScriptCheck&) = delete;
347  CScriptCheck(CScriptCheck&&) = default;
348  CScriptCheck& operator=(CScriptCheck&&) = default;
349 
350  std::optional<std::pair<ScriptError, std::string>> operator()();
351 };
352 
353 // CScriptCheck is used a lot in std::vector, make sure that's efficient
354 static_assert(std::is_nothrow_move_assignable_v<CScriptCheck>);
355 static_assert(std::is_nothrow_move_constructible_v<CScriptCheck>);
356 static_assert(std::is_nothrow_destructible_v<CScriptCheck>);
357 
363 {
364 private:
367 
368 public:
371 
372  ValidationCache(size_t script_execution_cache_bytes, size_t signature_cache_bytes);
373 
374  ValidationCache(const ValidationCache&) = delete;
375  ValidationCache& operator=(const ValidationCache&) = delete;
376 
379 };
380 
384 bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
385 
388  const CChainParams& chainparams,
389  Chainstate& chainstate,
390  const CBlock& block,
391  CBlockIndex* pindexPrev,
392  bool fCheckPOW = true,
393  bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
394 
396 bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams);
397 
399 bool IsBlockMutated(const CBlock& block, bool check_witness_root);
400 
403 
404 enum class VerifyDBResult {
405  SUCCESS,
407  INTERRUPTED,
410 };
411 
414 {
415 private:
417 
418 public:
419  explicit CVerifyDB(kernel::Notifications& notifications);
420  ~CVerifyDB();
421  [[nodiscard]] VerifyDBResult VerifyDB(
422  Chainstate& chainstate,
423  const Consensus::Params& consensus_params,
424  CCoinsView& coinsview,
425  int nCheckLevel,
426  int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
427 };
428 
430 {
431  DISCONNECT_OK, // All good.
432  DISCONNECT_UNCLEAN, // Rolled back, but UTXO set was inconsistent with block.
433  DISCONNECT_FAILED // Something else went wrong.
434 };
435 
436 class ConnectTrace;
437 
439 enum class FlushStateMode {
440  NONE,
441  IF_NEEDED,
442  PERIODIC,
443  ALWAYS
444 };
445 
455 class CoinsViews {
456 
457 public:
460  CCoinsViewDB m_dbview GUARDED_BY(cs_main);
461 
464 
467  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
468 
475  CoinsViews(DBParams db_params, CoinsViewOptions options);
476 
478  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
479 };
480 
482 {
484  CRITICAL = 2,
486  LARGE = 1,
487  OK = 0
488 };
489 
505 {
506 protected:
513 
517 
519  std::unique_ptr<CoinsViews> m_coins_views;
520 
532  bool m_disabled GUARDED_BY(::cs_main) {false};
533 
535  const CBlockIndex* m_cached_snapshot_base GUARDED_BY(::cs_main) {nullptr};
536 
537 public:
541 
546 
547  explicit Chainstate(
548  CTxMemPool* mempool,
549  node::BlockManager& blockman,
550  ChainstateManager& chainman,
551  std::optional<uint256> from_snapshot_blockhash = std::nullopt);
552 
558 
565  void InitCoinsDB(
566  size_t cache_size_bytes,
567  bool in_memory,
568  bool should_wipe,
569  fs::path leveldb_name = "chainstate");
570 
573  void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
574 
577  bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
578  {
580  return m_coins_views && m_coins_views->m_cacheview;
581  }
582 
586 
592  const std::optional<uint256> m_from_snapshot_blockhash;
593 
599  const CBlockIndex* SnapshotBase() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
600 
608  std::set<CBlockIndex*, node::CBlockIndexWorkComparator> setBlockIndexCandidates;
609 
612  {
615  return *Assert(m_coins_views->m_cacheview);
616  }
617 
620  {
622  return Assert(m_coins_views)->m_dbview;
623  }
624 
627  {
628  return m_mempool;
629  }
630 
634  {
636  return Assert(m_coins_views)->m_catcherview;
637  }
638 
640  void ResetCoinsViews() { m_coins_views.reset(); }
641 
643  bool HasCoinsViews() const { return (bool)m_coins_views; }
644 
647 
650 
653  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
655 
667  bool FlushStateToDisk(
668  BlockValidationState& state,
669  FlushStateMode mode,
670  int nManualPruneHeight = 0);
671 
673  void ForceFlushStateToDisk();
674 
677  void PruneAndFlush();
678 
700  bool ActivateBestChain(
701  BlockValidationState& state,
702  std::shared_ptr<const CBlock> pblock = nullptr)
705 
706  // Block (dis)connection on a given view:
707  DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view)
709  bool ConnectBlock(const CBlock& block, BlockValidationState& state, CBlockIndex* pindex,
710  CCoinsViewCache& view, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
711 
712  // Apply the effects of a block disconnection on the UTXO set.
714 
715  // Manual block validity manipulation:
720  bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
723 
725  bool InvalidateBlock(BlockValidationState& state, CBlockIndex* pindex)
728 
730  void SetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
731 
734 
736  bool ReplayBlocks();
737 
739  [[nodiscard]] bool NeedsRedownload() const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
741  bool LoadGenesisBlock();
742 
744 
746 
747  void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
748 
750  const CBlockIndex* FindForkInGlobalIndex(const CBlockLocator& locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
751 
754 
758  CoinsCacheSizeState GetCoinsCacheSizeState() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
759 
760  CoinsCacheSizeState GetCoinsCacheSizeState(
761  size_t max_coins_cache_size_bytes,
762  size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
763 
765 
767  RecursiveMutex* MempoolMutex() const LOCK_RETURNED(m_mempool->cs)
768  {
769  return m_mempool ? &m_mempool->cs : nullptr;
770  }
771 
772 private:
773  bool ActivateBestChainStep(BlockValidationState& state, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
774  bool ConnectTip(BlockValidationState& state, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
775 
778 
780 
783 
798  DisconnectedBlockTransactions& disconnectpool,
800 
802  void UpdateTip(const CBlockIndex* pindexNew)
804 
805  SteadyClock::time_point m_last_write{};
806  SteadyClock::time_point m_last_flush{};
807 
812  [[nodiscard]] util::Result<void> InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
813 
814  friend ChainstateManager;
815 };
816 
818  SUCCESS,
819  SKIPPED,
820 
821  // Expected assumeutxo configuration data is not found for the height of the
822  // base block.
824 
825  // Failed to generate UTXO statistics (to check UTXO set hash) for the background
826  // chainstate.
827  STATS_FAILED,
828 
829  // The UTXO set hash of the background validation chainstate does not match
830  // the one expected by assumeutxo chainparams.
832 
833  // The blockhash of the current tip of the background validation chainstate does
834  // not match the one expected by the snapshot chainstate.
836 };
837 
866 {
867 private:
884  std::unique_ptr<Chainstate> m_ibd_chainstate GUARDED_BY(::cs_main);
885 
896  std::unique_ptr<Chainstate> m_snapshot_chainstate GUARDED_BY(::cs_main);
897 
900  Chainstate* m_active_chainstate GUARDED_BY(::cs_main) {nullptr};
901 
902  CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
903 
905  CBlockIndex* m_last_notified_header GUARDED_BY(GetMutex()){nullptr};
906 
907  bool NotifyHeaderTip() LOCKS_EXCLUDED(GetMutex());
908 
916  [[nodiscard]] util::Result<void> PopulateAndValidateSnapshot(
917  Chainstate& snapshot_chainstate,
918  AutoFile& coins_file,
919  const node::SnapshotMetadata& metadata);
920 
928  bool AcceptBlockHeader(
929  const CBlockHeader& block,
930  BlockValidationState& state,
931  CBlockIndex** ppindex,
932  bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
933  friend Chainstate;
934 
936  std::chrono::time_point<std::chrono::steady_clock> m_last_presync_update GUARDED_BY(::cs_main) {};
937 
938  std::array<ThresholdConditionCache, VERSIONBITS_NUM_BITS> m_warningcache GUARDED_BY(::cs_main);
939 
945  bool IsUsable(const Chainstate* const cs) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
946  return cs && !cs->m_disabled;
947  }
948 
951 
954  SteadyClock::duration GUARDED_BY(::cs_main) time_check{};
955  SteadyClock::duration GUARDED_BY(::cs_main) time_forks{};
956  SteadyClock::duration GUARDED_BY(::cs_main) time_connect{};
957  SteadyClock::duration GUARDED_BY(::cs_main) time_verify{};
958  SteadyClock::duration GUARDED_BY(::cs_main) time_undo{};
959  SteadyClock::duration GUARDED_BY(::cs_main) time_index{};
960  SteadyClock::duration GUARDED_BY(::cs_main) time_total{};
961  int64_t GUARDED_BY(::cs_main) num_blocks_total{0};
962  SteadyClock::duration GUARDED_BY(::cs_main) time_connect_total{};
963  SteadyClock::duration GUARDED_BY(::cs_main) time_flush{};
964  SteadyClock::duration GUARDED_BY(::cs_main) time_chainstate{};
965  SteadyClock::duration GUARDED_BY(::cs_main) time_post_connect{};
966 
967 public:
969 
970  explicit ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager::Options blockman_options);
971 
974  std::function<void()> snapshot_download_completed = std::function<void()>();
975 
976  const CChainParams& GetParams() const { return m_options.chainparams; }
977  const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }
978  bool ShouldCheckBlockIndex() const;
979  const arith_uint256& MinimumChainWork() const { return *Assert(m_options.minimum_chain_work); }
980  const uint256& AssumedValidBlock() const { return *Assert(m_options.assumed_valid_block); }
981  kernel::Notifications& GetNotifications() const { return m_options.notifications; };
982 
988  void CheckBlockIndex();
989 
1002 
1008 
1010 
1018  mutable std::atomic<bool> m_cached_finished_ibd{false};
1019 
1025  int32_t nBlockSequenceId GUARDED_BY(::cs_main) = 1;
1027  int32_t nBlockReverseSequenceId = -1;
1029  arith_uint256 nLastPreciousChainwork = 0;
1030 
1031  // Reset the memory-only sequence counters we use to track block arrival
1032  // (used by tests to reset state)
1034  {
1036  nBlockSequenceId = 1;
1037  nBlockReverseSequenceId = -1;
1038  }
1039 
1040 
1060  std::set<CBlockIndex*> m_failed_blocks;
1061 
1063  CBlockIndex* m_best_header GUARDED_BY(::cs_main){nullptr};
1064 
1067  size_t m_total_coinstip_cache{0};
1068  //
1071  size_t m_total_coinsdb_cache{0};
1072 
1076  // constructor
1077  Chainstate& InitializeChainstate(CTxMemPool* mempool) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1078 
1080  std::vector<Chainstate*> GetAll();
1081 
1094  [[nodiscard]] util::Result<CBlockIndex*> ActivateSnapshot(
1095  AutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory);
1096 
1104  SnapshotCompletionResult MaybeCompleteSnapshotValidation() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1105 
1107  const CBlockIndex* GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1108 
1110  Chainstate& ActiveChainstate() const;
1111  CChain& ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChainstate().m_chain; }
1112  int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Height(); }
1113  CBlockIndex* ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Tip(); }
1114 
1117  return IsUsable(m_snapshot_chainstate.get()) && IsUsable(m_ibd_chainstate.get());
1118  }
1119 
1122  return BackgroundSyncInProgress() ? m_ibd_chainstate->m_chain.Tip() : nullptr;
1123  }
1124 
1126  {
1128  return m_blockman.m_block_index;
1129  }
1130 
1135 
1138  bool IsSnapshotActive() const;
1139 
1140  std::optional<uint256> SnapshotBlockhash() const;
1141 
1144  {
1145  return m_snapshot_chainstate && m_ibd_chainstate && m_ibd_chainstate->m_disabled;
1146  }
1147 
1149  bool IsInitialBlockDownload() const;
1150 
1152  double GuessVerificationProgress(const CBlockIndex* pindex) const;
1153 
1180  void LoadExternalBlockFile(
1181  AutoFile& file_in,
1182  FlatFilePos* dbp = nullptr,
1183  std::multimap<uint256, FlatFilePos>* blocks_with_unknown_parent = nullptr);
1184 
1209  bool ProcessNewBlock(const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked, bool* new_block) LOCKS_EXCLUDED(cs_main);
1210 
1222  bool ProcessNewBlockHeaders(std::span<const CBlockHeader> headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
1223 
1243  bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock, bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1244 
1245  void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1246 
1253  [[nodiscard]] MempoolAcceptResult ProcessTransaction(const CTransactionRef& tx, bool test_accept=false)
1255 
1257  bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1258 
1261  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1262 
1264  void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev) const;
1265 
1267  std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev) const;
1268 
1273  void ReportHeadersPresync(const arith_uint256& work, int64_t height, int64_t timestamp);
1274 
1277  bool DetectSnapshotChainstate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1278 
1279  void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1280 
1283  [[nodiscard]] bool DeleteSnapshotChainstate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1284 
1287  Chainstate& ActivateExistingSnapshot(uint256 base_blockhash) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1288 
1298  bool ValidatedSnapshotCleanup() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1299 
1308  Chainstate& GetChainstateForIndexing() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1309 
1313  std::pair<int, int> GetPruneRange(
1314  const Chainstate& chainstate, int last_height_can_prune) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1315 
1318  std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1319 
1323  void RecalculateBestHeader() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1324 
1325  CCheckQueue<CScriptCheck>& GetCheckQueue() { return m_script_check_queue; }
1326 
1327  ~ChainstateManager();
1328 };
1329 
1331 template<typename DEP>
1332 bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const ChainstateManager& chainman, DEP dep)
1333 {
1334  return DeploymentActiveAfter(pindexPrev, chainman.GetConsensus(), dep, chainman.m_versionbitscache);
1335 }
1336 
1337 template<typename DEP>
1338 bool DeploymentActiveAt(const CBlockIndex& index, const ChainstateManager& chainman, DEP dep)
1339 {
1340  return DeploymentActiveAt(index, chainman.GetConsensus(), dep, chainman.m_versionbitscache);
1341 }
1342 
1343 template<typename DEP>
1344 bool DeploymentEnabled(const ChainstateManager& chainman, DEP dep)
1345 {
1346  return DeploymentEnabled(chainman.GetConsensus(), dep);
1347 }
1348 
1350 bool IsBIP30Repeat(const CBlockIndex& block_index);
1351 
1353 bool IsBIP30Unspendable(const CBlockIndex& block_index);
1354 
1355 #endif // BITCOIN_VALIDATION_H
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:611
const std::optional< CFeeRate > m_effective_feerate
The feerate at which this transaction was considered.
Definition: validation.h:148
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1007
const std::optional< uint256 > m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from. ...
Definition: validation.h:592
const uint256 & AssumedValidBlock() const
Definition: validation.h:980
void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:516
Valid signature cache, to avoid doing expensive ECDSA signature checking twice for every transaction ...
Definition: sigcache.h:38
bool ReplayBlocks()
Replay blocks that aren&#39;t fully applied to the database.
CScriptCheck & operator=(const CScriptCheck &)=delete
bool DeploymentActiveAfter(const CBlockIndex *pindexPrev, const ChainstateManager &chainman, DEP dep)
Deployment* info via ChainstateManager.
Definition: validation.h:1332
SignatureCache m_signature_cache
Definition: validation.h:370
bool DeploymentActiveAt(const CBlockIndex &index, const ChainstateManager &chainman, DEP dep)
Definition: validation.h:1338
AssertLockHeld(pool.cs)
SteadyClock::time_point m_last_flush
Definition: validation.h:806
const Options m_options
Definition: validation.h:1004
static MempoolAcceptResult FeeFailure(TxValidationState state, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Definition: validation.h:163
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:85
Convenience class for initializing and passing the script execution cache and signature cache...
Definition: validation.h:362
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
Describes a place in the block chain to another node such that if the other node doesn&#39;t have the sam...
Definition: block.h:123
int64_t GUARDED_BY(::cs_main) num_blocks_total
Definition: validation.h:961
const std::optional< std::vector< Wtxid > > m_wtxids_fee_calculations
Contains the wtxids of the transactions used for fee-related checks.
Definition: validation.h:154
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Definition: validation.h:902
Valid, transaction was already in the mempool.
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances...
Definition: validation.h:535
Bilingual messages:
Definition: translation.h:24
Definition: block.h:68
The cache is at >= 90% capacity.
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:455
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:865
An in-memory indexed chain of blocks.
Definition: chain.h:416
unsigned int nFlags
Definition: validation.h:336
SteadyClock::duration GUARDED_BY(::cs_main) time_connect
Definition: validation.h:956
size_t m_coinsdb_cache_size_bytes
The cache size of the on-disk coins view.
Definition: validation.h:646
VerifyDBResult VerifyDB(Chainstate &chainstate, const Consensus::Params &consensus_params, CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:50
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:68
DisconnectResult
Definition: validation.h:429
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:519
CSHA256 m_script_execution_cache_hasher
Pre-initialized hasher to avoid having to recreate it for every hash calculation. ...
Definition: validation.h:366
static constexpr int DEFAULT_CHECKLEVEL
Definition: validation.h:70
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:125
std::unordered_map< uint256, CBlockIndex, BlockHasher > BlockMap
Definition: blockstorage.h:87
#define LOCK_RETURNED(x)
Definition: threadsafety.h:47
bool CheckFinalTxAtTip(const CBlockIndex &active_chain_tip, const CTransaction &tx)
Definition: validation.cpp:146
Chainstate *m_active_chainstate GUARDED_BY(::cs_main)
Points to either the ibd or snapshot chainstate; indicates our most-work chain.
Definition: validation.h:900
static constexpr int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:82
The coins cache is in immediate need of a flush.
An options struct for ChainstateManager, more ergonomically referred to as ChainstateManager::Options...
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.
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigops. ...
Definition: validation.h:140
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:135
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:1060
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:142
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system...
Definition: chainparams.h:80
User-controlled performance and debug options.
Definition: txdb.h:28
bool ConnectTip(BlockValidationState &state, CBlockIndex *pindexNew, const std::shared_ptr< const CBlock > &pblock, ConnectTrace &connectTrace, DisconnectedBlockTransactions &disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Connect a new block to m_chain.
void MaybeUpdateMempoolForReorg(DisconnectedBlockTransactions &disconnectpool, bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Make mempool consistent after a reorg, by re-adding or recursively erasing disconnected block transac...
Definition: validation.cpp:296
const ResultType m_result_type
Result type.
Definition: validation.h:132
void InvalidBlockFound(CBlockIndex *pindex, const BlockValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
PackageMempoolAcceptResult(PackageValidationState state, CFeeRate feerate, std::map< Wtxid, MempoolAcceptResult > &&results)
Definition: validation.h:243
std::map< Wtxid, MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
Definition: validation.h:237
bool DeploymentEnabled(const ChainstateManager &chainman, DEP dep)
Definition: validation.h:1344
const std::vector< std::string > CHECKLEVEL_DOC
Documentation for argument &#39;checklevel&#39;.
Definition: validation.cpp:99
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:585
bool cacheStore
Definition: validation.h:337
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:391
CBlockIndex *m_best_header GUARDED_BY(::cs_main)
Best header we&#39;ve seen so far (used for getheaders queries&#39; starting points).
Definition: validation.h:1063
bool HasCoinsViews() const
Does this chainstate have a UTXO set attached?
Definition: validation.h:643
CTxOut m_tx_out
Definition: validation.h:333
Filesystem operations and types.
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:640
PackageMempoolAcceptResult(PackageValidationState state, std::map< Wtxid, MempoolAcceptResult > &&results)
Definition: validation.h:239
const util::SignalInterrupt & m_interrupt
Definition: validation.h:1003
CVerifyDB(kernel::Notifications &notifications)
Transaction validation functions.
VersionBitsCache m_versionbitscache
Track versionbit status.
Definition: validation.h:1134
CoinsViews(DBParams db_params, CoinsViewOptions options)
This constructor initializes CCoinsViewDB and CCoinsViewErrorCatcher instances, but it does not creat...
bool IsUsable(const Chainstate *const cs) const EXCLUSIVE_LOCKS_REQUIRED(
Return true if a chainstate is considered usable.
Definition: validation.h:945
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
void PruneAndFlush()
Prune blockfiles from the disk if necessary and then flush chainstate changes if we pruned...
void UpdateTip(const CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(SteadyClock::time_poin m_last_write)
Check warning conditions and do some notifications on new chain tip set.
Definition: validation.h:805
bool IsValid() const
Definition: validation.h:106
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &txns, bool test_accept, const std::optional< CFeeRate > &client_maxfeerate) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Validate (and maybe submit) a package to the mempool.
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:545
bool DisconnectTip(BlockValidationState &state, DisconnectedBlockTransactions *disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Disconnect m_chain&#39;s tip.
An options struct for BlockManager, more ergonomically referred to as BlockManager::Options due to th...
util::Result< void > InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(friend ChainstateManager
In case of an invalid snapshot, rename the coins leveldb directory so that it can be examined for iss...
Definition: validation.h:812
bool BackgroundSyncInProgress() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
The state of a background sync (for net processing)
Definition: validation.h:1116
Chainstate stores and provides an API to update our local knowledge of the current best chain...
Definition: validation.h:504
bool IsBIP30Repeat(const CBlockIndex &block_index)
Identifies blocks that overwrote an existing coinbase output in the UTXO set (see BIP30) ...
const std::list< CTransactionRef > m_replaced_transactions
Mempool transactions replaced by the tx.
Definition: validation.h:138
std::chrono::steady_clock SteadyClock
Definition: time.h:27
Abstract view on the open txout dataset.
Definition: coins.h:309
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
Definition: chain.h:25
static void LoadExternalBlockFile(benchmark::Bench &bench)
The LoadExternalBlockFile() function is used during -reindex and -loadblock.
Validation result for package mempool acceptance.
Definition: validation.h:228
bool ActivateBestChain(BlockValidationState &state, std::shared_ptr< const CBlock > pblock=nullptr) LOCKS_EXCLUDED(DisconnectResult DisconnectBlock(const CBlock &block, const CBlockIndex *pindex, CCoinsViewCache &view) EXCLUSIVE_LOCKS_REQUIRED(boo ConnectBlock)(const CBlock &block, BlockValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, bool fJustCheck=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Find the best known block, and make it the tip of the block chain.
Definition: validation.h:709
bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Apply the effects of a block on the utxo cache, ignoring that it may already have been applied...
bool m_disabled GUARDED_BY(::cs_main)
This toggle exists for use when doing background validation for UTXO snapshots.
Definition: validation.h:532
ValidationCache(size_t script_execution_cache_bytes, size_t signature_cache_bytes)
SnapshotCompletionResult
Definition: validation.h:817
FlushStateMode
Definition: validation.h:439
Chainstate(CTxMemPool *mempool, node::BlockManager &blockman, ChainstateManager &chainman, std::optional< uint256 > from_snapshot_blockhash=std::nullopt)
kernel::Notifications & GetNotifications() const
Definition: validation.h:981
CBlockIndex *m_last_notified_header GUARDED_BY(GetMutex())
The last header for which a headerTip notification was issued.
Definition: validation.h:905
std::optional< std::pair< ScriptError, std::string > > operator()()
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:413
bool NeedsRedownload() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Whether the chain state needs to be redownloaded due to lack of witness data.
Holds various statistics on transactions within a chain.
Definition: chainparams.h:70
const Consensus::Params & GetConsensus() const
Definition: validation.h:977
bool ActivateBestChainStep(BlockValidationState &state, CBlockIndex *pindexMostWork, const std::shared_ptr< const CBlock > &pblock, bool &fInvalidFound, ConnectTrace &connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Try to make some progress towards making pindexMostWork the active block.
SteadyClock::duration GUARDED_BY(::cs_main) time_index
Definition: validation.h:959
bool FatalError(kernel::Notifications &notifications, BlockValidationState &state, const bilingual_str &message)
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1113
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:138
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:619
SteadyClock::duration GUARDED_BY(::cs_main) time_total
Definition: validation.h:960
void ForceFlushStateToDisk()
Unconditionally flush all changes to disk.
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:633
An output of a transaction.
Definition: transaction.h:149
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Update the chain tip based on database information, i.e.
static void CheckBlockIndex(benchmark::Bench &bench)
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1001
CBlockIndex * FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Return the tip of the chain with the most work in it, that isn&#39;t known to be invalid (it&#39;s however fa...
Parameters that influence chain consensus.
Definition: params.h:74
A base class defining functions for notifying about certain kernel events.
void TryAddBlockIndexCandidate(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
bool CheckFinalTxAtTip(const CBlockIndex &active_chain_tip, const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(std::optional< LockPoints > CalculateLockPointsAtTip(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx)
Check if transaction will be final in the next block to be created.
Definition: validation.h:309
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the mempool.
DisconnectedBlockTransactions.
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
Definition: validation.h:1080
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition: validation.h:123
unsigned int nHeight
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:189
static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees)
Definition: validation.h:178
#define Assume(val)
Assume is the identity function.
Definition: check.h:97
static MempoolAcceptResult MempoolTxDifferentWitness(const Wtxid &other_wtxid)
Definition: validation.h:182
256-bit unsigned big integer.
SteadyClock::duration GUARDED_BY(::cs_main) time_post_connect
Definition: validation.h:965
BIP 9 allows multiple softforks to be deployed in parallel.
Definition: versionbits.h:80
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1125
Closure representing one script verification Note that this stores references to the spending transac...
Definition: validation.h:330
ValidationCache m_validation_cache
Definition: validation.h:1009
Definition: messages.h:20
const CBlockIndex *SnapshotBase() EXCLUSIVE_LOCKS_REQUIRED(std::set< CBlockIndex *, node::CBlockIndexWorkComparator > setBlockIndexCandidates
The base of the snapshot this chainstate was created from.
Definition: validation.h:599
void InvalidateBlock(ChainstateManager &chainman, const uint256 block_hash)
MempoolAcceptResult(TxValidationState state, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Constructor for fee-related failure case.
Definition: validation.h:208
SteadyClock::duration GUARDED_BY(::cs_main) time_verify
Definition: validation.h:957
Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another threa...
SteadyClock::duration GUARDED_BY(::cs_main) time_flush
Definition: validation.h:963
ValidationCache & operator=(const ValidationCache &)=delete
const CChainParams & GetParams() const
Definition: validation.h:976
PackageValidationState m_state
Definition: validation.h:230
256-bit opaque blob.
Definition: uint256.h:201
CoinsCacheSizeState
Definition: validation.h:481
CSHA256 ScriptExecutionCacheHasher() const
Return a copy of the pre-initialized hasher.
Definition: validation.h:378
const CTransaction * ptxTo
Definition: validation.h:334
const arith_uint256 & MinimumChainWork() const
Definition: validation.h:979
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
bool TestBlockValidity(BlockValidationState &state, const CChainParams &chainparams, Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev, bool fCheckPOW=true, bool fCheckMerkleRoot=true) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check a block is completely valid from start to finish (only works on top of our current best block) ...
kernel::Notifications & m_notifications
Definition: validation.h:416
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:303
auto result
Definition: common-types.h:74
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
CCoinsViewDB m_dbview GUARDED_BY(cs_main)
The lowest level of the CoinsViews cache hierarchy sits in a leveldb database on disk.
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:140
const CChainParams & Params()
Return the currently selected parameters.
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:69
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:37
void PruneBlockIndexCandidates()
Delete all entries in setBlockIndexCandidates that are worse than the current tip.
CCheckQueue< CScriptCheck > m_script_check_queue
A queue for script verifications that have to be performed by worker threads.
Definition: validation.h:950
SteadyClock::duration GUARDED_BY(::cs_main) time_check
Timers and counters used for benchmarking validation in both background and active chainstates...
Definition: validation.h:954
bool m_mempool cs
Definition: validation.h:713
void ResetBlockSequenceCounters() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1033
VerifyDBResult
Definition: validation.h:404
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1112
Application-specific storage settings.
Definition: dbwrapper.h:34
Fee rate in satoshis per kilovirtualbyte: CAmount / kvB.
Definition: feerate.h:32
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:47
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, SignatureCache &signature_cache, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:342
const CBlockIndex * GetBackgroundSyncTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
The tip of the background sync chain.
Definition: validation.h:1121
PackageMempoolAcceptResult(const Wtxid &wtxid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a single MempoolAcceptResult.
Definition: validation.h:248
unsigned int nIn
Definition: validation.h:335
size_t m_coinstip_cache_size_bytes
The cache size of the in-memory coins view.
Definition: validation.h:649
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
Functions for validating blocks and updating the block tree.
MempoolAcceptResult(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Constructor for success case.
Definition: validation.h:195
Mutex m_chainstate_mutex
The ChainState Mutex A lock that must be held when modifying this ChainState - held in ActivateBestCh...
Definition: validation.h:512
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:159
SteadyClock::duration GUARDED_BY(::cs_main) time_chainstate
Definition: validation.h:964
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: transaction.h:295
void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
bool IsBIP30Unspendable(const CBlockIndex &block_index)
Identifies blocks which coinbase output was subsequently overwritten in the UTXO set (see BIP30) ...
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:362
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:79
MempoolAcceptResult(int64_t vsize, CAmount fees)
Constructor for already-in-mempool case.
Definition: validation.h:217
MempoolAcceptResult(const Wtxid &other_wtxid)
Constructor for witness-swapped case.
Definition: validation.h:221
CuckooCache::cache< uint256, SignatureCacheHasher > m_script_execution_cache
Definition: validation.h:369
A hasher class for SHA-256.
Definition: sha256.h:13
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate...
Definition: coins.h:511
bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(void SetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(voi ResetBlockFailureFlags)(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark a block as precious and reorganize.
Definition: validation.h:733
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
Definition: cs_main.cpp:8
arith_uint256 CalculateClaimedHeadersWork(std::span< const CBlockHeader > headers)
Return the sum of the claimed work on a given set of headers.
SignatureCache * m_signature_cache
Definition: validation.h:339
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:245
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:21
CTxMemPool * GetMempool()
Definition: validation.h:626
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:233
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1143
const std::optional< Wtxid > m_other_wtxid
The wtxid of the transaction in the mempool which has the same txid but different witness...
Definition: validation.h:157
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it...
Definition: txmempool.h:390
#define Assert(val)
Identity function.
Definition: check.h:85
static MempoolAcceptResult Success(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Definition: validation.h:169
SteadyClock::duration GUARDED_BY(::cs_main) time_undo
Definition: validation.h:958
Used to track blocks whose transactions were applied to the UTXO state as a part of a single Activate...
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:33
transaction_identifier represents the two canonical transaction identifier types (txid, wtxid).
bool IsBlockMutated(const CBlock &block, bool check_witness_root)
Check if a block has been mutated (with respect to its merkle root and witness commitments).
SteadyClock::duration GUARDED_BY(::cs_main) time_connect_total
Definition: validation.h:962
PrecomputedTransactionData * txdata
Definition: validation.h:338
SteadyClock::duration GUARDED_BY(::cs_main) time_forks
Definition: validation.h:955