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,
167  };
170 
173 
174  // The following fields are only present when m_result_type = ResultType::VALID or MEMPOOL_ENTRY
176  const std::optional<std::list<CTransactionRef>> m_replaced_transactions;
178  const std::optional<int64_t> m_vsize;
180  const std::optional<CAmount> m_base_fees;
181 
182  // The following field is only present when m_result_type = ResultType::DIFFERENT_WITNESS
184  const std::optional<uint256> m_other_wtxid;
185 
187  return MempoolAcceptResult(state);
188  }
189 
190  static MempoolAcceptResult Success(std::list<CTransactionRef>&& replaced_txns, int64_t vsize, CAmount fees) {
191  return MempoolAcceptResult(std::move(replaced_txns), vsize, fees);
192  }
193 
194  static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees) {
195  return MempoolAcceptResult(vsize, fees);
196  }
197 
199  return MempoolAcceptResult(other_wtxid);
200  }
201 
202 // Private constructors. Use static methods MempoolAcceptResult::Success, etc. to construct.
203 private:
206  : m_result_type(ResultType::INVALID), m_state(state) {
207  Assume(!state.IsValid()); // Can be invalid or error
208  }
209 
211  explicit MempoolAcceptResult(std::list<CTransactionRef>&& replaced_txns, int64_t vsize, CAmount fees)
212  : m_result_type(ResultType::VALID),
213  m_replaced_transactions(std::move(replaced_txns)), m_vsize{vsize}, m_base_fees(fees) {}
214 
216  explicit MempoolAcceptResult(int64_t vsize, CAmount fees)
217  : m_result_type(ResultType::MEMPOOL_ENTRY), m_vsize{vsize}, m_base_fees(fees) {}
218 
220  explicit MempoolAcceptResult(const uint256& other_wtxid)
221  : m_result_type(ResultType::DIFFERENT_WITNESS), m_other_wtxid(other_wtxid) {}
222 };
223 
228 {
236  std::map<const uint256, const MempoolAcceptResult> m_tx_results;
237 
239  std::map<const uint256, const MempoolAcceptResult>&& results)
240  : m_state{state}, m_tx_results(std::move(results)) {}
241 
243  explicit PackageMempoolAcceptResult(const uint256& wtxid, const MempoolAcceptResult& result)
244  : m_tx_results{ {wtxid, result} } {}
245 };
246 
261  int64_t accept_time, bool bypass_limits, bool test_accept)
263 
273  const Package& txns, bool test_accept)
275 
285 bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags = -1) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
286 
307  const CCoinsView& coins_view,
308  const CTransaction& tx,
309  int flags,
310  LockPoints* lp = nullptr,
311  bool useExistingLockPoints = false);
312 
318 {
319 private:
322  unsigned int nIn;
323  unsigned int nFlags;
327 
328 public:
329  CScriptCheck(): ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
330  CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
331  m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
332 
333  bool operator()();
334 
335  void swap(CScriptCheck &check) {
336  std::swap(ptxTo, check.ptxTo);
337  std::swap(m_tx_out, check.m_tx_out);
338  std::swap(nIn, check.nIn);
339  std::swap(nFlags, check.nFlags);
340  std::swap(cacheStore, check.cacheStore);
341  std::swap(error, check.error);
342  std::swap(txdata, check.txdata);
343  }
344 
345  ScriptError GetScriptError() const { return error; }
346 };
347 
350 
354 bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
355 
358  const CChainParams& chainparams,
359  CChainState& chainstate,
360  const CBlock& block,
361  CBlockIndex* pindexPrev,
362  bool fCheckPOW = true,
363  bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
364 
366 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
367 
369 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
370 
372 class CVerifyDB {
373 public:
374  CVerifyDB();
375  ~CVerifyDB();
376  bool VerifyDB(
377  CChainState& chainstate,
378  const Consensus::Params& consensus_params,
379  CCoinsView& coinsview,
380  int nCheckLevel,
381  int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
382 };
383 
385 {
386  DISCONNECT_OK, // All good.
387  DISCONNECT_UNCLEAN, // Rolled back, but UTXO set was inconsistent with block.
388  DISCONNECT_FAILED // Something else went wrong.
389 };
390 
391 class ConnectTrace;
392 
394 enum class FlushStateMode {
395  NONE,
396  IF_NEEDED,
397  PERIODIC,
398  ALWAYS
399 };
400 
410 class CoinsViews {
411 
412 public:
415  CCoinsViewDB m_dbview GUARDED_BY(cs_main);
416 
419 
422  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
423 
430  CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory, bool should_wipe);
431 
433  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
434 };
435 
437 {
439  CRITICAL = 2,
441  LARGE = 1,
442  OK = 0
443 };
444 
460 {
461 protected:
467  int32_t nBlockSequenceId GUARDED_BY(::cs_main) = 1;
472 
479 
486  mutable std::atomic<bool> m_cached_finished_ibd{false};
487 
491 
493  std::unique_ptr<CoinsViews> m_coins_views;
494 
495 public:
499 
502 
507 
508  explicit CChainState(
509  CTxMemPool* mempool,
510  node::BlockManager& blockman,
511  ChainstateManager& chainman,
512  std::optional<uint256> from_snapshot_blockhash = std::nullopt);
513 
520  void InitCoinsDB(
521  size_t cache_size_bytes,
522  bool in_memory,
523  bool should_wipe,
524  std::string leveldb_name = "chainstate");
525 
528  void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
529 
532  bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
533  {
535  return m_coins_views && m_coins_views->m_cacheview;
536  }
537 
541 
547  const std::optional<uint256> m_from_snapshot_blockhash;
548 
551  bool reliesOnAssumedValid() { return m_from_snapshot_blockhash.has_value(); }
552 
559  std::set<CBlockIndex*, node::CBlockIndexWorkComparator> setBlockIndexCandidates;
560 
563  {
565  assert(m_coins_views->m_cacheview);
566  return *m_coins_views->m_cacheview.get();
567  }
568 
571  {
573  return m_coins_views->m_dbview;
574  }
575 
578  {
579  return m_mempool;
580  }
581 
585  {
587  return m_coins_views->m_catcherview;
588  }
589 
591  void ResetCoinsViews() { m_coins_views.reset(); }
592 
595 
598 
601  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
603 
605  void LoadExternalBlockFile(FILE* fileIn, FlatFilePos* dbp = nullptr)
607 
619  bool FlushStateToDisk(
620  BlockValidationState& state,
621  FlushStateMode mode,
622  int nManualPruneHeight = 0);
623 
625  void ForceFlushStateToDisk();
626 
629  void PruneAndFlush();
630 
646  bool ActivateBestChain(
647  BlockValidationState& state,
648  std::shared_ptr<const CBlock> pblock = nullptr)
651 
652  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);
653 
654  // Block (dis)connection on a given view:
655  DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view)
657  bool ConnectBlock(const CBlock& block, BlockValidationState& state, CBlockIndex* pindex,
658  CCoinsViewCache& view, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
659 
660  // Apply the effects of a block disconnection on the UTXO set.
662 
663  // Manual block validity manipulation:
668  bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
671 
673  bool InvalidateBlock(BlockValidationState& state, CBlockIndex* pindex)
676 
679 
681  bool ReplayBlocks();
682 
684  [[nodiscard]] bool NeedsRedownload() const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
686  bool LoadGenesisBlock();
687 
689 
691 
693  bool IsInitialBlockDownload() const;
694 
697 
703  void CheckBlockIndex();
704 
706  void LoadMempool(const ArgsManager& args);
707 
710 
714  CoinsCacheSizeState GetCoinsCacheSizeState() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
715 
716  CoinsCacheSizeState GetCoinsCacheSizeState(
717  size_t max_coins_cache_size_bytes,
718  size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
719 
721 
722 private:
723  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);
724  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);
725 
728  void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
729 
731 
734 
737  {
738  return m_mempool ? &m_mempool->cs : nullptr;
739  }
740 
755  DisconnectedBlockTransactions& disconnectpool,
757 
759  void UpdateTip(const CBlockIndex* pindexNew)
761 
762  friend ChainstateManager;
763 };
764 
793 {
794 private:
810  std::unique_ptr<CChainState> m_ibd_chainstate GUARDED_BY(::cs_main);
811 
821  std::unique_ptr<CChainState> m_snapshot_chainstate GUARDED_BY(::cs_main);
822 
832  CChainState* m_active_chainstate GUARDED_BY(::cs_main) {nullptr};
833 
836  bool m_snapshot_validated{false};
837 
840 
842  [[nodiscard]] bool PopulateAndValidateSnapshot(
843  CChainState& snapshot_chainstate,
844  CAutoFile& coins_file,
845  const node::SnapshotMetadata& metadata);
846 
851  bool AcceptBlockHeader(
852  const CBlockHeader& block,
853  BlockValidationState& state,
854  const CChainParams& chainparams,
856  friend CChainState;
857 
858 public:
859  std::thread m_load_block;
863 
883  std::set<CBlockIndex*> m_failed_blocks;
884 
888  //
892 
897  // constructor
900  CChainState& InitializeChainstate(
901  CTxMemPool* mempool,
902  const std::optional<uint256>& snapshot_blockhash = std::nullopt)
904 
906  std::vector<CChainState*> GetAll();
907 
921  [[nodiscard]] bool ActivateSnapshot(
922  CAutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory);
923 
925  CChainState& ActiveChainstate() const;
927  int ActiveHeight() const { return ActiveChain().Height(); }
928  CBlockIndex* ActiveTip() const { return ActiveChain().Tip(); }
929 
931  {
933  return m_blockman.m_block_index;
934  }
935 
938  bool IsSnapshotActive() const;
939 
940  std::optional<uint256> SnapshotBlockhash() const;
941 
943  bool IsSnapshotValidated() const { return m_snapshot_validated; }
944 
964  bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock>& block, bool force_processing, bool* new_block) LOCKS_EXCLUDED(cs_main);
965 
977  bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
978 
985  [[nodiscard]] MempoolAcceptResult ProcessTransaction(const CTransactionRef& tx, bool test_accept=false)
987 
990 
992  void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
993 
995  void Reset();
996 
999  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1000 
1002  LOCK(::cs_main);
1003  UnloadBlockIndex(/* mempool */ nullptr, *this);
1004  Reset();
1005  }
1006 };
1007 
1008 using FopenFn = std::function<FILE*(const fs::path&, const char*)>;
1009 
1011 bool DumpMempool(const CTxMemPool& pool, FopenFn mockable_fopen_function = fsbridge::fopen, bool skip_file_commit = false);
1012 
1014 bool LoadMempool(CTxMemPool& pool, CChainState& active_chainstate, FopenFn mockable_fopen_function = fsbridge::fopen);
1015 
1023 const AssumeutxoData* ExpectedAssumeutxo(const int height, const CChainParams& params);
1024 
1025 #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:216
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:176
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:2676
CChainState::CoinsDB
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:570
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:3492
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:4723
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:883
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:3947
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:551
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:3581
MempoolAcceptResult::MempoolAcceptResult
MempoolAcceptResult(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees)
Constructor for success case.
Definition: validation.h:211
DISCONNECT_FAILED
@ DISCONNECT_FAILED
Definition: validation.h:388
CChainState::MempoolMutex
RecursiveMutex * MempoolMutex() const LOCK_RETURNED(m_mempool -> cs)
Indirection necessary to make lock annotations work with an optional mempool.
Definition: validation.h:736
CChainState::ForceFlushStateToDisk
void ForceFlushStateToDisk()
Unconditionally flush all changes to disk.
Definition: validation.cpp:2395
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:887
CoinsCacheSizeState::OK
@ OK
fs.h
nHeight
unsigned int nHeight
Definition: mempool_eviction.cpp:14
MempoolAcceptResult::m_state
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:172
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:27
flags
int flags
Definition: bitcoin-tx.cpp:529
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:3733
FlushStateMode::NONE
@ NONE
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
Result type.
Definition: validation.h:169
PackageMempoolAcceptResult::m_tx_results
std::map< const uint256, const MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
Definition: validation.h:236
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:4244
CScriptCheck::ptxTo
const CTransaction * ptxTo
Definition: validation.h:321
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:2735
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:836
fCheckpointsEnabled
bool fCheckpointsEnabled
Definition: validation.cpp:147
ChainstateManager::BlockIndex
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:930
AnnotatedMixin< std::recursive_mutex >
CChainState::InvalidBlockFound
void InvalidBlockFound(CBlockIndex *pindex, const BlockValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1563
FlushStateMode
FlushStateMode
Definition: validation.h:394
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:559
ChainstateManager::ActiveChainstate
CChainState & ActiveChainstate() const
The most-work chain.
Definition: validation.cpp:5025
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:406
GetBlockSubsidy
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
Definition: validation.cpp:1414
MempoolAcceptResult::Success
static MempoolAcceptResult Success(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees)
Definition: validation.h:190
InitScriptExecutionCache
void InitScriptExecutionCache()
Initializes the script-execution cache.
Definition: validation.cpp:1599
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:447
ChainstateManager::PopulateAndValidateSnapshot
bool PopulateAndValidateSnapshot(CChainState &snapshot_chainstate, CAutoFile &coins_file, const node::SnapshotMetadata &metadata)
Internal helper for ActivateSnapshot().
Definition: validation.cpp:4829
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:486
CChainState::DisconnectTip
bool DisconnectTip(BlockValidationState &state, DisconnectedBlockTransactions *disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Disconnect m_chain's tip.
Definition: validation.cpp:2506
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:2752
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:279
AssertLockHeld
AssertLockHeld(pool.cs)
ScriptError
enum ScriptError_t ScriptError
MempoolAcceptResult::m_base_fees
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:180
ChainstateManager::ActiveChain
CChain & ActiveChain() const
Definition: validation.h:926
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:3314
CScriptCheck::nIn
unsigned int nIn
Definition: validation.h:322
CChainState::ResetCoinsViews
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:591
txmempool.h
CChainState::m_chainstate_mutex
Mutex m_chainstate_mutex
The ChainState Mutex A lock that must be held when modifying this ChainState - held in ActivateBestCh...
Definition: validation.h:478
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:3780
CoinsCacheSizeState
CoinsCacheSizeState
Definition: validation.h:436
TxValidationState
Definition: validation.h:140
packages.h
CAutoFile
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:478
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:1355
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:178
PackageMempoolAcceptResult::PackageMempoolAcceptResult
PackageMempoolAcceptResult(const uint256 &wtxid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a single MempoolAcceptResult.
Definition: validation.h:243
CScriptCheck::swap
void swap(CScriptCheck &check)
Definition: validation.h:335
node::BlockManager
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:68
ChainstateManager::IsSnapshotActive
bool IsSnapshotActive() const
Definition: validation.cpp:5032
CScriptCheck::CScriptCheck
CScriptCheck()
Definition: validation.h:329
PackageMempoolAcceptResult::PackageMempoolAcceptResult
PackageMempoolAcceptResult(PackageValidationState state, std::map< const uint256, const MempoolAcceptResult > &&results)
Definition: validation.h:238
CChainState::CoinsErrorCatcher
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:584
CChainState::m_blockman
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all CChainState instances.
Definition: validation.h:498
CChainState::GetMempool
CTxMemPool * GetMempool()
Definition: validation.h:577
fRequireStandard
bool fRequireStandard
Definition: validation.cpp:145
FopenFn
std::function< FILE *(const fs::path &, const char *)> FopenFn
Definition: validation.h:1008
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:2403
CScriptCheck::GetScriptError
ScriptError GetScriptError() const
Definition: validation.h:345
CTxOut
An output of a transaction.
Definition: transaction.h:148
Consensus
Transaction validation functions.
Definition: params.h:12
StopScriptCheckWorkerThreads
void StopScriptCheckWorkerThreads()
Stop all of the script checking worker threads.
Definition: validation.cpp:1831
ChainstateManager::ActiveTip
CBlockIndex * ActiveTip() const
Definition: validation.h:928
node::BlockMap
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: blockstorage.h:55
DEFAULT_COINSTATSINDEX
static constexpr bool DEFAULT_COINSTATSINDEX
Definition: validation.h:84
fs::path
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:29
AbortNode
bool AbortNode(BlockValidationState &state, const std::string &strMessage, const bilingual_str &userMessage=bilingual_str{})
Definition: validation.cpp:1722
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:4035
ChainstateManager::SnapshotBlockhash
std::optional< uint256 > SnapshotBlockhash() const
Definition: validation.cpp:4673
DEFAULT_CHECKPOINTS_ENABLED
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:82
PackageValidationState
Definition: packages.h:35
ChainstateManager::ActiveHeight
int ActiveHeight() const
Definition: validation.h:927
CChainState::m_params
const CChainParams & m_params
Chain parameters for this chainstate.
Definition: validation.h:501
ChainstateManager::m_best_invalid
CBlockIndex * m_best_invalid
Definition: validation.h:838
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:943
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:759
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:227
CChainState::LoadMempool
void LoadMempool(const ArgsManager &args)
Load the persisted mempool from disk.
Definition: validation.cpp:3789
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:547
CChainState::nLastPreciousChainwork
arith_uint256 nLastPreciousChainwork
chainwork for the last block that preciousblock has been applied to.
Definition: validation.h:471
DISCONNECT_UNCLEAN
@ DISCONNECT_UNCLEAN
Definition: validation.h:387
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:316
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:2575
CChainState::AcceptBlock
bool ActivateBestChain(BlockValidationState &state, std::shared_ptr< const CBlock > pblock=nullptr) LOCKS_EXCLUDED(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)
Find the best known block, and make it the tip of the block chain.
Definition: validation.h:652
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:4656
CChainState::m_chainman
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:506
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:3694
ChainstateManager::CChainState
friend CChainState
Definition: validation.h:856
PrecomputedTransactionData
Definition: interpreter.h:151
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:493
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:906
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:133
uint256
256-bit opaque blob.
Definition: uint256.h:126
LOCK_RETURNED
#define LOCK_RETURNED(x)
Definition: threadsafety.h:47
PackageMempoolAcceptResult::m_state
const PackageValidationState m_state
Definition: validation.h:229
CScriptCheck::error
ScriptError error
Definition: validation.h:325
CChainState
CChainState stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:459
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:832
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:3747
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:3187
StartScriptCheckWorkerThreads
void StartScriptCheckWorkerThreads(int threads_num)
Run instances of script checking worker threads.
Definition: validation.cpp:1826
MempoolAcceptResult::MempoolAcceptResult
MempoolAcceptResult(const uint256 &other_wtxid)
Constructor for witness-swapped case.
Definition: validation.h:220
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:657
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:594
DISCONNECT_OK
@ DISCONNECT_OK
Definition: validation.h:386
CChainState::ReplayBlocks
bool ReplayBlocks()
Replay blocks that aren't fully applied to the database.
Definition: validation.cpp:3968
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:476
hasher.h
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:792
attributes.h
CVerifyDB
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:372
CChainState::cs
bool m_mempool cs
Definition: validation.h:661
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:3240
CChainState::CheckForkWarningConditions
void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1521
CScriptCheck::CScriptCheck
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:330
MempoolAcceptResult::ResultType::VALID
@ VALID
CBlock
Definition: block.h:62
UnloadBlockIndex
void UnloadBlockIndex(CTxMemPool *mempool, ChainstateManager &chainman)
Unload database information.
Definition: validation.cpp:4063
DisconnectedBlockTransactions
Definition: txmempool.h:929
MempoolAcceptResult::MempoolAcceptResult
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:205
CChain
An in-memory indexed chain of blocks.
Definition: chain.h:430
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:194
LOCKS_EXCLUDED
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
CChainState::nBlockReverseSequenceId
int32_t nBlockReverseSequenceId
Decreasing counter (used by subsequent preciousblock calls).
Definition: validation.h:469
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:1382
ArgsManager
Definition: system.h:164
translation.h
CChainState::CoinsTip
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:562
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
MempoolAcceptResult::Failure
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:186
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:4076
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...
MempoolAcceptResult::m_other_wtxid
const std::optional< uint256 > m_other_wtxid
The wtxid of the transaction in the mempool which has the same txid but different witness.
Definition: validation.h:184
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:317
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:1452
CScriptCheck::cacheStore
bool cacheStore
Definition: validation.h:324
LoadMempool
bool LoadMempool(CTxMemPool &pool, CChainState &active_chainstate, FopenFn mockable_fopen_function=fsbridge::fopen)
Load the mempool from disk.
Definition: validation.cpp:4509
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:33
CChainState::LoadChainTip
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Update the chain tip based on database information, i.e.
Definition: validation.cpp:3798
DEFAULT_SCRIPTCHECK_THREADS
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:80
MempoolAcceptResult::MempoolTxDifferentWitness
static MempoolAcceptResult MempoolTxDifferentWitness(const uint256 &other_wtxid)
Definition: validation.h:198
CScriptCheck::m_tx_out
CTxOut m_tx_out
Definition: validation.h:320
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:410
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:891
DEFAULT_TXINDEX
static const bool DEFAULT_TXINDEX
Definition: validation.h:83
CScriptCheck::nFlags
unsigned int nFlags
Definition: validation.h:323
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:2263
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:4735
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:151
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:2609
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:597
CChainState::LoadGenesisBlock
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
Definition: validation.cpp:4099
MempoolAcceptResult::ResultType::DIFFERENT_WITNESS
@ DIFFERENT_WITNESS
Valid, transaction was already in the mempool.
amount.h
CChainState::ResetBlockFailureFlags
bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(voi ResetBlockFailureFlags)(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark a block as precious and reorganize.
Definition: validation.h:678
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:1427
CScriptCheck::txdata
PrecomputedTransactionData * txdata
Definition: validation.h:326
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:384
CChainState::CChainState
CChainState(CTxMemPool *mempool, node::BlockManager &blockman, ChainstateManager &chainman, std::optional< uint256 > from_snapshot_blockhash=std::nullopt)
Definition: validation.cpp:1441
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
txdb.h
ChainstateManager::m_load_block
std::thread m_load_block
Definition: validation.h:859
SynchronizationState::POST_INIT
@ POST_INIT
CChainState::m_chain
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:540
ChainstateManager::m_blockman
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:862
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:4593
CChainState::m_mempool
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:490
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:3326
CChainState::InvalidChainFound
void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1540