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 
75 namespace Consensus {
76 struct Params;
77 }
78 
79 #define MIN_TRANSACTION_SIZE \
80  (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))
81 
83 static const int MAX_SCRIPTCHECK_THREADS = 15;
85 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
86 
87 static const bool DEFAULT_PEERBLOOMFILTERS = true;
88 
90 static const int DEFAULT_STOPATHEIGHT = 0;
95 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
96 static const signed int DEFAULT_CHECKBLOCKS = 6;
97 static constexpr int DEFAULT_CHECKLEVEL{3};
111 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
112 
115 
117 extern std::condition_variable g_best_block_cv;
119 extern uint256 g_best_block;
120 
122 extern const std::vector<std::string> CHECKLEVEL_DOC;
123 
125 private:
127  bool checkPoW : 1;
128  bool checkMerkleRoot : 1;
129 
130 public:
131  // Do full validation by default
132  explicit BlockValidationOptions(const Config &config);
133  explicit BlockValidationOptions(uint64_t _excessiveBlockSize,
134  bool _checkPow = true,
135  bool _checkMerkleRoot = true)
136  : excessiveBlockSize(_excessiveBlockSize), checkPoW(_checkPow),
137  checkMerkleRoot(_checkMerkleRoot) {}
138 
139  BlockValidationOptions withCheckPoW(bool _checkPoW = true) const {
140  BlockValidationOptions ret = *this;
141  ret.checkPoW = _checkPoW;
142  return ret;
143  }
144 
146  withCheckMerkleRoot(bool _checkMerkleRoot = true) const {
147  BlockValidationOptions ret = *this;
148  ret.checkMerkleRoot = _checkMerkleRoot;
149  return ret;
150  }
151 
152  bool shouldValidatePoW() const { return checkPoW; }
153  bool shouldValidateMerkleRoot() const { return checkMerkleRoot; }
154  uint64_t getExcessiveBlockSize() const { return excessiveBlockSize; }
155 };
156 
160 void StartScriptCheckWorkerThreads(int threads_num);
161 
166 
167 Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams);
168 
169 bool AbortNode(BlockValidationState &state, const std::string &strMessage,
170  const bilingual_str &userMessage = bilingual_str{});
171 
176 double GuessVerificationProgress(const ChainTxData &data,
177  const CBlockIndex *pindex);
178 
180 void PruneBlockFilesManual(Chainstate &active_chainstate,
181  int nManualPruneHeight);
182 
188  enum class ResultType {
190  VALID,
192  INVALID,
195  };
198 
199  // The following fields are only present when m_result_type =
200  // ResultType::VALID or MEMPOOL_ENTRY
205  const std::optional<int64_t> m_vsize;
207  const std::optional<Amount> m_base_fees;
209  return MempoolAcceptResult(state);
210  }
211 
213  static MempoolAcceptResult Success(int64_t vsize, Amount fees) {
214  return MempoolAcceptResult(ResultType::VALID, vsize, fees);
215  }
216 
221  static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees) {
222  return MempoolAcceptResult(ResultType::MEMPOOL_ENTRY, vsize, fees);
223  }
224 
225  // Private constructors. Use static methods MempoolAcceptResult::Success,
226  // etc. to construct.
227 private:
230  : m_result_type(ResultType::INVALID), m_state(state),
231  m_base_fees(std::nullopt) {
232  // Can be invalid or error
233  Assume(!state.IsValid());
234  }
235 
237  explicit MempoolAcceptResult(ResultType result_type, int64_t vsize,
238  Amount fees)
239  : m_result_type(result_type), m_vsize{vsize}, m_base_fees(fees) {}
240 };
241 
254  std::map<const TxId, const MempoolAcceptResult> m_tx_results;
255 
258  std::map<const TxId, const MempoolAcceptResult> &&results)
259  : m_state{state}, m_tx_results(std::move(results)) {}
260 
265  explicit PackageMempoolAcceptResult(const TxId &txid,
266  const MempoolAcceptResult &result)
267  : m_tx_results{{txid, result}} {}
268 };
269 
293 AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx,
294  int64_t accept_time, bool bypass_limits,
295  bool test_accept = false, unsigned int heightOverride = 0)
297 
310 ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool,
311  const Package &txns, bool test_accept)
313 
319 protected:
320  std::atomic<int64_t> remaining;
321 
322 public:
323  explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {}
324 
325  bool consume_and_check(int consumed) {
326  auto newvalue = (remaining -= consumed);
327  return newvalue >= 0;
328  }
329 
330  bool check() { return remaining >= 0; }
331 };
332 
334 public:
336 
337  // Let's make this bad boy copiable.
339  : CheckInputsLimiter(rhs.remaining.load()) {}
340 
342  remaining = rhs.remaining.load();
343  return *this;
344  }
345 
347  TxSigCheckLimiter txLimiter;
348  // Historically, there has not been a transaction with more than 20k sig
349  // checks on testnet or mainnet, so this effectively disable sigchecks.
350  txLimiter.remaining = 20000;
351  return txLimiter;
352  }
353 };
354 
355 class ConnectTrace;
356 
386 bool CheckInputScripts(const CTransaction &tx, TxValidationState &state,
387  const CCoinsViewCache &view, const uint32_t flags,
388  bool sigCacheStore, bool scriptCacheStore,
389  const PrecomputedTransactionData &txdata,
390  int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks,
391  CheckInputsLimiter *pBlockLimitSigChecks,
392  std::vector<CScriptCheck> *pvChecks)
394 
398 static inline bool
400  const CCoinsViewCache &view, const uint32_t flags,
401  bool sigCacheStore, bool scriptCacheStore,
402  const PrecomputedTransactionData &txdata, int &nSigChecksOut)
404  TxSigCheckLimiter nSigChecksTxLimiter;
405  return CheckInputScripts(tx, state, view, flags, sigCacheStore,
406  scriptCacheStore, txdata, nSigChecksOut,
407  nSigChecksTxLimiter, nullptr, nullptr);
408 }
409 
413 void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
414  int nHeight);
415 
419 void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
420  int nHeight);
421 
440 std::optional<LockPoints> CalculateLockPointsAtTip(CBlockIndex *tip,
441  const CCoinsView &coins_view,
442  const CTransaction &tx);
443 
453 bool CheckSequenceLocksAtTip(CBlockIndex *tip, const LockPoints &lock_points);
454 
463 private:
466  unsigned int nIn;
467  uint32_t nFlags;
474 
475 public:
476  CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn,
477  unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn,
478  const PrecomputedTransactionData &txdataIn,
479  TxSigCheckLimiter *pTxLimitSigChecksIn = nullptr,
480  CheckInputsLimiter *pBlockLimitSigChecksIn = nullptr)
481  : m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn),
482  cacheStore(cacheIn), txdata(txdataIn),
483  pTxLimitSigChecks(pTxLimitSigChecksIn),
484  pBlockLimitSigChecks(pBlockLimitSigChecksIn) {}
485 
486  CScriptCheck(const CScriptCheck &) = delete;
487  CScriptCheck &operator=(const CScriptCheck &) = delete;
488  CScriptCheck(CScriptCheck &&) = default;
490 
491  bool operator()();
492 
493  ScriptError GetScriptError() const { return error; }
494 
496 };
497 
506 bool CheckBlock(const CBlock &block, BlockValidationState &state,
507  const Consensus::Params &params,
508  BlockValidationOptions validationOptions);
509 
517  const CBlockIndex &active_chain_tip, const Consensus::Params &params,
518  const CTransaction &tx, TxValidationState &state)
520 
526  BlockValidationState &state, const CChainParams &params,
527  Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev,
528  const std::function<NodeClock::time_point()> &adjusted_time_callback,
530 
534 bool HasValidProofOfWork(const std::vector<CBlockHeader> &headers,
535  const Consensus::Params &consensusParams);
536 
538 arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader> &headers);
539 
540 enum class VerifyDBResult {
541  SUCCESS,
543  INTERRUPTED,
546 };
547 
552 class CVerifyDB {
553 private:
555 
556 public:
558 
559 public:
560  explicit CVerifyDB(kernel::Notifications &notifications);
561  ~CVerifyDB();
562 
563  [[nodiscard]] VerifyDBResult VerifyDB(Chainstate &chainstate,
564  CCoinsView &coinsview,
565  int nCheckLevel, int nCheckDepth)
567 };
568 
571 
581 class CoinsViews {
582 public:
586 
590 
593  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
594 
603  CoinsViews(DBParams db_params, CoinsViewOptions options);
604 
606  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
607 };
608 
611  CRITICAL = 2,
613  LARGE = 1,
614  OK = 0
615 };
616 
631 class Chainstate {
632 protected:
638 
644  std::atomic<int32_t> nBlockSequenceId{1};
646  int32_t nBlockReverseSequenceId = -1;
648  arith_uint256 nLastPreciousChainwork = 0;
649 
656  mutable std::atomic<bool> m_cached_finished_ibd{false};
657 
661 
664  std::unique_ptr<CoinsViews> m_coins_views;
665 
678  bool m_disabled GUARDED_BY(::cs_main){false};
679 
681 
686  const CBlockIndex *m_avalancheFinalizedBlockIndex
687  GUARDED_BY(cs_avalancheFinalizedBlockIndex) = nullptr;
688 
695  CRollingBloomFilter m_filterParkingPoliciesApplied =
696  CRollingBloomFilter{1000, 0.000001};
697 
698  CBlockIndex const *m_best_fork_tip = nullptr;
699  CBlockIndex const *m_best_fork_base = nullptr;
700 
701 public:
705 
710 
711  explicit Chainstate(
712  CTxMemPool *mempool, node::BlockManager &blockman,
713  ChainstateManager &chainman,
714  std::optional<BlockHash> from_snapshot_blockhash = std::nullopt);
715 
722  void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe,
723  std::string leveldb_name = "chainstate");
724 
727  void InitCoinsCache(size_t cache_size_bytes)
729 
733  bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main) {
735  return m_coins_views && m_coins_views->m_cacheview;
736  }
737 
741 
748  const std::optional<BlockHash> m_from_snapshot_blockhash{};
749 
753  return m_from_snapshot_blockhash.has_value();
754  }
755 
763  std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates;
764 
768  Assert(m_coins_views);
769  return *Assert(m_coins_views->m_cacheview);
770  }
771 
775  return Assert(m_coins_views)->m_dbview;
776  }
777 
779  CTxMemPool *GetMempool() { return m_mempool; }
780 
786  return Assert(m_coins_views)->m_catcherview;
787  }
788 
790  void ResetCoinsViews() { m_coins_views.reset(); }
791 
793  bool HasCoinsViews() const { return (bool)m_coins_views; }
794 
796  size_t m_coinsdb_cache_size_bytes{0};
797 
799  size_t m_coinstip_cache_size_bytes{0};
800 
803  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
805 
837  void LoadExternalBlockFile(FILE *fileIn, FlatFilePos *dbp = nullptr,
838  std::multimap<BlockHash, FlatFilePos>
839  *blocks_with_unknown_parent = nullptr)
840  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
841  !cs_avalancheFinalizedBlockIndex);
842 
854  bool FlushStateToDisk(BlockValidationState &state, FlushStateMode mode,
855  int nManualPruneHeight = 0);
856 
858  void ForceFlushStateToDisk();
859 
862  void PruneAndFlush();
863 
890  bool ActivateBestChain(BlockValidationState &state,
891  std::shared_ptr<const CBlock> pblock = nullptr,
892  bool skip_checkblockindex = false)
893  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
894  !cs_avalancheFinalizedBlockIndex)
896 
897  bool AcceptBlock(const std::shared_ptr<const CBlock> &pblock,
898  BlockValidationState &state, bool fRequested,
899  const FlatFilePos *dbp, bool *fNewBlock,
900  bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
901 
902  // Block (dis)connection on a given view:
903  DisconnectResult DisconnectBlock(const CBlock &block,
904  const CBlockIndex *pindex,
905  CCoinsViewCache &view)
907  bool ConnectBlock(const CBlock &block, BlockValidationState &state,
908  CBlockIndex *pindex, CCoinsViewCache &view,
909  BlockValidationOptions options,
910  Amount *blockFees = nullptr, bool fJustCheck = false)
912 
913  // Apply the effects of a block disconnection on the UTXO set.
914  bool DisconnectTip(BlockValidationState &state,
915  DisconnectedBlockTransactions *disconnectpool)
917 
918  // Manual block validity manipulation:
924  bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex)
925  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
926  !cs_avalancheFinalizedBlockIndex)
929  bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex)
931  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
932  !cs_avalancheFinalizedBlockIndex);
934  bool ParkBlock(BlockValidationState &state, CBlockIndex *pindex)
936  EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
937  !cs_avalancheFinalizedBlockIndex);
938 
942  bool AvalancheFinalizeBlock(CBlockIndex *pindex)
943  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
944 
948  void ClearAvalancheFinalizedBlock()
949  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
950 
954  bool IsBlockAvalancheFinalized(const CBlockIndex *pindex) const
955  EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
956 
958  void ResetBlockFailureFlags(CBlockIndex *pindex)
960  template <typename F>
961  bool UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f)
963  template <typename F, typename C, typename AC>
964  void UpdateFlags(CBlockIndex *pindex, CBlockIndex *&pindexReset, F f,
965  C fChild, AC fAncestorWasChanged)
967 
969  void UnparkBlockAndChildren(CBlockIndex *pindex)
971 
973  void UnparkBlock(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
974 
976  bool ReplayBlocks();
977 
982  bool LoadGenesisBlock();
983 
984  void PruneBlockIndexCandidates();
985 
986  void UnloadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
987 
992  bool IsInitialBlockDownload() const;
993 
995  const CBlockIndex *FindForkInGlobalIndex(const CBlockLocator &locator) const
997 
1004  void CheckBlockIndex();
1005 
1007  void
1008  LoadMempool(const fs::path &load_path,
1009  fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
1010 
1013  bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1014 
1018  CoinsCacheSizeState GetCoinsCacheSizeState()
1020 
1022  GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes,
1023  size_t max_mempool_size_bytes)
1025 
1027 
1030  RecursiveMutex *MempoolMutex() const LOCK_RETURNED(m_mempool->cs) {
1031  return m_mempool ? &m_mempool->cs : nullptr;
1032  }
1033 
1034 private:
1035  bool ActivateBestChainStep(BlockValidationState &state,
1036  CBlockIndex *pindexMostWork,
1037  const std::shared_ptr<const CBlock> &pblock,
1038  bool &fInvalidFound, ConnectTrace &connectTrace)
1039  EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs,
1040  !cs_avalancheFinalizedBlockIndex);
1041  bool ConnectTip(BlockValidationState &state,
1042  BlockPolicyValidationState &blockPolicyState,
1043  CBlockIndex *pindexNew,
1044  const std::shared_ptr<const CBlock> &pblock,
1045  ConnectTrace &connectTrace,
1046  DisconnectedBlockTransactions &disconnectpool)
1047  EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs,
1048  !cs_avalancheFinalizedBlockIndex);
1049  void InvalidBlockFound(CBlockIndex *pindex,
1050  const BlockValidationState &state)
1051  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1052  CBlockIndex *
1053  FindMostWorkChain(std::vector<const CBlockIndex *> &blocksToReconcile)
1054  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1055  void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew,
1056  const FlatFilePos &pos)
1058 
1059  bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs)
1061 
1062  void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren)
1064 
1065  bool UnwindBlock(BlockValidationState &state, CBlockIndex *pindex,
1066  bool invalidate)
1067  EXCLUSIVE_LOCKS_REQUIRED(m_chainstate_mutex,
1068  !cs_avalancheFinalizedBlockIndex);
1069 
1070  void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1071  void CheckForkWarningConditionsOnNewFork(CBlockIndex *pindexNewForkTip)
1073  void InvalidChainFound(CBlockIndex *pindexNew)
1074  EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1075 
1076  const CBlockIndex *FindBlockToFinalize(CBlockIndex *pindexNew)
1078 
1082  void UpdateTip(const CBlockIndex *pindexNew)
1084 
1085  std::chrono::microseconds m_last_write{0};
1086  std::chrono::microseconds m_last_flush{0};
1087 
1092  [[nodiscard]] util::Result<void> InvalidateCoinsDBOnDisk()
1094 
1096 };
1097 
1099  SUCCESS,
1100  SKIPPED,
1101 
1102  // Expected assumeutxo configuration data is not found for the height of the
1103  // base block.
1105 
1106  // Failed to generate UTXO statistics (to check UTXO set hash) for the
1107  // background chainstate.
1108  STATS_FAILED,
1109 
1110  // The UTXO set hash of the background validation chainstate does not match
1111  // the one expected by assumeutxo chainparams.
1112  HASH_MISMATCH,
1113 
1114  // The blockhash of the current tip of the background validation chainstate
1115  // does not match the one expected by the snapshot chainstate.
1117 };
1118 
1147 private:
1163  std::unique_ptr<Chainstate> m_ibd_chainstate GUARDED_BY(::cs_main);
1164 
1174  std::unique_ptr<Chainstate> m_snapshot_chainstate GUARDED_BY(::cs_main);
1175 
1185  Chainstate *m_active_chainstate GUARDED_BY(::cs_main){nullptr};
1186 
1187  CBlockIndex *m_best_invalid GUARDED_BY(::cs_main){nullptr};
1188  CBlockIndex *m_best_parked GUARDED_BY(::cs_main){nullptr};
1189 
1191  [[nodiscard]] bool
1192  PopulateAndValidateSnapshot(Chainstate &snapshot_chainstate,
1193  AutoFile &coins_file,
1194  const node::SnapshotMetadata &metadata);
1203  bool AcceptBlockHeader(
1204  const CBlockHeader &block, BlockValidationState &state,
1205  CBlockIndex **ppindex, bool min_pow_checked,
1206  const std::optional<CCheckpointData> &test_checkpoints = std::nullopt)
1208  friend Chainstate;
1209 
1211  const CBlockIndex *GetSnapshotBaseBlock() const
1213 
1216  std::optional<int> GetSnapshotBaseHeight() const
1218 
1224  bool IsUsable(const Chainstate *const pchainstate) const
1226  return pchainstate && !pchainstate->m_disabled;
1227  }
1228 
1230  SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main){};
1231 
1232 public:
1234 
1235  explicit ChainstateManager(Options options,
1236  node::BlockManager::Options blockman_options);
1237 
1238  const Config &GetConfig() const { return m_options.config; }
1239 
1240  const CChainParams &GetParams() const {
1241  return m_options.config.GetChainParams();
1242  }
1244  return m_options.config.GetChainParams().GetConsensus();
1245  }
1246  bool ShouldCheckBlockIndex() const {
1247  return *Assert(m_options.check_block_index);
1248  }
1250  return *Assert(m_options.minimum_chain_work);
1251  }
1252  const BlockHash &AssumedValidBlock() const {
1253  return *Assert(m_options.assumed_valid_block);
1254  }
1256  return m_options.notifications;
1257  };
1258 
1272  }
1273 
1275  std::thread m_load_block;
1279 
1299  std::set<CBlockIndex *> m_failed_blocks;
1300 
1305  CBlockIndex *m_best_header GUARDED_BY(::cs_main){nullptr};
1306 
1309  int64_t m_total_coinstip_cache{0};
1310  //
1313  int64_t m_total_coinsdb_cache{0};
1314 
1318  // constructor
1319  Chainstate &InitializeChainstate(CTxMemPool *mempool)
1321 
1323  std::vector<Chainstate *> GetAll();
1324 
1338  [[nodiscard]] bool ActivateSnapshot(AutoFile &coins_file,
1339  const node::SnapshotMetadata &metadata,
1340  bool in_memory);
1341 
1349  SnapshotCompletionResult MaybeCompleteSnapshotValidation(
1350  std::function<void(bilingual_str)> shutdown_fnc =
1351  [](bilingual_str msg) { AbortNode(msg.original, msg); })
1353 
1355  Chainstate &ActiveChainstate() const;
1357  return ActiveChainstate().m_chain;
1358  }
1359  int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
1360  return ActiveChain().Height();
1361  }
1363  return ActiveChain().Tip();
1364  }
1365 
1368  return m_blockman.m_block_index;
1369  }
1370 
1373  bool IsSnapshotActive() const;
1374 
1375  std::optional<BlockHash> SnapshotBlockhash() const;
1376 
1379  return m_snapshot_chainstate && m_ibd_chainstate &&
1380  m_ibd_chainstate->m_disabled;
1381  }
1382 
1410  bool ProcessNewBlock(const std::shared_ptr<const CBlock> &block,
1411  bool force_processing, bool min_pow_checked,
1412  bool *new_block) LOCKS_EXCLUDED(cs_main);
1413 
1429  bool ProcessNewBlockHeaders(
1430  const std::vector<CBlockHeader> &block, bool min_pow_checked,
1431  BlockValidationState &state, const CBlockIndex **ppindex = nullptr,
1432  const std::optional<CCheckpointData> &test_checkpoints = std::nullopt)
1434 
1443  [[nodiscard]] MempoolAcceptResult
1444  ProcessTransaction(const CTransactionRef &tx, bool test_accept = false)
1446 
1449  bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1450 
1453  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1454 
1461  void ReportHeadersPresync(const arith_uint256 &work, int64_t height,
1462  int64_t timestamp);
1463 
1466  bool DetectSnapshotChainstate(CTxMemPool *mempool)
1468 
1469  void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1470 
1473  Chainstate &ActivateExistingSnapshot(CTxMemPool *mempool,
1474  BlockHash base_blockhash)
1476 
1486  bool ValidatedSnapshotCleanup() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1487 };
1488 
1490 template <typename DEP>
1491 bool DeploymentActiveAfter(const CBlockIndex *pindexPrev,
1492  const ChainstateManager &chainman, DEP dep) {
1493  return DeploymentActiveAfter(pindexPrev, chainman.GetConsensus(), dep);
1494 }
1495 
1496 template <typename DEP>
1498  const ChainstateManager &chainman, DEP dep) {
1499  return DeploymentActiveAt(index, chainman.GetConsensus(), dep);
1500 }
1501 
1509 const AssumeutxoData *ExpectedAssumeutxo(const int height,
1510  const CChainParams &params);
1511 
1512 #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:154
BlockValidationOptions withCheckPoW(bool _checkPoW=true) const
Definition: validation.h:139
BlockValidationOptions(uint64_t _excessiveBlockSize, bool _checkPow=true, bool _checkMerkleRoot=true)
Definition: validation.h:133
BlockValidationOptions withCheckMerkleRoot(bool _checkMerkleRoot=true) const
Definition: validation.h:146
BlockValidationOptions(const Config &config)
Definition: validation.cpp:117
bool shouldValidatePoW() const
Definition: validation.h:152
uint64_t excessiveBlockSize
Definition: validation.h:126
bool shouldValidateMerkleRoot() const
Definition: validation.h:153
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
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:115
Closure representing one script verification.
Definition: validation.h:462
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:476
ScriptError GetScriptError() const
Definition: validation.h:493
ScriptExecutionMetrics GetScriptExecutionMetrics() const
Definition: validation.h:495
CScriptCheck(const CScriptCheck &)=delete
uint32_t nFlags
Definition: validation.h:467
TxSigCheckLimiter * pTxLimitSigChecks
Definition: validation.h:472
ScriptExecutionMetrics metrics
Definition: validation.h:470
CTxOut m_tx_out
Definition: validation.h:464
CScriptCheck(CScriptCheck &&)=default
bool cacheStore
Definition: validation.h:468
ScriptError error
Definition: validation.h:469
CScriptCheck & operator=(const CScriptCheck &)=delete
PrecomputedTransactionData txdata
Definition: validation.h:471
const CTransaction * ptxTo
Definition: validation.h:465
unsigned int nIn
Definition: validation.h:466
CheckInputsLimiter * pBlockLimitSigChecks
Definition: validation.h:473
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:552
VerifyDBResult VerifyDB(Chainstate &chainstate, CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
kernel::Notifications & m_notifications
Definition: validation.h:554
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:631
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries with either BLOCK_VALID_TRANSACTIONS (for itself and all ancestors...
Definition: validation.h:763
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:783
CTxMemPool * GetMempool()
Definition: validation.h:779
Mutex m_chainstate_mutex
The ChainState Mutex.
Definition: validation.h:637
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:740
bool HasCoinsViews() const
Does this chainstate have a UTXO set attached?
Definition: validation.h:793
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:773
Mutex cs_avalancheFinalizedBlockIndex
Definition: validation.h:678
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:660
bool reliesOnAssumedValid()
Return true if this chainstate relies on blocks that are assumed-valid.
Definition: validation.h:752
bool m_disabled GUARDED_BY(::cs_main)
This toggle exists for use when doing background validation for UTXO snapshots.
Definition: validation.h:678
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:709
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:664
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:790
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:766
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Definition: validation.h:704
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:1146
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1356
std::unique_ptr< Chainstate > m_ibd_chainstate GUARDED_BY(::cs_main)
The chainstate used under normal operation (i.e.
Chainstate *m_active_chainstate GUARDED_BY(::cs_main)
Points to either the ibd or snapshot chainstate; indicates our most-work chain.
Definition: validation.h:1185
CBlockIndex *m_best_parked GUARDED_BY(::cs_main)
Definition: validation.h:1188
const CChainParams & GetParams() const
Definition: validation.h:1240
const arith_uint256 & MinimumChainWork() const
Definition: validation.h:1249
SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main)
Most recent headers presync progress update, for rate-limiting.
Definition: validation.h:1230
bool ShouldCheckBlockIndex() const
Definition: validation.h:1246
const Config & GetConfig() const
Definition: validation.h:1238
const BlockHash & AssumedValidBlock() const
Definition: validation.h:1252
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1366
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1378
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1270
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1359
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1362
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Definition: validation.h:1187
const Options m_options
Definition: validation.h:1274
CBlockIndex *m_best_header GUARDED_BY(::cs_main)
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.h:1305
std::thread m_load_block
Definition: validation.h:1275
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
Definition: validation.h:1323
std::set< CBlockIndex * > m_failed_blocks
In order to efficiently track invalidity of headers, we keep the set of blocks which we tried to conn...
Definition: validation.h:1299
std::unique_ptr< Chainstate > m_snapshot_chainstate GUARDED_BY(::cs_main)
A chainstate initialized on the basis of a UTXO snapshot.
kernel::Notifications & GetNotifications() const
Definition: validation.h:1255
const Consensus::Params & GetConsensus() const
Definition: validation.h:1243
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1278
Simple class for regulating resource usage during CheckInputScripts (and CScriptCheck),...
Definition: validation.h:318
bool consume_and_check(int consumed)
Definition: validation.h:325
std::atomic< int64_t > remaining
Definition: validation.h:320
CheckInputsLimiter(int64_t limit)
Definition: validation.h:323
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:581
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:346
TxSigCheckLimiter & operator=(const TxSigCheckLimiter &rhs)
Definition: validation.h:341
TxSigCheckLimiter(const TxSigCheckLimiter &rhs)
Definition: validation.h:338
bool IsValid() const
Definition: validation.h:112
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:71
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:21
256-bit opaque blob.
Definition: uint256.h:129
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:57
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:257
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:38
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
@ PERIODIC
Called by RandAddPeriodic()
ScriptError
Definition: script_error.h:11
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:87
Definition: amount.h:19
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h: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 single transaction mempool acceptance.
Definition: validation.h:186
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigchecks.
Definition: validation.h:205
const ResultType m_result_type
Definition: validation.h:196
static MempoolAcceptResult Success(int64_t vsize, Amount fees)
Constructor for success case.
Definition: validation.h:213
MempoolAcceptResult(ResultType result_type, int64_t vsize, Amount fees)
Generic constructor for success cases.
Definition: validation.h:237
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:229
const TxValidationState m_state
Definition: validation.h:197
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:188
@ MEMPOOL_ENTRY
Valid, transaction was already in the mempool.
@ VALID
Fully validated, valid.
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:208
static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees)
Constructor for already-in-mempool case.
Definition: validation.h:221
const std::optional< Amount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:207
std::chrono::time_point< NodeClock > time_point
Definition: time.h:19
Validation result for package mempool acceptance.
Definition: validation.h:245
PackageMempoolAcceptResult(const TxId &txid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a MempoolAcceptResult.
Definition: validation.h:265
std::map< const TxId, const MempoolAcceptResult > m_tx_results
Map from txid to finished MempoolAcceptResults.
Definition: validation.h:254
PackageMempoolAcceptResult(PackageValidationState state, std::map< const TxId, const MempoolAcceptResult > &&results)
Definition: validation.h:256
const PackageValidationState m_state
Definition: validation.h:246
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:97
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &txns, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Validate (and maybe submit) a package to the mempool.
arith_uint256 CalculateHeadersWork(const std::vector< CBlockHeader > &headers)
Return the sum of the work on a given set of headers.
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev?...
Definition: validation.h:111
bool 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:95
bool HasValidProofOfWork(const std::vector< CBlockHeader > &headers, const Consensus::Params &consensusParams)
Check with the proof of work on each blockheader matches the value in nBits.
bool DeploymentActiveAfter(const CBlockIndex *pindexPrev, const ChainstateManager &chainman, DEP dep)
Deployment* info via ChainstateManager.
Definition: validation.h:1491
SnapshotCompletionResult
Definition: validation.h:1098
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:83
const AssumeutxoData * ExpectedAssumeutxo(const int height, const CChainParams &params)
Return the expected assumeutxo value for a given height, if one exists.
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:114
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:85
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:540
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:525
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
CoinsCacheSizeState
Definition: validation.h:609
@ 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:1497
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:96
FlushStateMode
Definition: validation.h:570
uint256 g_best_block
Used to notify getblocktemplate RPC of new tips.
Definition: validation.cpp:115
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:87
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:90