Bitcoin Core  22.99.0
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2021 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 #if defined(HAVE_CONFIG_H)
10 #include <config/bitcoin-config.h>
11 #endif
12 
13 #include <arith_uint256.h>
14 #include <attributes.h>
15 #include <chain.h>
16 #include <consensus/amount.h>
17 #include <fs.h>
18 #include <node/blockstorage.h>
19 #include <policy/feerate.h>
20 #include <policy/packages.h>
21 #include <script/script_error.h>
22 #include <sync.h>
23 #include <txdb.h>
24 #include <txmempool.h> // For CTxMemPool::cs
25 #include <uint256.h>
26 #include <util/check.h>
27 #include <util/hasher.h>
28 #include <util/translation.h>
29 
30 #include <atomic>
31 #include <map>
32 #include <memory>
33 #include <optional>
34 #include <set>
35 #include <stdint.h>
36 #include <string>
37 #include <thread>
38 #include <utility>
39 #include <vector>
40 
41 class CChainState;
42 class CBlockTreeDB;
43 class CChainParams;
44 class CTxMemPool;
45 class ChainstateManager;
46 struct ChainTxData;
49 struct LockPoints;
50 struct AssumeutxoData;
51 namespace node {
52 class SnapshotMetadata;
53 } // namespace node
54 
56 static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
58 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
60 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
62 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
64 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
65 
66 // If a package is submitted, it must be within the mempool's ancestor/descendant limits. Since a
67 // submitted package must be child-with-unconfirmed-parents (all of the transactions are an ancestor
68 // of the child), package limits are ultimately bounded by mempool package limits. Ensure that the
69 // defaults reflect this constraint.
74 
76 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
78 static const int MAX_SCRIPTCHECK_THREADS = 15;
80 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
81 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
82 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
83 static const bool DEFAULT_TXINDEX = false;
84 static constexpr bool DEFAULT_COINSTATSINDEX{false};
85 static const char* const DEFAULT_BLOCKFILTERINDEX = "0";
87 static const bool DEFAULT_PERSIST_MEMPOOL = true;
89 static const int DEFAULT_STOPATHEIGHT = 0;
91 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
92 static const signed int DEFAULT_CHECKBLOCKS = 6;
93 static const unsigned int DEFAULT_CHECKLEVEL = 3;
94 // Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat)
95 // At 1MB per block, 288 blocks = 288MB.
96 // Add 15% for Undo data = 331MB
97 // Add 20% for Orphan block rate = 397MB
98 // We want the low water mark after pruning to be at least 397 MB and since we prune in
99 // full block file chunks, we need the high water mark which triggers the prune to be
100 // one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
101 // Setting the target to >= 550 MiB will make it likely we can respect the target.
102 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
103 
106  INIT_REINDEX,
108  POST_INIT
109 };
110 
111 extern RecursiveMutex cs_main;
113 extern std::condition_variable g_best_block_cv;
115 extern uint256 g_best_block;
119 extern bool g_parallel_script_checks;
120 extern bool fRequireStandard;
121 extern bool fCheckBlockIndex;
122 extern bool fCheckpointsEnabled;
124 extern CFeeRate minRelayTxFee;
126 extern int64_t nMaxTipAge;
127 
129 extern uint256 hashAssumeValid;
130 
133 
136 
138 extern const std::vector<std::string> CHECKLEVEL_DOC;
139 
141 void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman);
143 void StartScriptCheckWorkerThreads(int threads_num);
146 
147 CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
148 
149 bool AbortNode(BlockValidationState& state, const std::string& strMessage, const bilingual_str& userMessage = bilingual_str{});
150 
152 double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex* pindex);
153 
155 void PruneBlockFilesManual(CChainState& active_chainstate, int nManualPruneHeight);
156 
162  enum class ResultType {
163  VALID,
164  INVALID,
165  MEMPOOL_ENTRY,
166  };
169 
170  // The following fields are only present when m_result_type = ResultType::VALID or MEMPOOL_ENTRY
172  const std::optional<std::list<CTransactionRef>> m_replaced_transactions;
174  const std::optional<int64_t> m_vsize;
176  const std::optional<CAmount> m_base_fees;
177 
179  return MempoolAcceptResult(state);
180  }
181 
182  static MempoolAcceptResult Success(std::list<CTransactionRef>&& replaced_txns, int64_t vsize, CAmount fees) {
183  return MempoolAcceptResult(std::move(replaced_txns), vsize, fees);
184  }
185 
186  static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees) {
187  return MempoolAcceptResult(vsize, fees);
188  }
189 
190 // Private constructors. Use static methods MempoolAcceptResult::Success, etc. to construct.
191 private:
194  : m_result_type(ResultType::INVALID), m_state(state) {
195  Assume(!state.IsValid()); // Can be invalid or error
196  }
197 
199  explicit MempoolAcceptResult(std::list<CTransactionRef>&& replaced_txns, int64_t vsize, CAmount fees)
200  : m_result_type(ResultType::VALID),
201  m_replaced_transactions(std::move(replaced_txns)), m_vsize{vsize}, m_base_fees(fees) {}
202 
204  explicit MempoolAcceptResult(int64_t vsize, CAmount fees)
205  : m_result_type(ResultType::MEMPOOL_ENTRY), m_vsize{vsize}, m_base_fees(fees) {}
206 };
207 
212 {
220  std::map<const uint256, const MempoolAcceptResult> m_tx_results;
221 
223  std::map<const uint256, const MempoolAcceptResult>&& results)
224  : m_state{state}, m_tx_results(std::move(results)) {}
225 
227  explicit PackageMempoolAcceptResult(const uint256& wtxid, const MempoolAcceptResult& result)
228  : m_tx_results{ {wtxid, result} } {}
229 };
230 
245  int64_t accept_time, bool bypass_limits, bool test_accept)
247 
257  const Package& txns, bool test_accept)
259 
269 bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags = -1) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
270 
291  const CCoinsView& coins_view,
292  const CTransaction& tx,
293  int flags,
294  LockPoints* lp = nullptr,
295  bool useExistingLockPoints = false);
296 
302 {
303 private:
306  unsigned int nIn;
307  unsigned int nFlags;
311 
312 public:
313  CScriptCheck(): ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
314  CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
315  m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
316 
317  bool operator()();
318 
319  void swap(CScriptCheck &check) {
320  std::swap(ptxTo, check.ptxTo);
321  std::swap(m_tx_out, check.m_tx_out);
322  std::swap(nIn, check.nIn);
323  std::swap(nFlags, check.nFlags);
324  std::swap(cacheStore, check.cacheStore);
325  std::swap(error, check.error);
326  std::swap(txdata, check.txdata);
327  }
328 
329  ScriptError GetScriptError() const { return error; }
330 };
331 
334 
338 bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
339 
342  const CChainParams& chainparams,
343  CChainState& chainstate,
344  const CBlock& block,
345  CBlockIndex* pindexPrev,
346  bool fCheckPOW = true,
347  bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
348 
350 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
351 
353 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
354 
356 class CVerifyDB {
357 public:
358  CVerifyDB();
359  ~CVerifyDB();
360  bool VerifyDB(
361  CChainState& chainstate,
362  const Consensus::Params& consensus_params,
363  CCoinsView& coinsview,
364  int nCheckLevel,
365  int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
366 };
367 
369 {
370  DISCONNECT_OK, // All good.
371  DISCONNECT_UNCLEAN, // Rolled back, but UTXO set was inconsistent with block.
372  DISCONNECT_FAILED // Something else went wrong.
373 };
374 
375 class ConnectTrace;
376 
378 enum class FlushStateMode {
379  NONE,
380  IF_NEEDED,
381  PERIODIC,
382  ALWAYS
383 };
384 
394 class CoinsViews {
395 
396 public:
399  CCoinsViewDB m_dbview GUARDED_BY(cs_main);
400 
403 
406  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
407 
414  CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory, bool should_wipe);
415 
417  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
418 };
419 
421 {
423  CRITICAL = 2,
425  LARGE = 1,
426  OK = 0
427 };
428 
444 {
445 protected:
451  int32_t nBlockSequenceId GUARDED_BY(::cs_main) = 1;
456 
462 
469  mutable std::atomic<bool> m_cached_finished_ibd{false};
470 
474 
476  std::unique_ptr<CoinsViews> m_coins_views;
477 
478 public:
482 
485 
490 
491  explicit CChainState(
492  CTxMemPool* mempool,
493  node::BlockManager& blockman,
494  ChainstateManager& chainman,
495  std::optional<uint256> from_snapshot_blockhash = std::nullopt);
496 
503  void InitCoinsDB(
504  size_t cache_size_bytes,
505  bool in_memory,
506  bool should_wipe,
507  std::string leveldb_name = "chainstate");
508 
511  void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
512 
515  bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
516  return m_coins_views && m_coins_views->m_cacheview;
517  }
518 
522 
528  const std::optional<uint256> m_from_snapshot_blockhash;
529 
532  bool reliesOnAssumedValid() { return m_from_snapshot_blockhash.has_value(); }
533 
540  std::set<CBlockIndex*, node::CBlockIndexWorkComparator> setBlockIndexCandidates;
541 
544  {
545  assert(m_coins_views->m_cacheview);
546  return *m_coins_views->m_cacheview.get();
547  }
548 
551  {
552  return m_coins_views->m_dbview;
553  }
554 
557  {
558  return m_mempool;
559  }
560 
564  {
565  return m_coins_views->m_catcherview;
566  }
567 
569  void ResetCoinsViews() { m_coins_views.reset(); }
570 
573 
576 
579  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
581 
583  void LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp = nullptr);
584 
596  bool FlushStateToDisk(
597  BlockValidationState& state,
598  FlushStateMode mode,
599  int nManualPruneHeight = 0);
600 
602  void ForceFlushStateToDisk();
603 
606  void PruneAndFlush();
607 
623  bool ActivateBestChain(
624  BlockValidationState& state,
625  std::shared_ptr<const CBlock> pblock = nullptr) LOCKS_EXCLUDED(cs_main);
626 
627  bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
628 
629  // Block (dis)connection on a given view:
630  DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view)
632  bool ConnectBlock(const CBlock& block, BlockValidationState& state, CBlockIndex* pindex,
633  CCoinsViewCache& view, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
634 
635  // Apply the effects of a block disconnection on the UTXO set.
637 
638  // Manual block validity manipulation:
648 
650  bool ReplayBlocks();
651 
653  [[nodiscard]] bool NeedsRedownload() const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
655  bool LoadGenesisBlock();
656 
658 
660 
662  bool IsInitialBlockDownload() const;
663 
666 
672  void CheckBlockIndex();
673 
675  void LoadMempool(const ArgsManager& args);
676 
679 
683  CoinsCacheSizeState GetCoinsCacheSizeState() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
684 
685  CoinsCacheSizeState GetCoinsCacheSizeState(
686  size_t max_coins_cache_size_bytes,
687  size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
688 
690 
691 private:
692  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);
693  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);
694 
697  void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
698 
700 
703 
706  {
707  return m_mempool ? &m_mempool->cs : nullptr;
708  }
709 
724  DisconnectedBlockTransactions& disconnectpool,
726 
728  void UpdateTip(const CBlockIndex* pindexNew)
730 
731  friend ChainstateManager;
732 };
733 
762 {
763 private:
779  std::unique_ptr<CChainState> m_ibd_chainstate GUARDED_BY(::cs_main);
780 
790  std::unique_ptr<CChainState> m_snapshot_chainstate GUARDED_BY(::cs_main);
791 
801  CChainState* m_active_chainstate GUARDED_BY(::cs_main) {nullptr};
802 
805  bool m_snapshot_validated{false};
806 
809 
811  [[nodiscard]] bool PopulateAndValidateSnapshot(
812  CChainState& snapshot_chainstate,
813  CAutoFile& coins_file,
814  const node::SnapshotMetadata& metadata);
815 
820  bool AcceptBlockHeader(
821  const CBlockHeader& block,
822  BlockValidationState& state,
823  const CChainParams& chainparams,
825  friend CChainState;
826 
827 public:
828  std::thread m_load_block;
832 
852  std::set<CBlockIndex*> m_failed_blocks;
853 
857  //
861 
866  // constructor
869  CChainState& InitializeChainstate(
870  CTxMemPool* mempool,
871  const std::optional<uint256>& snapshot_blockhash = std::nullopt)
873 
875  std::vector<CChainState*> GetAll();
876 
890  [[nodiscard]] bool ActivateSnapshot(
891  CAutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory);
892 
894  CChainState& ActiveChainstate() const;
896  int ActiveHeight() const { return ActiveChain().Height(); }
897  CBlockIndex* ActiveTip() const { return ActiveChain().Tip(); }
898 
900  {
901  return m_blockman.m_block_index;
902  }
903 
906  bool IsSnapshotActive() const;
907 
908  std::optional<uint256> SnapshotBlockhash() const;
909 
911  bool IsSnapshotValidated() const { return m_snapshot_validated; }
912 
932  bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock>& block, bool force_processing, bool* new_block) LOCKS_EXCLUDED(cs_main);
933 
945  bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
946 
953  [[nodiscard]] MempoolAcceptResult ProcessTransaction(const CTransactionRef& tx, bool test_accept=false)
955 
958 
960  void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
961 
963  void Reset();
964 
967  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
968 
970  LOCK(::cs_main);
971  UnloadBlockIndex(/* mempool */ nullptr, *this);
972  Reset();
973  }
974 };
975 
976 using FopenFn = std::function<FILE*(const fs::path&, const char*)>;
977 
979 bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function = fsbridge::fopen, bool skip_file_commit = false);
980 
982 bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mockable_fopen_function = fsbridge::fopen);
983 
991 const AssumeutxoData* ExpectedAssumeutxo(const int height, const CChainParams& params);
992 
993 #endif // BITCOIN_VALIDATION_H
CChainState::FindForkInGlobalIndex
CBlockIndex * FindForkInGlobalIndex(const CBlockLocator &locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Find the last common block of this chain and a locator.
Definition: validation.cpp:155
MempoolAcceptResult::MempoolAcceptResult
MempoolAcceptResult(int64_t vsize, CAmount fees)
Constructor for already-in-mempool case.
Definition: validation.h:204
MempoolAcceptResult::m_replaced_transactions
const std::optional< std::list< CTransactionRef > > m_replaced_transactions
Mempool transactions replaced by the tx per BIP 125 rules.
Definition: validation.h:172
arith_uint256.h
CChainState::FindMostWorkChain
CBlockIndex * FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Return the tip of the chain with the most work in it, that isn't known to be invalid (it's however fa...
Definition: validation.cpp:2631
feerate.h
ChainstateManager::AcceptBlockHeader
bool AcceptBlockHeader(const CBlockHeader &block, BlockValidationState &state, const CChainParams &chainparams, CBlockIndex **ppindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
If a block header hasn't already been seen, call CheckBlockHeader on it, ensure that it doesn't desce...
Definition: validation.cpp:3436
CCoinsViewDB
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:49
ExpectedAssumeutxo
const AssumeutxoData * ExpectedAssumeutxo(const int height, const CChainParams &params)
Return the expected assumeutxo value for a given height, if one exists.
Definition: validation.cpp:4658
ChainstateManager::m_failed_blocks
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:852
CChainState::RollforwardBlock
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.
Definition: validation.cpp:3890
ToString
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:87
FlushStateMode::ALWAYS
@ ALWAYS
DEFAULT_CHECKLEVEL
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:93
fCheckBlockIndex
bool fCheckBlockIndex
Definition: validation.cpp:146
CChainState::reliesOnAssumedValid
bool reliesOnAssumedValid()
Return true if this chainstate relies on blocks that are assumed-valid.
Definition: validation.h:532
assert
assert(!tx.IsCoinBase())
ChainstateManager::ProcessNewBlockHeaders
bool ProcessNewBlockHeaders(const std::vector< CBlockHeader > &block, BlockValidationState &state, const CChainParams &chainparams, const CBlockIndex **ppindex=nullptr) LOCKS_EXCLUDED(cs_main)
Process incoming block headers.
Definition: validation.cpp:3525
MempoolAcceptResult::MempoolAcceptResult
MempoolAcceptResult(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees)
Constructor for success case.
Definition: validation.h:199
DISCONNECT_FAILED
@ DISCONNECT_FAILED
Definition: validation.h:372
CChainState::MempoolMutex
RecursiveMutex * MempoolMutex() const LOCK_RETURNED(m_mempool -> cs)
Indirection necessary to make lock annotations work with an optional mempool.
Definition: validation.h:705
CChainState::ForceFlushStateToDisk
void ForceFlushStateToDisk()
Unconditionally flush all changes to disk.
Definition: validation.cpp:2351
DEFAULT_PERSIST_MEMPOOL
static const bool DEFAULT_PERSIST_MEMPOOL
Default for -persistmempool.
Definition: validation.h:87
check.h
g_parallel_script_checks
bool g_parallel_script_checks
Whether there are dedicated script-checking threads running.
Definition: validation.cpp:144
hashAssumeValid
uint256 hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:150
ChainstateManager::m_total_coinstip_cache
int64_t m_total_coinstip_cache
The total number of bytes available for us to use across all in-memory coins caches.
Definition: validation.h:856
CoinsCacheSizeState::OK
@ OK
fs.h
nHeight
unsigned int nHeight
Definition: mempool_eviction.cpp:14
MempoolAcceptResult::m_state
const TxValidationState m_state
Definition: validation.h:168
node::SnapshotMetadata
Metadata describing a serialized version of a UTXO set from which an assumeutxo CChainState can be co...
Definition: utxo_snapshot.h:15
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:20
DEFAULT_ANCESTOR_SIZE_LIMIT
static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT
Default for -limitancestorsize, maximum kilobytes of tx + all in-mempool ancestors.
Definition: validation.h:60
BlockValidationState
Definition: validation.h:141
fsbridge::fopen
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:25
flags
int flags
Definition: bitcoin-tx.cpp:525
ChainstateManager::ProcessTransaction
MempoolAcceptResult ProcessTransaction(const CTransactionRef &tx, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the memory pool.
Definition: validation.cpp:3677
FlushStateMode::NONE
@ NONE
CChainState::PreciousBlock
bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
Mark a block as precious and reorganize.
Definition: validation.cpp:2927
CoinsCacheSizeState::CRITICAL
@ CRITICAL
The coins cache is in immediate need of a flush.
AssumeutxoData
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:40
sync.h
MempoolAcceptResult::m_result_type
const ResultType m_result_type
Definition: validation.h:167
PackageMempoolAcceptResult::m_tx_results
std::map< const uint256, const MempoolAcceptResult > m_tx_results
Map from (w)txid to finished MempoolAcceptResults.
Definition: validation.h:220
nMaxTipAge
int64_t nMaxTipAge
If the tip is older than this (in seconds), the node is considered to be in initial block download.
Definition: validation.cpp:148
bilingual_str
Bilingual messages:
Definition: translation.h:16
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:429
MAX_SCRIPTCHECK_THREADS
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:78
uint256.h
arith_uint256
256-bit unsigned big integer.
Definition: arith_uint256.h:250
CChainState::CheckBlockIndex
void CheckBlockIndex()
Make various assertions about the state of the block index.
Definition: validation.cpp:4183
CScriptCheck::ptxTo
const CTransaction * ptxTo
Definition: validation.h:305
CHECKLEVEL_DOC
const std::vector< std::string > CHECKLEVEL_DOC
Documentation for argument 'checklevel'.
Definition: validation.cpp:101
g_best_block_mutex
Mutex g_best_block_mutex
Definition: validation.cpp:141
DEFAULT_MEMPOOL_EXPIRY
static const unsigned int DEFAULT_MEMPOOL_EXPIRY
Default for -mempoolexpiry, expiration time for mempool transactions in hours.
Definition: validation.h:76
CChainState::PruneBlockIndexCandidates
void PruneBlockIndexCandidates()
Delete all entries in setBlockIndexCandidates that are worse than the current tip.
Definition: validation.cpp:2688
CoinsCacheSizeState::LARGE
@ LARGE
The cache is at >= 90% capacity.
DEFAULT_STOPATHEIGHT
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:89
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:69
ChainstateManager::m_snapshot_validated
bool m_snapshot_validated
If true, the assumed-valid chainstate has been fully validated by the background validation chainstat...
Definition: validation.h:805
fCheckpointsEnabled
bool fCheckpointsEnabled
Definition: validation.cpp:147
ChainstateManager::BlockIndex
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:899
AnnotatedMixin< std::recursive_mutex >
CChainState::InvalidBlockFound
void InvalidBlockFound(CBlockIndex *pindex, const BlockValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1526
FlushStateMode
FlushStateMode
Definition: validation.h:378
MIN_BLOCKS_TO_KEEP
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:91
bitcoin-config.h
CChainState::setBlockIndexCandidates
std::set< CBlockIndex *, node::CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries with either BLOCK_VALID_TRANSACTIONS (for itself and all ancestors...
Definition: validation.h:540
ChainstateManager::ActiveChainstate
CChainState & ActiveChainstate() const
The most-work chain.
Definition: validation.cpp:4960
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
GetBlockSubsidy
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
Definition: validation.cpp:1380
CChainState::ActivateBestChain
bool ActivateBestChain(BlockValidationState &state, std::shared_ptr< const CBlock > pblock=nullptr) LOCKS_EXCLUDED(cs_main)
Find the best known block, and make it the tip of the block chain.
Definition: validation.cpp:2827
MempoolAcceptResult::Success
static MempoolAcceptResult Success(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees)
Definition: validation.h:182
InitScriptExecutionCache
void InitScriptExecutionCache()
Initializes the script-execution cache.
Definition: validation.cpp:1561
CChainState::m_cs_chainstate
RecursiveMutex m_cs_chainstate
the ChainState CriticalSection A lock that must be held when modifying this ChainState - held in Acti...
Definition: validation.h:461
DEFAULT_DESCENDANT_LIMIT
static const unsigned int DEFAULT_DESCENDANT_LIMIT
Default for -limitdescendantcount, max number of in-mempool descendants.
Definition: validation.h:62
CChain::Tip
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:434
ChainstateManager::PopulateAndValidateSnapshot
bool PopulateAndValidateSnapshot(CChainState &snapshot_chainstate, CAutoFile &coins_file, const node::SnapshotMetadata &metadata)
Internal helper for ActivateSnapshot().
Definition: validation.cpp:4764
CFeeRate
Fee rate in satoshis per kilobyte: CAmount / kB.
Definition: feerate.h:29
CChainState::m_cached_finished_ibd
std::atomic< bool > m_cached_finished_ibd
Whether this chainstate is undergoing initial block download.
Definition: validation.h:469
CChainState::DisconnectTip
bool DisconnectTip(BlockValidationState &state, DisconnectedBlockTransactions *disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Disconnect m_chain's tip.
Definition: validation.cpp:2461
CChainState::ActivateBestChainStep
bool ActivateBestChainStep(BlockValidationState &state, CBlockIndex *pindexMostWork, const std::shared_ptr< const CBlock > &pblock, bool &fInvalidFound, ConnectTrace &connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Dictates whether we need to flush the cache to disk or not.
Definition: validation.cpp:2705
MempoolAcceptResult::ResultType
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:162
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:259
ScriptError
enum ScriptError_t ScriptError
MempoolAcceptResult::m_base_fees
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:176
ChainstateManager::ActiveChain
CChain & ActiveChain() const
Definition: validation.h:895
UpdateUncommittedBlockStructures
void UpdateUncommittedBlockStructures(CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
Update uncommitted block structures (currently: only the witness reserved value).
Definition: validation.cpp:3259
CScriptCheck::nIn
unsigned int nIn
Definition: validation.h:306
CChainState::ResetCoinsViews
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:569
txmempool.h
CCoinsView
Abstract view on the open txout dataset.
Definition: coins.h:157
ValidationState::IsValid
bool IsValid() const
Definition: validation.h:120
PruneBlockFilesManual
void PruneBlockFilesManual(CChainState &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
Definition: validation.cpp:3723
CoinsCacheSizeState
CoinsCacheSizeState
Definition: validation.h:420
TxValidationState
Definition: validation.h:140
packages.h
CAutoFile
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:544
AcceptToMemoryPool
MempoolAcceptResult AcceptToMemoryPool(CChainState &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.
Definition: validation.cpp:1322
Assume
#define Assume(val)
Assume is the identity function.
Definition: check.h:72
Consensus::Params
Parameters that influence chain consensus.
Definition: params.h:70
MempoolAcceptResult::m_vsize
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigops.
Definition: validation.h:174
PackageMempoolAcceptResult::PackageMempoolAcceptResult
PackageMempoolAcceptResult(const uint256 &wtxid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a single MempoolAcceptResult.
Definition: validation.h:227
CScriptCheck::swap
void swap(CScriptCheck &check)
Definition: validation.h:319
node::BlockManager
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:65
ChainstateManager::IsSnapshotActive
bool IsSnapshotActive() const
Definition: validation.cpp:4967
CScriptCheck::CScriptCheck
CScriptCheck()
Definition: validation.h:313
PackageMempoolAcceptResult::PackageMempoolAcceptResult
PackageMempoolAcceptResult(PackageValidationState state, std::map< const uint256, const MempoolAcceptResult > &&results)
Definition: validation.h:222
CChainState::m_blockman
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all CChainState instances.
Definition: validation.h:481
CChainState::GetMempool
CTxMemPool * GetMempool()
Definition: validation.h:556
fRequireStandard
bool fRequireStandard
Definition: validation.cpp:145
FopenFn
std::function< FILE *(const fs::path &, const char *)> FopenFn
Definition: validation.h:976
CTxMemPool::cs
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:517
DEFAULT_ANCESTOR_LIMIT
static const unsigned int DEFAULT_ANCESTOR_LIMIT
Default for -limitancestorcount, max number of in-mempool ancestors.
Definition: validation.h:58
CChainState::PruneAndFlush
void PruneAndFlush()
Prune blockfiles from the disk if necessary and then flush chainstate changes if we pruned.
Definition: validation.cpp:2359
CScriptCheck::GetScriptError
ScriptError GetScriptError() const
Definition: validation.h:329
CTxOut
An output of a transaction.
Definition: transaction.h:128
Consensus
Transaction validation functions.
Definition: params.h:12
StopScriptCheckWorkerThreads
void StopScriptCheckWorkerThreads()
Stop all of the script checking worker threads.
Definition: validation.cpp:1792
ChainstateManager::ActiveTip
CBlockIndex * ActiveTip() const
Definition: validation.h:897
node::BlockMap
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: blockstorage.h:52
DEFAULT_COINSTATSINDEX
static constexpr bool DEFAULT_COINSTATSINDEX
Definition: validation.h:84
fs::path
Path class wrapper to prepare application code for transition from boost::filesystem library to std::...
Definition: fs.h:33
AbortNode
bool AbortNode(BlockValidationState &state, const std::string &strMessage, const bilingual_str &userMessage=bilingual_str{})
Definition: validation.cpp:1684
FlatFilePos
Definition: flatfile.h:14
CChainState::NeedsRedownload
bool NeedsRedownload() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Whether the chain state needs to be redownloaded due to lack of witness data.
Definition: validation.cpp:3977
ChainstateManager::SnapshotBlockhash
std::optional< uint256 > SnapshotBlockhash() const
Definition: validation.cpp:4609
CChainState::InvalidateBlock
bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
Mark a block as invalid.
Definition: validation.cpp:2956
DEFAULT_CHECKPOINTS_ENABLED
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:82
PackageValidationState
Definition: packages.h:34
ChainstateManager::ActiveHeight
int ActiveHeight() const
Definition: validation.h:896
CChainState::m_params
const CChainParams & m_params
Chain parameters for this chainstate.
Definition: validation.h:484
ChainstateManager::m_best_invalid
CBlockIndex * m_best_invalid
Definition: validation.h:807
minRelayTxFee
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
Definition: validation.cpp:153
MempoolAcceptResult::ResultType::INVALID
@ INVALID
Fully validated, valid.
ChainstateManager::IsSnapshotValidated
bool IsSnapshotValidated() const
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:911
ChainTxData
Holds various statistics on transactions within a chain.
Definition: chainparams.h:59
CChainState::ChainstateManager
void UpdateTip(const CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(frien ChainstateManager)
Check warning conditions and do some notifications on new chain tip set.
Definition: validation.h:728
DEFAULT_MAX_TIP_AGE
static const int64_t DEFAULT_MAX_TIP_AGE
Definition: validation.h:81
PackageMempoolAcceptResult
Validation result for package mempool acceptance.
Definition: validation.h:211
CChainState::LoadMempool
void LoadMempool(const ArgsManager &args)
Load the persisted mempool from disk.
Definition: validation.cpp:3732
CChainState::m_from_snapshot_blockhash
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:528
CChainState::nLastPreciousChainwork
arith_uint256 nLastPreciousChainwork
chainwork for the last block that preciousblock has been applied to.
Definition: validation.h:455
DISCONNECT_UNCLEAN
@ DISCONNECT_UNCLEAN
Definition: validation.h:371
CBlockTreeDB
Access to the block database (blocks/index/)
Definition: txdb.h:77
CChainState::MaybeUpdateMempoolForReorg
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:314
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
SynchronizationState::INIT_REINDEX
@ INIT_REINDEX
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:138
ConnectTrace
Used to track blocks whose transactions were applied to the UTXO state as a part of a single Activate...
Definition: validation.cpp:2530
CChainState::AcceptBlock
bool AcceptBlock(const std::shared_ptr< const CBlock > &pblock, BlockValidationState &state, CBlockIndex **ppindex, bool fRequested, const FlatFilePos *dbp, bool *fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Store block on disk.
Definition: validation.cpp:3555
GuessVerificationProgress
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
Definition: validation.cpp:4592
CChainState::m_chainman
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:489
MempoolAcceptResult::ResultType::MEMPOOL_ENTRY
@ MEMPOOL_ENTRY
Invalid.
ChainstateManager::ProcessNewBlock
bool ProcessNewBlock(const CChainParams &chainparams, const std::shared_ptr< const CBlock > &block, bool force_processing, bool *new_block) LOCKS_EXCLUDED(cs_main)
Process an incoming block.
Definition: validation.cpp:3638
ChainstateManager::CChainState
friend CChainState
Definition: validation.h:825
PrecomputedTransactionData
Definition: interpreter.h:150
CChainState::m_coins_views
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:476
ChainstateManager::GetAll
CChainState &InitializeChainstate(CTxMemPool *mempool, const std::optional< uint256 > &snapshot_blockhash=std::nullopt) LIFETIMEBOUND EXCLUSIVE_LOCKS_REQUIRED(std::vector< CChainState * GetAll)()
Instantiate a new chainstate and assign it based upon whether it is from a snapshot.
Definition: validation.h:875
node::BlockManager::LoadBlockIndex
bool WriteBlockIndexDB() EXCLUSIVE_LOCKS_REQUIRED(bool LoadBlockIndexDB(ChainstateManager &chainman) EXCLUSIVE_LOCKS_REQUIRED(bool LoadBlockIndex(const Consensus::Params &consensus_params, ChainstateManager &chainman) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the blocktree off disk and into memory.
Definition: blockstorage.h:130
uint256
256-bit opaque blob.
Definition: uint256.h:124
LOCK_RETURNED
#define LOCK_RETURNED(x)
Definition: threadsafety.h:47
PackageMempoolAcceptResult::m_state
const PackageValidationState m_state
Definition: validation.h:213
CScriptCheck::error
ScriptError error
Definition: validation.h:309
CChainState
CChainState stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:443
CChainState::CoinsDB
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:550
ChainstateManager::GUARDED_BY
CChainState *m_active_chainstate GUARDED_BY(::cs_main)
Points to either the ibd or snapshot chainstate; indicates our most-work chain.
Definition: validation.h:801
TestBlockValidity
bool TestBlockValidity(BlockValidationState &state, const CChainParams &chainparams, CChainState &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)
Definition: validation.cpp:3690
CChainState::ReceivedBlockTransactions
void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew, const FlatFilePos &pos) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS).
Definition: validation.cpp:3133
StartScriptCheckWorkerThreads
void StartScriptCheckWorkerThreads(int threads_num)
Run instances of script checking worker threads.
Definition: validation.cpp:1787
CChainState::ConnectBlock
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)
Apply the effects of this block (with given index) on the UTXO set represented by coins.
Definition: validation.h:632
chain.h
MAX_PACKAGE_COUNT
static constexpr uint32_t MAX_PACKAGE_COUNT
Default maximum number of transactions in a package.
Definition: packages.h:15
CChainState::m_coinsdb_cache_size_bytes
size_t m_coinsdb_cache_size_bytes
The cache size of the on-disk coins view.
Definition: validation.h:572
DISCONNECT_OK
@ DISCONNECT_OK
Definition: validation.h:370
CChainState::ReplayBlocks
bool ReplayBlocks()
Replay blocks that aren't fully applied to the database.
Definition: validation.cpp:3910
DEFAULT_MIN_RELAY_TX_FEE
static const unsigned int DEFAULT_MIN_RELAY_TX_FEE
Default for -minrelaytxfee, minimum relay fee for transactions.
Definition: validation.h:56
CoinsViews::GUARDED_BY
CCoinsViewDB m_dbview GUARDED_BY(cs_main)
The lowest level of the CoinsViews cache hierarchy sits in a leveldb database on disk.
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:463
hasher.h
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:761
attributes.h
CVerifyDB
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:356
CChainState::cs
bool m_mempool cs
Definition: validation.h:636
CheckBlock
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.
Definition: validation.cpp:3185
CChainState::CheckForkWarningConditions
void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1485
CScriptCheck::CScriptCheck
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:314
MempoolAcceptResult::ResultType::VALID
@ VALID
CBlock
Definition: block.h:62
UnloadBlockIndex
void UnloadBlockIndex(CTxMemPool *mempool, ChainstateManager &chainman)
Unload database information.
Definition: validation.cpp:4003
DisconnectedBlockTransactions
Definition: txmempool.h:901
MempoolAcceptResult::MempoolAcceptResult
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:193
CChain
An in-memory indexed chain of blocks.
Definition: chain.h:417
MIN_DISK_SPACE_FOR_BLOCK_FILES
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:102
MempoolAcceptResult::MempoolTx
static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees)
Definition: validation.h:186
LOCKS_EXCLUDED
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
CChainState::nBlockReverseSequenceId
int32_t nBlockReverseSequenceId
Decreasing counter (used by subsequent preciousblock calls).
Definition: validation.h:453
LIFETIMEBOUND
#define LIFETIMEBOUND
Definition: attributes.h:16
SynchronizationState::INIT_DOWNLOAD
@ INIT_DOWNLOAD
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:213
ProcessNewPackage
PackageMempoolAcceptResult ProcessNewPackage(CChainState &active_chainstate, CTxMemPool &pool, const Package &txns, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Validate (and maybe submit) a package to the mempool.
Definition: validation.cpp:1348
ArgsManager
Definition: system.h:158
translation.h
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
MempoolAcceptResult::Failure
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:178
LOCK
#define LOCK(cs)
Definition: sync.h:226
script_error.h
ChainstateManager::LoadBlockIndex
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the block tree and coins database from disk, initializing state if we're running with -reindex.
Definition: validation.cpp:4016
blockstorage.h
std
Definition: setup_common.h:33
CChainState::GUARDED_BY
int32_t nBlockSequenceId GUARDED_BY(::cs_main)
Every received block is assigned a unique and increasing identifier, so we know which one to give pri...
LockPoints
Definition: txmempool.h:41
g_best_block_cv
std::condition_variable g_best_block_cv
Definition: validation.cpp:142
MempoolAcceptResult
Validation result for a single transaction mempool acceptance.
Definition: validation.h:160
CCoinsViewErrorCatcher
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Definition: coins.h:343
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:561
CScriptCheck
Closure representing one script verification Note that this stores references to the spending transac...
Definition: validation.h:301
CChainState::InitCoinsDB
void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe, std::string leveldb_name="chainstate")
Initialize the CoinsViews UTXO set database management data structures.
Definition: validation.cpp:1417
CScriptCheck::cacheStore
bool cacheStore
Definition: validation.h:308
LoadMempool
bool LoadMempool(CTxMemPool &pool, CChainState &active_chainstate, FopenFn mockable_fopen_function=fsbridge::fopen)
Load the mempool from disk.
Definition: validation.cpp:4446
DEFAULT_BLOCKFILTERINDEX
static const char *const DEFAULT_BLOCKFILTERINDEX
Definition: validation.h:85
node
Definition: init.h:22
Package
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:32
CChainState::LoadChainTip
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Update the chain tip based on database information, i.e.
Definition: validation.cpp:3741
CChainState::ResetBlockFailureFlags
void ResetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove invalidity status from a block and its descendants.
Definition: validation.cpp:3098
DEFAULT_SCRIPTCHECK_THREADS
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:80
CScriptCheck::m_tx_out
CTxOut m_tx_out
Definition: validation.h:304
SynchronizationState
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:105
CoinsViews
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:394
pindexBestHeader
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.cpp:140
ChainstateManager::m_total_coinsdb_cache
int64_t m_total_coinsdb_cache
The total number of bytes available for us to use across all leveldb coins databases.
Definition: validation.h:860
DEFAULT_TXINDEX
static const bool DEFAULT_TXINDEX
Definition: validation.h:83
CScriptCheck::nFlags
unsigned int nFlags
Definition: validation.h:307
lp
LockPoints lp
Definition: mempool_eviction.cpp:17
CChainState::FlushStateToDisk
bool FlushStateToDisk(BlockValidationState &state, FlushStateMode mode, int nManualPruneHeight=0)
Update the on-disk chain state.
Definition: validation.cpp:2219
DEFAULT_DESCENDANT_SIZE_LIMIT
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT
Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.
Definition: validation.h:64
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
MAX_PACKAGE_SIZE
static constexpr uint32_t MAX_PACKAGE_SIZE
Default maximum total virtual size of transactions in a package in KvB.
Definition: packages.h:17
ChainstateManager::ActivateSnapshot
bool ActivateSnapshot(CAutoFile &coins_file, const node::SnapshotMetadata &metadata, bool in_memory)
Construct and activate a Chainstate on the basis of UTXO snapshot data.
Definition: validation.cpp:4670
FlushStateMode::IF_NEEDED
@ IF_NEEDED
CheckFinalTx
bool CheckFinalTx(const CBlockIndex *active_chain_tip, const CTransaction &tx, int flags=-1) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Transaction validation functions.
Definition: validation.cpp:181
CBlockLocator
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:114
nMinimumChainWork
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
Definition: validation.cpp:151
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:148
SCRIPT_ERR_UNKNOWN_ERROR
@ SCRIPT_ERR_UNKNOWN_ERROR
Definition: script_error.h:14
CChainState::ConnectTip
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.
Definition: validation.cpp:2564
CChainState::m_coinstip_cache_size_bytes
size_t m_coinstip_cache_size_bytes
The cache size of the in-memory coins view.
Definition: validation.h:575
CChainState::LoadGenesisBlock
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
Definition: validation.cpp:4039
amount.h
CoinsViews::CoinsViews
CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory, bool should_wipe)
This constructor initializes CCoinsViewDB and CCoinsViewErrorCatcher instances, but it does not creat...
Definition: validation.cpp:1393
CScriptCheck::txdata
PrecomputedTransactionData * txdata
Definition: validation.h:310
ChainstateManager::GUARDED_BY
std::unique_ptr< CChainState > m_ibd_chainstate GUARDED_BY(::cs_main)
The chainstate used under normal operation (i.e.
DisconnectResult
DisconnectResult
Definition: validation.h:368
CChainState::CoinsErrorCatcher
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:563
CChainState::CChainState
CChainState(CTxMemPool *mempool, node::BlockManager &blockman, ChainstateManager &chainman, std::optional< uint256 > from_snapshot_blockhash=std::nullopt)
Definition: validation.cpp:1406
CheckSequenceLocks
bool CheckSequenceLocks(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx, int flags, LockPoints *lp=nullptr, bool useExistingLockPoints=false)
Check if transaction will be BIP68 final in the next block to be created on top of tip.
Definition: validation.cpp:214
CChainState::CoinsTip
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:543
txdb.h
ChainstateManager::m_load_block
std::thread m_load_block
Definition: validation.h:828
SynchronizationState::POST_INIT
@ POST_INIT
CChainState::m_chain
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:521
ChainstateManager::m_blockman
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:831
DumpMempool
bool DumpMempool(const CTxMemPool &pool, FopenFn mockable_fopen_function=fsbridge::fopen, bool skip_file_commit=false)
Dump the mempool to disk.
Definition: validation.cpp:4529
CChainState::m_mempool
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:473
g_best_block
uint256 g_best_block
Used to notify getblocktemplate RPC of new tips.
Definition: validation.cpp:143
RNGLevel::PERIODIC
@ PERIODIC
Called by RandAddPeriodic()
DEFAULT_CHECKBLOCKS
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:92
args
ArgsManager args
Definition: notifications.cpp:36
GenerateCoinbaseCommitment
std::vector< unsigned char > GenerateCoinbaseCommitment(CBlock &block, const CBlockIndex *pindexPrev, const Consensus::Params &consensusParams)
Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks...
Definition: validation.cpp:3271
CChainState::InvalidChainFound
void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1504