Bitcoin Core  21.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-2020 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 <amount.h>
14 #include <attributes.h>
15 #include <coins.h>
16 #include <consensus/validation.h>
17 #include <crypto/common.h> // for ReadLE64
18 #include <fs.h>
19 #include <node/utxo_snapshot.h>
20 #include <policy/feerate.h>
21 #include <protocol.h> // For CMessageHeader::MessageStartChars
22 #include <script/script_error.h>
23 #include <sync.h>
24 #include <txmempool.h> // For CTxMemPool::cs
25 #include <txdb.h>
26 #include <versionbits.h>
27 #include <serialize.h>
28 #include <util/check.h>
29 #include <util/hasher.h>
30 
31 #include <atomic>
32 #include <map>
33 #include <memory>
34 #include <optional>
35 #include <set>
36 #include <stdint.h>
37 #include <string>
38 #include <thread>
39 #include <utility>
40 #include <vector>
41 
42 class CChainState;
44 class CBlockIndex;
45 class CBlockTreeDB;
46 class CBlockUndo;
47 class CChainParams;
48 struct CCheckpointData;
49 class CInv;
50 class CConnman;
51 class CScriptCheck;
52 class CTxMemPool;
53 class ChainstateManager;
54 struct ChainTxData;
55 
58 struct LockPoints;
59 struct AssumeutxoData;
60 
62 static const unsigned int DEFAULT_MIN_RELAY_TX_FEE = 1000;
64 static const unsigned int DEFAULT_ANCESTOR_LIMIT = 25;
66 static const unsigned int DEFAULT_ANCESTOR_SIZE_LIMIT = 101;
68 static const unsigned int DEFAULT_DESCENDANT_LIMIT = 25;
70 static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT = 101;
72 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
74 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
76 static const int MAX_SCRIPTCHECK_THREADS = 15;
78 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
79 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
80 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
81 static const bool DEFAULT_TXINDEX = false;
82 static const char* const DEFAULT_BLOCKFILTERINDEX = "0";
84 static const bool DEFAULT_PERSIST_MEMPOOL = true;
86 static const bool DEFAULT_FEEFILTER = true;
88 static const int DEFAULT_STOPATHEIGHT = 0;
90 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
91 static const signed int DEFAULT_CHECKBLOCKS = 6;
92 static const unsigned int DEFAULT_CHECKLEVEL = 3;
93 // Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat)
94 // At 1MB per block, 288 blocks = 288MB.
95 // Add 15% for Undo data = 331MB
96 // Add 20% for Orphan block rate = 397MB
97 // We want the low water mark after pruning to be at least 397 MB and since we prune in
98 // full block file chunks, we need the high water mark which triggers the prune to be
99 // one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
100 // Setting the target to >= 550 MiB will make it likely we can respect the target.
101 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
102 
105  INIT_REINDEX,
107  POST_INIT
108 };
109 
110 extern RecursiveMutex cs_main;
111 typedef std::unordered_map<uint256, CBlockIndex*, BlockHasher> BlockMap;
113 extern std::condition_variable g_best_block_cv;
114 extern uint256 g_best_block;
115 extern std::atomic_bool fImporting;
116 extern std::atomic_bool fReindex;
120 extern bool g_parallel_script_checks;
121 extern bool fRequireStandard;
122 extern bool fCheckBlockIndex;
123 extern bool fCheckpointsEnabled;
125 extern CFeeRate minRelayTxFee;
127 extern int64_t nMaxTipAge;
128 
130 extern uint256 hashAssumeValid;
131 
134 
137 
140 extern bool fHavePruned;
142 extern bool fPruneMode;
144 extern uint64_t nPruneTarget;
146 extern const std::vector<std::string> CHECKLEVEL_DOC;
147 
149 FILE* OpenBlockFile(const FlatFilePos &pos, bool fReadOnly = false);
151 fs::path GetBlockPosFilename(const FlatFilePos &pos);
153 void UnloadBlockIndex(CTxMemPool* mempool, ChainstateManager& chainman);
155 void StartScriptCheckWorkerThreads(int threads_num);
170 CTransactionRef GetTransaction(const CBlockIndex* const block_index, const CTxMemPool* const mempool, const uint256& hash, const Consensus::Params& consensusParams, uint256& hashBlock);
171 CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
172 
174 double GuessVerificationProgress(const ChainTxData& data, const CBlockIndex* pindex);
175 
177 uint64_t CalculateCurrentUsage();
178 
182 void UnlinkPrunedFiles(const std::set<int>& setFilesToPrune);
183 
185 void PruneBlockFilesManual(CChainState& active_chainstate, int nManualPruneHeight);
186 
194  enum class ResultType {
195  VALID,
196  INVALID,
197  };
200 
201  // The following fields are only present when m_result_type = ResultType::VALID
203  std::optional<std::list<CTransactionRef>> m_replaced_transactions;
205  std::optional<CAmount> m_base_fees;
206 
209  : m_result_type(ResultType::INVALID), m_state(state) {
210  Assume(!state.IsValid()); // Can be invalid or error
211  }
212 
214  explicit MempoolAcceptResult(std::list<CTransactionRef>&& replaced_txns, CAmount fees)
216  m_replaced_transactions(std::move(replaced_txns)), m_base_fees(fees) {}
217 };
218 
225  bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
226 
227 
229 void UpdateCoins(const CTransaction& tx, CCoinsViewCache& inputs, int nHeight);
230 
240 bool CheckFinalTx(const CBlockIndex* active_chain_tip, const CTransaction &tx, int flags = -1) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
241 
246 
258 bool CheckSequenceLocks(CChainState& active_chainstate,
259  const CTxMemPool& pool,
260  const CTransaction& tx,
261  int flags,
262  LockPoints* lp = nullptr,
263  bool useExistingLockPoints = false) EXCLUSIVE_LOCKS_REQUIRED(::cs_main, pool.cs);
264 
270 {
271 private:
274  unsigned int nIn;
275  unsigned int nFlags;
279 
280 public:
281  CScriptCheck(): ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false), error(SCRIPT_ERR_UNKNOWN_ERROR) {}
282  CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData* txdataIn) :
283  m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), cacheStore(cacheIn), error(SCRIPT_ERR_UNKNOWN_ERROR), txdata(txdataIn) { }
284 
285  bool operator()();
286 
287  void swap(CScriptCheck &check) {
288  std::swap(ptxTo, check.ptxTo);
289  std::swap(m_tx_out, check.m_tx_out);
290  std::swap(nIn, check.nIn);
291  std::swap(nFlags, check.nFlags);
292  std::swap(cacheStore, check.cacheStore);
293  std::swap(error, check.error);
294  std::swap(txdata, check.txdata);
295  }
296 
297  ScriptError GetScriptError() const { return error; }
298 };
299 
302 
306 bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
307 
310  const CChainParams& chainparams,
311  CChainState& chainstate,
312  const CBlock& block,
313  CBlockIndex* pindexPrev,
314  bool fCheckPOW = true,
315  bool fCheckMerkleRoot = true) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
316 
319 bool IsWitnessEnabled(const CBlockIndex* pindexPrev, const Consensus::Params& params);
320 
322 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
323 
325 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev, const Consensus::Params& consensusParams);
326 
328 class CVerifyDB {
329 public:
330  CVerifyDB();
331  ~CVerifyDB();
332  bool VerifyDB(const CChainParams& chainparams, CChainState& active_chainstate, CCoinsView *coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
333 };
334 
336 {
337  DISCONNECT_OK, // All good.
338  DISCONNECT_UNCLEAN, // Rolled back, but UTXO set was inconsistent with block.
339  DISCONNECT_FAILED // Something else went wrong.
340 };
341 
342 class ConnectTrace;
343 
345 enum class FlushStateMode {
346  NONE,
347  IF_NEEDED,
348  PERIODIC,
349  ALWAYS
350 };
351 
353 {
354  bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const;
355 };
356 
365 {
366  friend CChainState;
367 
368 private:
369  /* Calculate the block/rev files to delete based on height specified by user with RPC command pruneblockchain */
370  void FindFilesToPruneManual(std::set<int>& setFilesToPrune, int nManualPruneHeight, int chain_tip_height);
371 
387  void FindFilesToPrune(std::set<int>& setFilesToPrune, uint64_t nPruneAfterHeight, int chain_tip_height, int prune_height, bool is_ibd);
388 
389 public:
390  BlockMap m_block_index GUARDED_BY(cs_main);
391 
410  std::set<CBlockIndex*> m_failed_blocks;
411 
416  std::multimap<CBlockIndex*, CBlockIndex*> m_blocks_unlinked;
417 
426  bool LoadBlockIndex(
427  const Consensus::Params& consensus_params,
428  CBlockTreeDB& blocktree,
429  std::set<CBlockIndex*, CBlockIndexWorkComparator>& block_index_candidates)
431 
434 
438 
440  void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
441 
446  bool AcceptBlockHeader(
447  const CBlockHeader& block,
448  BlockValidationState& state,
449  const CChainParams& chainparams,
451 
453 
456 
459 
466 
468  Unload();
469  }
470 };
471 
481 class CoinsViews {
482 
483 public:
486  CCoinsViewDB m_dbview GUARDED_BY(cs_main);
487 
490 
493  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
494 
501  CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory, bool should_wipe);
502 
504  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
505 };
506 
508 {
510  CRITICAL = 2,
512  LARGE = 1,
513  OK = 0
514 };
515 
531 {
532 protected:
539  int32_t nBlockSequenceId = 1;
544 
550 
557  mutable std::atomic<bool> m_cached_finished_ibd{false};
558 
561 
563  std::unique_ptr<CoinsViews> m_coins_views;
564 
565 public:
569 
570  explicit CChainState(CTxMemPool& mempool, BlockManager& blockman, uint256 from_snapshot_blockhash = uint256());
571 
578  void InitCoinsDB(
579  size_t cache_size_bytes,
580  bool in_memory,
581  bool should_wipe,
582  std::string leveldb_name = "chainstate");
583 
586  void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
587 
590  bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
591  return m_coins_views && m_coins_views->m_cacheview;
592  }
593 
597 
604 
610  std::set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexCandidates;
611 
614  {
615  assert(m_coins_views->m_cacheview);
616  return *m_coins_views->m_cacheview.get();
617  }
618 
621  {
622  return m_coins_views->m_dbview;
623  }
624 
628  {
629  return m_coins_views->m_catcherview;
630  }
631 
633  void ResetCoinsViews() { m_coins_views.reset(); }
634 
637 
640 
643  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
645 
647  void LoadExternalBlockFile(const CChainParams& chainparams, FILE* fileIn, FlatFilePos* dbp = nullptr);
648 
660  bool FlushStateToDisk(
661  const CChainParams& chainparams,
662  BlockValidationState &state,
663  FlushStateMode mode,
664  int nManualPruneHeight = 0);
665 
667  void ForceFlushStateToDisk();
668 
671  void PruneAndFlush();
672 
688  bool ActivateBestChain(
689  BlockValidationState& state,
690  const CChainParams& chainparams,
691  std::shared_ptr<const CBlock> pblock = nullptr) LOCKS_EXCLUDED(cs_main);
692 
693  bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, const CChainParams& chainparams, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
694 
695  // Block (dis)connection on a given view:
696  DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view);
697  bool ConnectBlock(const CBlock& block, BlockValidationState& state, CBlockIndex* pindex,
698  CCoinsViewCache& view, const CChainParams& chainparams, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
699 
700  // Apply the effects of a block disconnection on the UTXO set.
702 
703  // Manual block validity manipulation:
710  bool InvalidateBlock(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindex) LOCKS_EXCLUDED(cs_main);
713 
715  bool ReplayBlocks(const CChainParams& params);
718  bool LoadGenesisBlock(const CChainParams& chainparams);
719 
721 
722  void UnloadBlockIndex();
723 
725  bool IsInitialBlockDownload() const;
726 
732  void CheckBlockIndex(const Consensus::Params& consensusParams);
733 
735  void LoadMempool(const ArgsManager& args);
736 
738  bool LoadChainTip(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
739 
743  CoinsCacheSizeState GetCoinsCacheSizeState(const CTxMemPool* tx_pool)
745 
746  CoinsCacheSizeState GetCoinsCacheSizeState(
747  const CTxMemPool* tx_pool,
748  size_t max_coins_cache_size_bytes,
749  size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
750 
751  std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
752 
753 private:
754  bool ActivateBestChainStep(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool.cs);
755  bool ConnectTip(BlockValidationState& state, const CChainParams& chainparams, CBlockIndex* pindexNew, const std::shared_ptr<const CBlock>& pblock, ConnectTrace& connectTrace, DisconnectedBlockTransactions& disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool.cs);
756 
759  void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos, const Consensus::Params& consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
760 
761  bool RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& inputs, const CChainParams& params) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
762 
765 
768 
770 
772 };
773 
808 {
809 private:
825  std::unique_ptr<CChainState> m_ibd_chainstate GUARDED_BY(::cs_main);
826 
836  std::unique_ptr<CChainState> m_snapshot_chainstate GUARDED_BY(::cs_main);
837 
847  CChainState* m_active_chainstate GUARDED_BY(::cs_main) {nullptr};
848 
851  bool m_snapshot_validated{false};
852 
854  [[nodiscard]] bool PopulateAndValidateSnapshot(
855  CChainState& snapshot_chainstate,
856  CAutoFile& coins_file,
857  const SnapshotMetadata& metadata);
858 
859  // For access to m_active_chainstate.
860  friend CChainState& ChainstateActive();
861  friend CChain& ChainActive();
862 
863 public:
864  std::thread m_load_block;
868 
871  int64_t m_total_coinstip_cache{0};
872  //
875  int64_t m_total_coinsdb_cache{0};
876 
881  // constructor
884  CChainState& InitializeChainstate(CTxMemPool& mempool, const uint256& snapshot_blockhash = uint256())
886 
888  std::vector<CChainState*> GetAll();
889 
903  [[nodiscard]] bool ActivateSnapshot(
904  CAutoFile& coins_file, const SnapshotMetadata& metadata, bool in_memory);
905 
907  CChainState& ActiveChainstate() const;
908  CChain& ActiveChain() const { return ActiveChainstate().m_chain; }
909  int ActiveHeight() const { return ActiveChain().Height(); }
910  CBlockIndex* ActiveTip() const { return ActiveChain().Tip(); }
911 
913  {
914  return m_blockman.m_block_index;
915  }
916 
917  bool IsSnapshotActive() const;
918 
919  std::optional<uint256> SnapshotBlockhash() const;
920 
922  bool IsSnapshotValidated() const { return m_snapshot_validated; }
923 
926  bool IsBackgroundIBD(CChainState* chainstate) const;
927 
932  CChainState& ValidatedChainstate() const;
933 
934  CChain& ValidatedChain() const { return ValidatedChainstate().m_chain; }
935  CBlockIndex* ValidatedTip() const { return ValidatedChain().Tip(); }
936 
957  bool ProcessNewBlock(const CChainParams& chainparams, const std::shared_ptr<const CBlock> pblock, bool fForceProcessing, bool* fNewBlock) LOCKS_EXCLUDED(cs_main);
958 
970  bool ProcessNewBlockHeaders(const std::vector<CBlockHeader>& block, BlockValidationState& state, const CChainParams& chainparams, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
971 
973  bool LoadBlockIndex(const CChainParams& chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
974 
976  void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
977 
979  void Reset();
980 
983  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
984 };
985 
988 
991 
994 
996 extern std::unique_ptr<CBlockTreeDB> pblocktree;
997 
999 
1003 int32_t ComputeBlockVersion(const CBlockIndex* pindexPrev, const Consensus::Params& params);
1004 
1006 CBlockFileInfo* GetBlockFileInfo(size_t n);
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 
1017 inline bool IsBlockPruned(const CBlockIndex* pblockindex)
1018 {
1019  return (fHavePruned && !(pblockindex->nStatus & BLOCK_HAVE_DATA) && pblockindex->nTx > 0);
1020 }
1021 
1029 const AssumeutxoData* ExpectedAssumeutxo(const int height, const CChainParams& params);
1030 
1031 #endif // BITCOIN_VALIDATION_H
CChainState::RollforwardBlock
bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs, const CChainParams &params) 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:4205
GetTransaction
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const uint256 &hash, const Consensus::Params &consensusParams, uint256 &hashBlock)
Return transaction from the block at block_index.
Definition: validation.cpp:1125
CChainState::LoadChainTip
bool LoadChainTip(const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Update the chain tip based on database information, i.e.
Definition: validation.cpp:4066
CChainState::ReceivedBlockTransactions
void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew, const FlatFilePos &pos, const Consensus::Params &consensusParams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS).
Definition: validation.cpp:3059
BlockManager::PruneOneBlockFile
void PruneOneBlockFile(const int fileNumber) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark one block file as pruned (modify associated database entries)
Definition: validation.cpp:3752
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:2523
feerate.h
CChainState::FlushStateToDisk
bool FlushStateToDisk(const CChainParams &chainparams, BlockValidationState &state, FlushStateMode mode, int nManualPruneHeight=0)
Update the on-disk chain state.
Definition: validation.cpp:2137
CCoinsViewDB
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:46
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:5084
ChainstateManager::BlockIndex
BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:912
ToString
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:79
FlushStateMode::ALWAYS
@ ALWAYS
DEFAULT_CHECKLEVEL
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:92
fCheckBlockIndex
bool fCheckBlockIndex
Definition: validation.cpp:143
DISCONNECT_FAILED
@ DISCONNECT_FAILED
Definition: validation.h:339
CChainState::DisconnectTip
bool DisconnectTip(BlockValidationState &state, const CChainParams &chainparams, DisconnectedBlockTransactions *disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Disconnect m_chain's tip.
Definition: validation.cpp:2359
CChainState::ForceFlushStateToDisk
void ForceFlushStateToDisk()
Unconditionally flush all changes to disk.
Definition: validation.cpp:2275
DEFAULT_PERSIST_MEMPOOL
static const bool DEFAULT_PERSIST_MEMPOOL
Default for -persistmempool.
Definition: validation.h:84
check.h
g_parallel_script_checks
bool g_parallel_script_checks
Whether there are dedicated script-checking threads running.
Definition: validation.cpp:137
CheckSequenceLocks
bool CheckSequenceLocks(CChainState &active_chainstate, const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
Definition: validation.cpp:265
hashAssumeValid
uint256 hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:148
CoinsCacheSizeState::OK
@ OK
fs.h
nHeight
unsigned int nHeight
Definition: mempool_eviction.cpp:14
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:66
BlockValidationState
Definition: validation.h:140
fsbridge::fopen
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:24
flags
int flags
Definition: bitcoin-tx.cpp:512
FlushStateMode::NONE
@ NONE
pblocktree
std::unique_ptr< CBlockTreeDB > pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: validation.cpp:201
CChainState::CheckBlockIndex
void CheckBlockIndex(const Consensus::Params &consensusParams)
Make various assertions about the state of the block index.
Definition: validation.cpp:4632
MempoolAcceptResult::m_base_fees
std::optional< CAmount > m_base_fees
Raw base fees.
Definition: validation.h:205
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:33
sync.h
UnlinkPrunedFiles
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
Definition: validation.cpp:3787
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:146
GetBlockFileInfo
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
Definition: validation.cpp:4862
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:477
ChainstateManager::ValidatedChain
CChain & ValidatedChain() const
Definition: validation.h:934
MAX_SCRIPTCHECK_THREADS
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:76
arith_uint256
256-bit unsigned big integer.
Definition: arith_uint256.h:250
BlockManager::GUARDED_BY
BlockMap m_block_index GUARDED_BY(cs_main)
CChainState::CChainState
CChainState(CTxMemPool &mempool, BlockManager &blockman, uint256 from_snapshot_blockhash=uint256())
Definition: validation.cpp:1178
CScriptCheck::ptxTo
const CTransaction * ptxTo
Definition: validation.h:273
CHECKLEVEL_DOC
const std::vector< std::string > CHECKLEVEL_DOC
Documentation for argument 'checklevel'.
Definition: validation.cpp:79
g_best_block_mutex
Mutex g_best_block_mutex
Definition: validation.cpp:134
CBlockIndexWorkComparator::operator()
bool operator()(const CBlockIndex *pa, const CBlockIndex *pb) const
Definition: validation.cpp:88
validation.h
DEFAULT_MEMPOOL_EXPIRY
static const unsigned int DEFAULT_MEMPOOL_EXPIRY
Default for -mempoolexpiry, expiration time for mempool transactions in hours.
Definition: validation.h:72
CChainState::PruneBlockIndexCandidates
void PruneBlockIndexCandidates()
Delete all entries in setBlockIndexCandidates that are worse than the current tip.
Definition: validation.cpp:2579
CoinsCacheSizeState::LARGE
@ LARGE
The cache is at >= 90% capacity.
DEFAULT_STOPATHEIGHT
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:88
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:64
fPruneMode
bool fPruneMode
True if we're running in -prune mode.
Definition: validation.cpp:141
fCheckpointsEnabled
bool fCheckpointsEnabled
Definition: validation.cpp:144
AnnotatedMixin< std::recursive_mutex >
CalculateCurrentUsage
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
Definition: validation.cpp:3741
CChainState::InvalidBlockFound
void InvalidBlockFound(CBlockIndex *pindex, const BlockValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1293
BlockManager::LoadBlockIndex
bool LoadBlockIndex(const Consensus::Params &consensus_params, CBlockTreeDB &blocktree, std::set< CBlockIndex *, CBlockIndexWorkComparator > &block_index_candidates) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the blocktree off disk and into memory.
Definition: validation.cpp:3935
versionbitscache
VersionBitsCache versionbitscache
FlushStateMode
FlushStateMode
Definition: validation.h:345
CChainState::ActivateBestChainStep
bool ActivateBestChainStep(BlockValidationState &state, const CChainParams &chainparams, 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:2596
MIN_BLOCKS_TO_KEEP
static const unsigned int MIN_BLOCKS_TO_KEEP
Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ChainActive().Tip() will not be pr...
Definition: validation.h:90
bitcoin-config.h
CInv
inv message data
Definition: protocol.h:423
BlockManager
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: validation.h:364
VersionBitsCache
BIP 9 allows multiple softforks to be deployed in parallel.
Definition: versionbits.h:76
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:386
GetBlockSubsidy
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
Definition: validation.cpp:1152
ComputeBlockVersion
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Determine what nVersion a new block should use.
Definition: validation.cpp:1686
InitScriptExecutionCache
void InitScriptExecutionCache()
Initializes the script-execution cache.
Definition: validation.cpp:1342
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:549
DEFAULT_DESCENDANT_LIMIT
static const unsigned int DEFAULT_DESCENDANT_LIMIT
Default for -limitdescendantcount, max number of in-mempool descendants.
Definition: validation.h:68
GetBlockPosFilename
fs::path GetBlockPosFilename(const FlatFilePos &pos)
Translation to a filesystem path.
Definition: validation.cpp:3910
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:557
MempoolAcceptResult::ResultType
ResultType
Used to indicate the results of mempool validation, including the possibility of unfinished validatio...
Definition: validation.h:194
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:259
ScriptError
enum ScriptError_t ScriptError
CChainState::ConnectBlock
bool ConnectBlock(const CBlock &block, BlockValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, const CChainParams &chainparams, 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.cpp:1802
DEFAULT_FEEFILTER
static const bool DEFAULT_FEEFILTER
Default for using fee filter.
Definition: validation.h:86
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:3272
CScriptCheck::nIn
unsigned int nIn
Definition: validation.h:274
CChainState::ResetCoinsViews
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:633
txmempool.h
CCoinsView
Abstract view on the open txout dataset.
Definition: coins.h:159
ValidationState::IsValid
bool IsValid() const
Definition: validation.h:119
PruneBlockFilesManual
void PruneBlockFilesManual(CChainState &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
Definition: validation.cpp:3821
CoinsCacheSizeState
CoinsCacheSizeState
Definition: validation.h:507
TxValidationState
Definition: validation.h:139
CChainState::RewindBlockIndex
bool RewindBlockIndex(const CChainParams &params) LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:4328
CChainState::LoadBlockIndexDB
bool LoadBlockIndexDB(const CChainParams &chainparams) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:4001
CAutoFile
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:564
Assume
#define Assume(val)
Assume is the identity function.
Definition: check.h:72
Consensus::Params
Parameters that influence chain consensus.
Definition: params.h:56
ChainstateManager::ValidatedTip
CBlockIndex * ValidatedTip() const
Definition: validation.h:935
protocol.h
CChainState::ConnectTip
bool ConnectTip(BlockValidationState &state, const CChainParams &chainparams, 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:2460
OpenBlockFile
FILE * OpenBlockFile(const FlatFilePos &pos, bool fReadOnly=false)
Open a block file (blk?????.dat)
Definition: validation.cpp:3901
MempoolAcceptResult::m_replaced_transactions
std::optional< std::list< CTransactionRef > > m_replaced_transactions
Mempool transactions replaced by the tx per BIP 125 rules.
Definition: validation.h:203
MAX_BLOCKFILE_SIZE
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
Definition: validation.h:74
BlockManager::FindFilesToPruneManual
void FindFilesToPruneManual(std::set< int > &setFilesToPrune, int nManualPruneHeight, int chain_tip_height)
Definition: validation.cpp:3797
CScriptCheck::swap
void swap(CScriptCheck &check)
Definition: validation.h:287
BlockManager::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:3468
CScriptCheck::CScriptCheck
CScriptCheck()
Definition: validation.h:281
fRequireStandard
bool fRequireStandard
Definition: validation.cpp:142
FopenFn
std::function< FILE *(const fs::path &, const char *)> FopenFn
Definition: validation.h:1008
IsWitnessEnabled
bool IsWitnessEnabled(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Check whether witness commitments are required for a block, and whether to enforce NULLDUMMY (BIP 147...
Definition: validation.cpp:3266
DEFAULT_ANCESTOR_LIMIT
static const unsigned int DEFAULT_ANCESTOR_LIMIT
Default for -limitancestorcount, max number of in-mempool ancestors.
Definition: validation.h:64
CChainState::PruneAndFlush
void PruneAndFlush()
Prune blockfiles from the disk if necessary and then flush chainstate changes if we pruned.
Definition: validation.cpp:2283
CScriptCheck::GetScriptError
ScriptError GetScriptError() const
Definition: validation.h:297
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:1679
ChainstateManager::ActiveTip
CBlockIndex * ActiveTip() const
Definition: validation.h:910
nPruneTarget
uint64_t nPruneTarget
Number of MiB of block files that we're trying to stay below.
Definition: validation.cpp:145
FlatFilePos
Definition: flatfile.h:14
CChainState::LoadGenesisBlock
bool LoadGenesisBlock(const CChainParams &chainparams)
Ensures we have a genesis block in the block tree, possibly writing one to disk.
Definition: validation.cpp:4480
DEFAULT_CHECKPOINTS_ENABLED
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:80
ChainstateManager::ActiveHeight
int ActiveHeight() const
Definition: validation.h:909
minRelayTxFee
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
Definition: validation.cpp:151
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:922
ChainTxData
Holds various statistics on transactions within a chain.
Definition: chainparams.h:54
MempoolAcceptResult::m_state
TxValidationState m_state
Definition: validation.h:199
DEFAULT_MAX_TIP_AGE
static const int64_t DEFAULT_MAX_TIP_AGE
Definition: validation.h:79
CChainState::LoadMempool
void LoadMempool(const ArgsManager &args)
Load the persisted mempool from disk.
Definition: validation.cpp:4057
CChainState::nLastPreciousChainwork
arith_uint256 nLastPreciousChainwork
chainwork for the last block that preciousblock has been applied to.
Definition: validation.h:543
DISCONNECT_UNCLEAN
@ DISCONNECT_UNCLEAN
Definition: validation.h:338
CBlockTreeDB
Access to the block database (blocks/index/)
Definition: txdb.h:96
g_chainman
ChainstateManager g_chainman
Definition: validation.cpp:106
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:131
ConnectTrace
Used to track blocks whose transactions were applied to the UTXO state as a part of a single Activate...
Definition: validation.cpp:2426
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:5019
versionbits.h
AcceptToMemoryPool
MempoolAcceptResult AcceptToMemoryPool(CChainState &active_chainstate, CTxMemPool &pool, const CTransactionRef &tx, bool bypass_limits, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
(Try to) add a transaction to the memory pool.
Definition: validation.cpp:1118
cs
static void pool cs
Definition: mempool_eviction.cpp:12
PrecomputedTransactionData
Definition: interpreter.h:146
CCheckpointData
Definition: chainparams.h:19
utxo_snapshot.h
CChainState::ActivateBestChain
bool ActivateBestChain(BlockValidationState &state, const CChainParams &chainparams, 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:2720
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:563
uint256
256-bit opaque blob.
Definition: uint256.h:124
BlockManager::FindForkInGlobalIndex
CBlockIndex * FindForkInGlobalIndex(const CChain &chain, const CBlockLocator &locator) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Find the last common block between the parameter chain and a locator.
Definition: validation.cpp:181
CScriptCheck::error
ScriptError error
Definition: validation.h:277
fReindex
std::atomic_bool fReindex
CChainState
CChainState stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:530
CChainState::CoinsDB
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:620
CChainState::DisconnectBlock
DisconnectResult DisconnectBlock(const CBlock &block, const CBlockIndex *pindex, CCoinsViewCache &view)
Undo the effects of this block (with given index) on the UTXO set represented by coins.
Definition: validation.cpp:1566
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:847
fHavePruned
bool fHavePruned
Pruning-related variables and constants.
Definition: validation.cpp:140
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:3703
StartScriptCheckWorkerThreads
void StartScriptCheckWorkerThreads(int threads_num)
Run instances of script checking worker threads.
Definition: validation.cpp:1674
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:636
DISCONNECT_OK
@ DISCONNECT_OK
Definition: validation.h:337
coins.h
TestLockPointValidity
bool TestLockPointValidity(CChain &active_chain, const LockPoints *lp) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Test whether the LockPoints height and time are still valid on the current chain.
Definition: validation.cpp:246
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:62
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.
ChainActive
CChain & ChainActive()
Please prefer the identical ChainstateManager::ActiveChain.
Definition: validation.cpp:115
BlockManager::FindFilesToPrune
void FindFilesToPrune(std::set< int > &setFilesToPrune, uint64_t nPruneAfterHeight, int chain_tip_height, int prune_height, bool is_ibd)
Prune block and undo files (blk???.dat and undo???.dat) so that the disk space used is less than a us...
Definition: validation.cpp:3832
hasher.h
BlockManager::GetSpendHeight
int GetSpendHeight(const CCoinsViewCache &inputs) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Return the spend height, which is one more than the inputs.GetBestBlock().
Definition: validation.cpp:1330
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:807
attributes.h
CVerifyDB
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:328
CChainState::cs
bool m_mempool cs
Definition: validation.h:701
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:3192
CChainState::CheckForkWarningConditions
void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1251
CScriptCheck::CScriptCheck
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:282
MempoolAcceptResult::ResultType::VALID
@ VALID
CBlock
Definition: block.h:62
BlockManager::LookupBlockIndex
CBlockIndex * LookupBlockIndex(const uint256 &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:173
CChainState::IsInitialBlockDownload
bool IsInitialBlockDownload() const
Check whether we are doing an initial block download (synchronizing from disk or network)
Definition: validation.cpp:1209
CChainState::UnloadBlockIndex
void UnloadBlockIndex()
Definition: validation.cpp:4431
CConnman
Definition: net.h:803
CChainState::m_from_snapshot_blockhash
const uint256 m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from.
Definition: validation.h:603
UnloadBlockIndex
void UnloadBlockIndex(CTxMemPool *mempool, ChainstateManager &chainman)
Unload database information.
Definition: validation.cpp:4439
DisconnectedBlockTransactions
Definition: txmempool.h:892
CChainState::nBlockSequenceId
int32_t nBlockSequenceId
Blocks loaded from disk are assigned id 0, so start the counter at 1.
Definition: validation.h:539
MempoolAcceptResult::MempoolAcceptResult
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:208
CChain
An in-memory indexed chain of blocks.
Definition: chain.h:392
MIN_DISK_SPACE_FOR_BLOCK_FILES
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:101
LOCKS_EXCLUDED
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:48
CChainState::nBlockReverseSequenceId
int32_t nBlockReverseSequenceId
Decreasing counter (used by subsequent preciousblock calls).
Definition: validation.h:541
BlockManager::AddToBlockIndex
CBlockIndex * AddToBlockIndex(const CBlockHeader &block) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3022
CBlockIndexWorkComparator
Definition: validation.h:352
BlockManager::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:410
SynchronizationState::INIT_DOWNLOAD
@ INIT_DOWNLOAD
common.h
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:215
ArgsManager
Definition: system.h:162
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:49
script_error.h
CBlockFileInfo
Definition: chain.h:40
LockPoints
Definition: txmempool.h:39
g_best_block_cv
std::condition_variable g_best_block_cv
Definition: validation.cpp:135
MempoolAcceptResult
Validation result for a single transaction mempool acceptance.
Definition: validation.h:190
CChainState::setBlockIndexCandidates
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries with BLOCK_VALID_TRANSACTIONS (for itself and all ancestors) and a...
Definition: validation.h:610
CCoinsViewErrorCatcher
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Definition: coins.h:345
CChainState::m_blockman
BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all CChainState instances.
Definition: validation.h:568
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:538
CScriptCheck
Check if transaction will be BIP 68 final in the next block to be created.
Definition: validation.h:269
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:1183
CScriptCheck::cacheStore
bool cacheStore
Definition: validation.h:276
DEFAULT_BLOCKFILTERINDEX
static const char *const DEFAULT_BLOCKFILTERINDEX
Definition: validation.h:82
serialize.h
fImporting
std::atomic_bool fImporting
CChainState::ResetBlockFailureFlags
void ResetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove invalidity status from a block and its descendants.
Definition: validation.cpp:2988
DEFAULT_SCRIPTCHECK_THREADS
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:78
BlockManager::GetLastCheckpoint
CBlockIndex * GetLastCheckpoint(const CCheckpointData &data) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Returns last CBlockIndex* that is a checkpoint.
Definition: validation.cpp:3313
CScriptCheck::m_tx_out
CTxOut m_tx_out
Definition: validation.h:272
SynchronizationState
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:104
CoinsViews
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:481
pindexBestHeader
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.cpp:133
CChainState::AcceptBlock
bool AcceptBlock(const std::shared_ptr< const CBlock > &pblock, BlockValidationState &state, const CChainParams &chainparams, CBlockIndex **ppindex, bool fRequested, const FlatFilePos *dbp, bool *fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Store block on disk.
Definition: validation.cpp:3584
CChainState::InvalidateBlock
bool InvalidateBlock(BlockValidationState &state, const CChainParams &chainparams, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
Mark a block as invalid.
Definition: validation.cpp:2847
BlockManager::m_blocks_unlinked
std::multimap< CBlockIndex *, CBlockIndex * > m_blocks_unlinked
All pairs A->B, where A (or one of its ancestors) misses transactions, but B has transactions.
Definition: validation.h:416
DEFAULT_TXINDEX
static const bool DEFAULT_TXINDEX
Definition: validation.h:81
CScriptCheck::nFlags
unsigned int nFlags
Definition: validation.h:275
lp
LockPoints lp
Definition: mempool_eviction.cpp:17
MempoolAcceptResult::m_result_type
ResultType m_result_type
Definition: validation.h:198
CChainState::m_mempool
CTxMemPool & m_mempool
mempool that is kept in sync with the chain
Definition: validation.h:560
DEFAULT_DESCENDANT_SIZE_LIMIT
static const unsigned int DEFAULT_DESCENDANT_SIZE_LIMIT
Default for -limitdescendantsize, maximum kilobytes of in-mempool descendants.
Definition: validation.h:70
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:50
CChainState::ReplayBlocks
bool ReplayBlocks(const CChainParams &params)
Replay blocks that aren't fully applied to the database.
Definition: validation.cpp:4225
MempoolAcceptResult::MempoolAcceptResult
MempoolAcceptResult(std::list< CTransactionRef > &&replaced_txns, CAmount fees)
Constructor for success case.
Definition: validation.h:214
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:212
BLOCK_HAVE_DATA
@ BLOCK_HAVE_DATA
full block available in blk*.dat
Definition: chain.h:121
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:149
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:137
SCRIPT_ERR_UNKNOWN_ERROR
@ SCRIPT_ERR_UNKNOWN_ERROR
Definition: script_error.h:14
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:639
CChainState::EraseBlockData
void EraseBlockData(CBlockIndex *index) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark a block as not having block data.
Definition: validation.cpp:4293
BlockManager::CChainState
friend CChainState
Definition: validation.h:366
amount.h
assert
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
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:1165
CScriptCheck::txdata
PrecomputedTransactionData * txdata
Definition: validation.h:278
CChainState::cs_nBlockSequenceId
RecursiveMutex cs_nBlockSequenceId
Every received block is assigned a unique and increasing identifier, so we know which one to give pri...
Definition: validation.h:537
IsBlockPruned
bool IsBlockPruned(const CBlockIndex *pblockindex)
Check whether the block associated with this index entry is pruned or not.
Definition: validation.h:1017
CChainState::PreciousBlock
bool PreciousBlock(BlockValidationState &state, const CChainParams &params, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
Mark a block as precious and reorganize.
Definition: validation.cpp:2818
DisconnectResult
DisconnectResult
Definition: validation.h:335
CChainState::CoinsErrorCatcher
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:627
GUARDED_BY
ChainstateManager g_chainman GUARDED_BY(::cs_main)
DEPRECATED! Please use node.chainman instead.
CChainState::CoinsTip
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:613
ChainstateActive
CChainState & ChainstateActive()
Please prefer the identical ChainstateManager::ActiveChainstate.
Definition: validation.cpp:108
txdb.h
SnapshotMetadata
Metadata describing a serialized version of a UTXO set from which an assumeutxo CChainState can be co...
Definition: utxo_snapshot.h:14
UpdateCoins
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
Definition: validation.cpp:1318
ChainstateManager::m_load_block
std::thread m_load_block
Definition: validation.h:864
CBlockUndo
Undo information for a CBlock.
Definition: undo.h:63
BlockManager::InsertBlockIndex
CBlockIndex * InsertBlockIndex(const uint256 &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Create a new block index entry for a given block hash.
Definition: validation.cpp:3915
SynchronizationState::POST_INIT
@ POST_INIT
CChainState::m_chain
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:596
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:4956
BlockManager::Unload
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Clear all data members.
Definition: validation.cpp:3990
g_best_block
uint256 g_best_block
Definition: validation.cpp:136
RNGLevel::PERIODIC
@ PERIODIC
Called by RandAddPeriodic()
BlockMap
std::unordered_map< uint256, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:111
DEFAULT_CHECKBLOCKS
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:91
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:3284
fsbridge
Filesystem operations and types.
Definition: fs.cpp:22
CChainState::InvalidChainFound
void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1271