Bitcoin ABC  0.24.7
P2P Digital Currency
validation.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2019 The Bitcoin Core developers
3 // Copyright (c) 2017-2020 The Bitcoin developers
4 // Distributed under the MIT software license, see the accompanying
5 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
6 
7 #ifndef BITCOIN_VALIDATION_H
8 #define BITCOIN_VALIDATION_H
9 
10 #if defined(HAVE_CONFIG_H)
11 #include <config/bitcoin-config.h>
12 #endif
13 
14 #include <amount.h>
15 #include <blockfileinfo.h>
17 #include <coins.h>
18 #include <consensus/consensus.h>
19 #include <disconnectresult.h>
20 #include <flatfile.h>
21 #include <fs.h>
22 #include <protocol.h> // For CMessageHeader::MessageMagic
23 #include <script/script_error.h>
24 #include <script/script_metrics.h>
25 #include <sync.h>
26 #include <txdb.h>
27 #include <txmempool.h> // For CTxMemPool::cs
28 #include <versionbits.h>
29 
30 #include <atomic>
31 #include <cstdint>
32 #include <map>
33 #include <memory>
34 #include <optional>
35 #include <set>
36 #include <string>
37 #include <utility>
38 #include <vector>
39 
41 class CBlockIndex;
42 class CBlockTreeDB;
43 class CBlockUndo;
44 class CChainParams;
45 class CChain;
46 class CChainState;
47 class CConnman;
48 class CInv;
49 class ChainstateManager;
50 class Config;
51 class CScriptCheck;
52 class CTxMemPool;
53 class CTxUndo;
55 class TxValidationState;
56 
57 struct ChainTxData;
58 struct FlatFilePos;
60 struct LockPoints;
61 
62 namespace Consensus {
63 struct Params;
64 }
65 
66 #define MIN_TRANSACTION_SIZE \
67  (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))
68 
77 static const unsigned int DEFAULT_MEMPOOL_EXPIRY = 336;
79 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
81 static const int MAX_SCRIPTCHECK_THREADS = 15;
83 static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
84 static const int64_t DEFAULT_MAX_TIP_AGE = 24 * 60 * 60;
85 static const bool DEFAULT_CHECKPOINTS_ENABLED = true;
86 static const bool DEFAULT_TXINDEX = false;
87 static const char *const DEFAULT_BLOCKFILTERINDEX = "0";
88 
90 static const bool DEFAULT_PERSIST_MEMPOOL = true;
92 static const bool DEFAULT_FEEFILTER = true;
93 
94 static const bool DEFAULT_PEERBLOOMFILTERS = true;
95 
97 static const int DEFAULT_STOPATHEIGHT = 0;
99 static const int DEFAULT_MAX_REORG_DEPTH = 10;
106 static const int64_t DEFAULT_MIN_FINALIZATION_DELAY = 2 * 60 * 60;
111 static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
112 static const signed int DEFAULT_CHECKBLOCKS = 6;
113 static const unsigned int DEFAULT_CHECKLEVEL = 3;
127 static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
128 
131 
132 extern RecursiveMutex cs_main;
133 typedef std::unordered_map<BlockHash, CBlockIndex *, BlockHasher> BlockMap;
135 extern std::condition_variable g_best_block_cv;
136 extern uint256 g_best_block;
137 extern std::atomic_bool fImporting;
138 extern std::atomic_bool fReindex;
139 extern bool fRequireStandard;
140 extern bool fCheckBlockIndex;
141 extern bool fCheckpointsEnabled;
142 
147 extern CFeeRate minRelayTxFee;
152 extern int64_t nMaxTipAge;
153 
159 
164 
169 
172 extern bool fHavePruned;
174 extern bool fPruneMode;
176 extern uint64_t nPruneTarget;
178 extern const std::vector<std::string> CHECKLEVEL_DOC;
179 
181 private:
183  bool checkPoW : 1;
184  bool checkMerkleRoot : 1;
185 
186 public:
187  // Do full validation by default
188  explicit BlockValidationOptions(const Config &config);
189  explicit BlockValidationOptions(uint64_t _excessiveBlockSize,
190  bool _checkPow = true,
191  bool _checkMerkleRoot = true)
192  : excessiveBlockSize(_excessiveBlockSize), checkPoW(_checkPow),
193  checkMerkleRoot(_checkMerkleRoot) {}
194 
195  BlockValidationOptions withCheckPoW(bool _checkPoW = true) const {
196  BlockValidationOptions ret = *this;
197  ret.checkPoW = _checkPoW;
198  return ret;
199  }
200 
202  withCheckMerkleRoot(bool _checkMerkleRoot = true) const {
203  BlockValidationOptions ret = *this;
204  ret.checkMerkleRoot = _checkMerkleRoot;
205  return ret;
206  }
207 
208  bool shouldValidatePoW() const { return checkPoW; }
209  bool shouldValidateMerkleRoot() const { return checkMerkleRoot; }
210  uint64_t getExcessiveBlockSize() const { return excessiveBlockSize; }
211 };
212 
216 void LoadExternalBlockFile(const Config &config, FILE *fileIn,
217  FlatFilePos *dbp = nullptr);
218 
223 bool LoadGenesisBlock(const CChainParams &chainparams);
224 
228 void UnloadBlockIndex(CTxMemPool *mempool, ChainstateManager &chainman);
229 
233 void ThreadScriptCheck(int worker_num);
234 
250 CTransactionRef GetTransaction(const CBlockIndex *const block_index,
251  const CTxMemPool *const mempool,
252  const TxId &txid,
253  const Consensus::Params &consensusParams,
254  BlockHash &hashBlock);
261 bool ActivateBestChain(
262  const Config &config, BlockValidationState &state,
263  std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>());
264 Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams);
265 
270 double GuessVerificationProgress(const ChainTxData &data,
271  const CBlockIndex *pindex);
272 
276 uint64_t CalculateCurrentUsage();
277 
281 void UnlinkPrunedFiles(const std::set<int> &setFilesToPrune);
282 
284 void PruneBlockFilesManual(int nManualPruneHeight);
285 
290 bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool,
291  TxValidationState &state, const CTransactionRef &tx,
292  bool bypass_limits, bool test_accept = false,
293  Amount *fee_out = nullptr)
295 
301 protected:
302  std::atomic<int64_t> remaining;
303 
304 public:
305  explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {}
306 
307  bool consume_and_check(int consumed) {
308  auto newvalue = (remaining -= consumed);
309  return newvalue >= 0;
310  }
311 
312  bool check() { return remaining >= 0; }
313 };
314 
316 public:
318 
319  // Let's make this bad boy copiable.
321  : CheckInputsLimiter(rhs.remaining.load()) {}
322 
324  remaining = rhs.remaining.load();
325  return *this;
326  }
327 
329  TxSigCheckLimiter txLimiter;
330  // Historically, there has not been a transaction with more than 20k sig
331  // checks on testnet or mainnet, so this effectively disable sigchecks.
332  txLimiter.remaining = 20000;
333  return txLimiter;
334  }
335 };
336 
337 class ConnectTrace;
338 
368 bool CheckInputScripts(const CTransaction &tx, TxValidationState &state,
369  const CCoinsViewCache &view, const uint32_t flags,
370  bool sigCacheStore, bool scriptCacheStore,
371  const PrecomputedTransactionData &txdata,
372  int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks,
373  CheckInputsLimiter *pBlockLimitSigChecks,
374  std::vector<CScriptCheck> *pvChecks)
376 
380 static inline bool
382  const CCoinsViewCache &view, const uint32_t flags,
383  bool sigCacheStore, bool scriptCacheStore,
384  const PrecomputedTransactionData &txdata, int &nSigChecksOut)
386  TxSigCheckLimiter nSigChecksTxLimiter;
387  return CheckInputScripts(tx, state, view, flags, sigCacheStore,
388  scriptCacheStore, txdata, nSigChecksOut,
389  nSigChecksTxLimiter, nullptr, nullptr);
390 }
391 
395 
399  const CBlockIndex *pindex);
400 
407 
414 
416 void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight);
417 
421 void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
422  int nHeight);
423 
427 void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, int nHeight);
428 void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
429  int nHeight);
430 
437 
449 bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx,
450  int flags, LockPoints *lp = nullptr,
451  bool useExistingLockPoints = false)
453 
462 private:
465  unsigned int nIn;
466  uint32_t nFlags;
473 
474 public:
476  : ptxTo(nullptr), nIn(0), nFlags(0), cacheStore(false),
477  error(ScriptError::UNKNOWN), txdata(), pTxLimitSigChecks(nullptr),
478  pBlockLimitSigChecks(nullptr) {}
479 
480  CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn,
481  unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn,
482  const PrecomputedTransactionData &txdataIn,
483  TxSigCheckLimiter *pTxLimitSigChecksIn = nullptr,
484  CheckInputsLimiter *pBlockLimitSigChecksIn = nullptr)
485  : m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn),
486  cacheStore(cacheIn), error(ScriptError::UNKNOWN), txdata(txdataIn),
487  pTxLimitSigChecks(pTxLimitSigChecksIn),
488  pBlockLimitSigChecks(pBlockLimitSigChecksIn) {}
489 
490  bool operator()();
491 
492  void swap(CScriptCheck &check) {
493  std::swap(ptxTo, check.ptxTo);
494  std::swap(m_tx_out, check.m_tx_out);
495  std::swap(nIn, check.nIn);
496  std::swap(nFlags, check.nFlags);
497  std::swap(cacheStore, check.cacheStore);
498  std::swap(error, check.error);
499  std::swap(metrics, check.metrics);
500  std::swap(txdata, check.txdata);
501  std::swap(pTxLimitSigChecks, check.pTxLimitSigChecks);
502  std::swap(pBlockLimitSigChecks, check.pBlockLimitSigChecks);
503  }
504 
505  ScriptError GetScriptError() const { return error; }
506 
508 };
509 
510 bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex);
511 
520 bool CheckBlock(const CBlock &block, BlockValidationState &state,
521  const Consensus::Params &params,
522  BlockValidationOptions validationOptions);
523 
531  const CTransaction &tx,
532  TxValidationState &state,
533  int flags = -1)
535 
540 bool TestBlockValidity(BlockValidationState &state, const CChainParams &params,
541  const CBlock &block, CBlockIndex *pindexPrev,
542  BlockValidationOptions validationOptions)
544 
549 class CVerifyDB {
550 public:
551  CVerifyDB();
552  ~CVerifyDB();
553  bool VerifyDB(const Config &config, CCoinsView *coinsview, int nCheckLevel,
554  int nCheckDepth);
555 };
556 
559 
562  const CBlockLocator &locator)
564 
567 
570 extern std::unique_ptr<CCoinsViewCache> pcoinsTip;
571 
580  friend CChainState;
581 
582 private:
587  void FindFilesToPruneManual(std::set<int> &setFilesToPrune,
588  int nManualPruneHeight, int chain_tip_height);
589 
611  void FindFilesToPrune(std::set<int> &setFilesToPrune,
612  uint64_t nPruneAfterHeight, int chain_tip_height,
613  bool is_ibd);
614 
615 public:
616  BlockMap m_block_index GUARDED_BY(cs_main);
617 
637  std::set<CBlockIndex *> m_failed_blocks;
638 
644  std::multimap<CBlockIndex *, CBlockIndex *> m_blocks_unlinked;
645 
654  bool LoadBlockIndex(const Consensus::Params &consensus_params,
655  CBlockTreeDB &blocktree,
656  std::set<CBlockIndex *, CBlockIndexWorkComparator>
657  &block_index_candidates)
659 
662 
668 
670  void PruneOneBlockFile(const int fileNumber)
672 
678  bool AcceptBlockHeader(const Config &config, const CBlockHeader &block,
679  BlockValidationState &state, CBlockIndex **ppindex)
681 
683 };
684 
694 class CoinsViews {
695 public:
698  CCoinsViewDB m_dbview GUARDED_BY(cs_main);
699 
703 
706  std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
707 
716  CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory,
717  bool should_wipe);
718 
720  void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
721 };
722 
725  CRITICAL = 2,
727  LARGE = 1,
728  OK = 0
729 };
730 
745 class CChainState {
746 private:
753 
759  std::atomic<int32_t> nBlockSequenceId{1};
764 
771  mutable std::atomic<bool> m_cached_finished_ibd{false};
772 
777 
780 
783  std::unique_ptr<CoinsViews> m_coins_views;
784 
789  const CBlockIndex *m_finalizedBlockIndex GUARDED_BY(cs_main) = nullptr;
790 
791 public:
792  explicit CChainState(CTxMemPool &mempool, BlockManager &blockman,
793  BlockHash from_snapshot_blockhash = BlockHash());
794 
801  void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe,
802  std::string leveldb_name = "chainstate");
803 
806  void InitCoinsCache(size_t cache_size_bytes)
808 
812  bool CanFlushToDisk() EXCLUSIVE_LOCKS_REQUIRED(cs_main) {
813  return m_coins_views && m_coins_views->m_cacheview;
814  }
815 
819 
827 
834  std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates;
835 
838  assert(m_coins_views->m_cacheview);
839  return *m_coins_views->m_cacheview.get();
840  }
841 
843  CCoinsViewDB &CoinsDB() { return m_coins_views->m_dbview; }
844 
849  return m_coins_views->m_catcherview;
850  }
851 
853  void ResetCoinsViews() { m_coins_views.reset(); }
854 
857 
860 
863  bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
865 
877  bool FlushStateToDisk(const CChainParams &chainparams,
879  int nManualPruneHeight = 0);
880 
882  void ForceFlushStateToDisk();
883 
886  void PruneAndFlush();
887 
902  bool ActivateBestChain(
903  const Config &config, BlockValidationState &state,
904  std::shared_ptr<const CBlock> pblock = std::shared_ptr<const CBlock>())
906 
907  bool AcceptBlock(const Config &config,
908  const std::shared_ptr<const CBlock> &pblock,
909  BlockValidationState &state, bool fRequested,
910  const FlatFilePos *dbp, bool *fNewBlock)
912 
913  // Block (dis)connection on a given view:
915  const CBlockIndex *pindex,
916  CCoinsViewCache &view);
917  bool ConnectBlock(const CBlock &block, BlockValidationState &state,
918  CBlockIndex *pindex, CCoinsViewCache &view,
919  const CChainParams &params,
920  BlockValidationOptions options, bool fJustCheck = false)
922 
923  // Block disconnection on our pcoinsTip:
924  bool DisconnectTip(const CChainParams &params, BlockValidationState &state,
925  DisconnectedBlockTransactions *disconnectpool)
927 
928  // Manual block validity manipulation:
929  bool PreciousBlock(const Config &config, BlockValidationState &state,
932  bool InvalidateBlock(const Config &config, BlockValidationState &state,
936  bool ParkBlock(const Config &config, BlockValidationState &state,
939 
944  bool FinalizeBlock(const Config &config, BlockValidationState &state,
948  const CBlockIndex *GetFinalizedBlock() const
953  bool IsBlockFinalized(const CBlockIndex *pindex) const
955 
956  void ResetBlockFailureFlags(CBlockIndex *pindex)
958  template <typename F>
959  bool UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f)
961  template <typename F, typename C, typename AC>
962  void UpdateFlags(CBlockIndex *pindex, CBlockIndex *&pindexReset, F f,
963  C fChild, AC fAncestorWasChanged)
966  void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren)
968 
970  bool ReplayBlocks(const Consensus::Params &params);
971  bool LoadGenesisBlock(const CChainParams &chainparams);
972 
974 
976 
981  bool IsInitialBlockDownload() const;
982 
989  void CheckBlockIndex(const Consensus::Params &consensusParams);
990 
992  void LoadMempool(const Config &config, const ArgsManager &args);
993 
996  bool LoadChainTip(const CChainParams &chainparams)
998 
1002  CoinsCacheSizeState GetCoinsCacheSizeState(const CTxMemPool *tx_pool)
1004 
1005  CoinsCacheSizeState GetCoinsCacheSizeState(
1006  const CTxMemPool *tx_pool, size_t max_coins_cache_size_bytes,
1007  size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1008 
1009  std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1010 
1011 private:
1012  bool ActivateBestChainStep(const Config &config,
1013  BlockValidationState &state,
1014  CBlockIndex *pindexMostWork,
1015  const std::shared_ptr<const CBlock> &pblock,
1016  bool &fInvalidFound, ConnectTrace &connectTrace)
1018  bool ConnectTip(const Config &config, BlockValidationState &state,
1019  CBlockIndex *pindexNew,
1020  const std::shared_ptr<const CBlock> &pblock,
1021  ConnectTrace &connectTrace,
1022  DisconnectedBlockTransactions &disconnectpool)
1024  void InvalidBlockFound(CBlockIndex *pindex,
1025  const BlockValidationState &state)
1027  void InvalidChainFound(CBlockIndex *pindexNew)
1031  const CBlockIndex *pindex)
1033  void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew,
1034  const FlatFilePos &pos)
1036 
1037  bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs,
1038  const Consensus::Params &params)
1040  bool UnwindBlock(const Config &config, BlockValidationState &state,
1041  CBlockIndex *pindex, bool invalidate)
1043 
1045 };
1046 
1052 bool PreciousBlock(const Config &config, BlockValidationState &state,
1054 
1056 void ResetBlockFailureFlags(CBlockIndex *pindex)
1058 
1060 void UnparkBlockAndChildren(CBlockIndex *pindex)
1062 
1065 
1100 private:
1118  std::unique_ptr<CChainState> m_ibd_chainstate;
1119 
1131  std::unique_ptr<CChainState> m_snapshot_chainstate;
1132 
1144  CChainState *m_active_chainstate{nullptr};
1145 
1148  bool m_snapshot_validated{false};
1149 
1150  // For access to m_active_chainstate.
1151  friend CChainState &ChainstateActive();
1152  friend CChain &ChainActive();
1153 
1154 public:
1158 
1161  int64_t m_total_coinstip_cache{0};
1162  //
1165  int64_t m_total_coinsdb_cache{0};
1166 
1171  // constructor
1174  CChainState &
1175  InitializeChainstate(CTxMemPool &mempool,
1176  const BlockHash &snapshot_blockhash = BlockHash())
1178 
1180  std::vector<CChainState *> GetAll();
1181 
1183  CChainState &ActiveChainstate() const;
1184  CChain &ActiveChain() const { return ActiveChainstate().m_chain; }
1185  int ActiveHeight() const { return ActiveChain().Height(); }
1186  CBlockIndex *ActiveTip() const { return ActiveChain().Tip(); }
1187 
1189  return m_blockman.m_block_index;
1190  }
1191 
1192  bool IsSnapshotActive() const;
1193 
1194  std::optional<BlockHash> SnapshotBlockhash() const;
1195 
1197  bool IsSnapshotValidated() const { return m_snapshot_validated; }
1198 
1201  bool IsBackgroundIBD(CChainState *chainstate) const;
1202 
1207  CChainState &ValidatedChainstate() const;
1208 
1209  CChain &ValidatedChain() const { return ValidatedChainstate().m_chain; }
1210  CBlockIndex *ValidatedTip() const { return ValidatedChain().Tip(); }
1211 
1235  bool ProcessNewBlock(const Config &config,
1236  const std::shared_ptr<const CBlock> pblock,
1237  bool fForceProcessing, bool *fNewBlock)
1239 
1254  bool ProcessNewBlockHeaders(const Config &config,
1255  const std::vector<CBlockHeader> &block,
1256  BlockValidationState &state,
1257  const CBlockIndex **ppindex = nullptr)
1259 
1262  bool LoadBlockIndex(const Consensus::Params &params)
1264 
1266  void Unload() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1267 
1269  void Reset();
1270 
1273  void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1274 };
1275 
1281 
1284 
1286 CChain &ChainActive();
1287 
1291 extern std::unique_ptr<CBlockTreeDB> pblocktree;
1292 
1299 int GetSpendHeight(const CCoinsViewCache &inputs);
1300 
1304 int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev,
1305  const Consensus::Params &params);
1306 
1308 CBlockFileInfo *GetBlockFileInfo(size_t n);
1309 
1311 bool DumpMempool(const CTxMemPool &pool);
1312 
1314 bool LoadMempool(const Config &config, CTxMemPool &pool);
1315 
1317 bool IsBlockPruned(const CBlockIndex *pblockindex);
1318 
1319 #endif // BITCOIN_VALIDATION_H
DEFAULT_MAX_REORG_DEPTH
static const int DEFAULT_MAX_REORG_DEPTH
Default for -maxreorgdepth.
Definition: validation.h:99
TxSigCheckLimiter::TxSigCheckLimiter
TxSigCheckLimiter()
Definition: validation.h:317
CChainState::CChainState
CChainState(CTxMemPool &mempool, BlockManager &blockman, BlockHash from_snapshot_blockhash=BlockHash())
Definition: validation.cpp:872
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:4826
ThreadScriptCheck
void ThreadScriptCheck(int worker_num)
Run an instance of the script checking thread.
Definition: validation.cpp:1501
CChainState::ConnectTip
bool ConnectTip(const Config &config, 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:2527
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:4504
SpendCoins
void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
Mark all the coins corresponding to a given transaction inputs as spent.
Definition: validation.cpp:1071
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:2651
CCoinsViewDB
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:53
ChainstateManager::BlockIndex
BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1188
CChainState::LoadMempool
void LoadMempool(const Config &config, const ArgsManager &args)
Load the persisted mempool from disk.
Definition: validation.cpp:4819
DEFAULT_MIN_RELAY_TX_FEE_PER_KB
static const Amount DEFAULT_MIN_RELAY_TX_FEE_PER_KB(1000 *SATOSHI)
Default for -minrelaytxfee, minimum relay fee for transactions.
ScriptError
ScriptError
Definition: script_error.h:11
ToString
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:69
FlushStateMode::ALWAYS
@ ALWAYS
DEFAULT_CHECKLEVEL
static const unsigned int DEFAULT_CHECKLEVEL
Definition: validation.h:113
fCheckBlockIndex
bool fCheckBlockIndex
Definition: validation.cpp:114
CChainState::DisconnectTip
bool DisconnectTip(const CChainParams &params, BlockValidationState &state, DisconnectedBlockTransactions *disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Disconnect m_chain's tip.
Definition: validation.cpp:2320
CChainState::ForceFlushStateToDisk
void ForceFlushStateToDisk()
Unconditionally flush all changes to disk.
Definition: validation.cpp:2264
DEFAULT_PERSIST_MEMPOOL
static const bool DEFAULT_PERSIST_MEMPOOL
Default for -persistmempool.
Definition: validation.h:90
BlockManager::InsertBlockIndex
CBlockIndex * InsertBlockIndex(const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Create a new block index entry for a given block hash.
Definition: validation.cpp:4651
LoadExternalBlockFile
void LoadExternalBlockFile(const Config &config, FILE *fileIn, FlatFilePos *dbp=nullptr)
Import blocks from an external file.
Definition: validation.cpp:5245
CChainState::UpdateFlagsForBlock
bool UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3423
GetSpendHeight
int GetSpendHeight(const CCoinsViewCache &inputs)
Return the spend height, which is one more than the inputs.GetBestBlock().
Definition: validation.cpp:1126
TestBlockValidity
bool TestBlockValidity(BlockValidationState &state, const CChainParams &params, const CBlock &block, CBlockIndex *pindexPrev, BlockValidationOptions validationOptions) 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:4447
TxSigCheckLimiter::operator=
TxSigCheckLimiter & operator=(const TxSigCheckLimiter &rhs)
Definition: validation.h:323
CoinsCacheSizeState::OK
@ OK
fs.h
nHeight
unsigned int nHeight
Definition: mempool_eviction.cpp:13
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:22
BlockValidationState
Definition: validation.h:138
flags
int flags
Definition: bitcoin-tx.cpp:532
CTxUndo
Restore the UTXO in a Coin at a given COutPoint.
Definition: undo.h:62
FlushStateMode::NONE
@ NONE
CChainState::nBlockSequenceId
std::atomic< int32_t > nBlockSequenceId
Every received block is assigned a unique and increasing identifier, so we know which one to give pri...
Definition: validation.h:759
pblocktree
std::unique_ptr< CBlockTreeDB > pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: validation.cpp:176
CChainState::CheckBlockIndex
void CheckBlockIndex(const Consensus::Params &consensusParams)
Make various assertions about the state of the block index.
Definition: validation.cpp:5405
CoinsCacheSizeState::CRITICAL
@ CRITICAL
The coins cache is in immediate need of a flush.
sync.h
LookupBlockIndex
CBlockIndex * LookupBlockIndex(const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:150
CChainState::PreciousBlock
bool PreciousBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main)
Definition: validation.cpp:3131
UnlinkPrunedFiles
void UnlinkPrunedFiles(const std::set< int > &setFilesToPrune)
Actually unlink the specified files.
Definition: validation.cpp:4537
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:117
Consensus::DeploymentPos
DeploymentPos
Definition: params.h:16
GetBlockFileInfo
CBlockFileInfo * GetBlockFileInfo(size_t n)
Get block file info entry for one block file.
Definition: validation.cpp:5772
CTxMemPool
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:495
ChainstateManager::ValidatedChain
CChain & ValidatedChain() const
Definition: validation.h:1209
MAX_SCRIPTCHECK_THREADS
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:81
DEFAULT_MIN_FINALIZATION_DELAY
static const int64_t DEFAULT_MIN_FINALIZATION_DELAY
Default for -finalizationdelay This is the minimum time between a block header reception and the bloc...
Definition: validation.h:106
blockindexworkcomparator.h
arith_uint256
256-bit unsigned big integer.
Definition: arith_uint256.h:285
TxSigCheckLimiter::getDisabled
static TxSigCheckLimiter getDisabled()
Definition: validation.h:328
CScriptCheck::GetScriptExecutionMetrics
ScriptExecutionMetrics GetScriptExecutionMetrics() const
Definition: validation.h:507
flatfile.h
BlockManager::GUARDED_BY
BlockMap m_block_index GUARDED_BY(cs_main)
GetBlockSubsidy
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
Definition: validation.cpp:849
CScriptCheck::ptxTo
const CTransaction * ptxTo
Definition: validation.h:464
CHECKLEVEL_DOC
const std::vector< std::string > CHECKLEVEL_DOC
Documentation for argument 'checklevel'.
Definition: validation.cpp:69
g_best_block_mutex
Mutex g_best_block_mutex
Definition: validation.cpp:106
CChainState::UnloadBlockIndex
void UnloadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:5159
DEFAULT_MEMPOOL_EXPIRY
static const unsigned int DEFAULT_MEMPOOL_EXPIRY
Default for -mempoolexpiry, expiration time for mempool transactions in hours.
Definition: validation.h:77
CChainState::PruneBlockIndexCandidates
void PruneBlockIndexCandidates()
Delete all entries in setBlockIndexCandidates that are worse than the current tip.
Definition: validation.cpp:2817
CoinsCacheSizeState::LARGE
@ LARGE
The cache is at >= 90% capacity.
DEFAULT_STOPATHEIGHT
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:97
CChainParams
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:47
fPruneMode
bool fPruneMode
True if we're running in -prune mode.
Definition: validation.cpp:112
MAX_TX_SIGCHECKS
static const uint64_t MAX_TX_SIGCHECKS
Allowed number of signature check operations per transaction.
Definition: consensus.h:22
CChainState::GetFinalizedBlock
const CBlockIndex * GetFinalizedBlock() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Return the currently finalized block index.
Definition: validation.cpp:3537
fCheckpointsEnabled
bool fCheckpointsEnabled
Definition: validation.cpp:115
AnnotatedMixin< std::recursive_mutex >
UndoReadFromDisk
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
Definition: validation.cpp:1267
CheckInputsLimiter::remaining
std::atomic< int64_t > remaining
Definition: validation.h:302
CalculateCurrentUsage
uint64_t CalculateCurrentUsage()
Calculate the amount of disk space the block & undo files currently use.
Definition: validation.cpp:4493
CChainState::InvalidBlockFound
void InvalidBlockFound(CBlockIndex *pindex, const BlockValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1061
CChainState::CoinsDB
CCoinsViewDB & CoinsDB()
Definition: validation.h:843
BlockValidationOptions::shouldValidatePoW
bool shouldValidatePoW() const
Definition: validation.h:208
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:4672
FlushStateMode
FlushStateMode
Definition: validation.h:566
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:111
CInv
Inv(ventory) message data.
Definition: protocol.h:492
BlockManager
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: validation.h:579
BlockMap
std::unordered_map< BlockHash, CBlockIndex *, BlockHasher > BlockMap
Definition: validation.h:133
BlockValidationOptions
Definition: validation.h:180
CheckSequenceLocks
bool CheckSequenceLocks(const CTxMemPool &pool, const CTransaction &tx, int flags, LockPoints *lp, bool useExistingLockPoints)
Definition: validation.cpp:200
ComputeBlockVersion
int32_t ComputeBlockVersion(const CBlockIndex *pindexPrev, const Consensus::Params &params)
Determine what nVersion a new block should use.
Definition: validation.cpp:1508
DisconnectResult
DisconnectResult
Definition: disconnectresult.h:8
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:752
BlockManager::FindFilesToPrune
void FindFilesToPrune(std::set< int > &setFilesToPrune, uint64_t nPruneAfterHeight, int chain_tip_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:4585
CFeeRate
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
CChainState::m_cached_finished_ibd
std::atomic< bool > m_cached_finished_ibd
Whether this chainstate is undergoing initial block download.
Definition: validation.h:771
CheckBlock
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &params, BlockValidationOptions validationOptions)
Functions for validating blocks and updating the block tree.
Definition: validation.cpp:3753
CTransaction
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:194
DEFAULT_PEERBLOOMFILTERS
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:94
cs
static void pool cs
Definition: mempool_eviction.cpp:11
DEFAULT_FEEFILTER
static const bool DEFAULT_FEEFILTER
Default for using fee filter.
Definition: validation.h:92
BlockValidationOptions::BlockValidationOptions
BlockValidationOptions(uint64_t _excessiveBlockSize, bool _checkPow=true, bool _checkMerkleRoot=true)
Definition: validation.h:189
CScriptCheck::nIn
unsigned int nIn
Definition: validation.h:465
Amount::zero
static constexpr Amount zero()
Definition: amount.h:42
CChainState::ResetCoinsViews
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:853
txmempool.h
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:637
CCoinsView
Abstract view on the open txout dataset.
Definition: coins.h:175
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:834
CoinsCacheSizeState
CoinsCacheSizeState
Definition: validation.h:723
TxValidationState
Definition: validation.h:137
CheckInputsLimiter::consume_and_check
bool consume_and_check(int consumed)
Definition: validation.h:307
SATOSHI
static constexpr Amount SATOSHI
Definition: amount.h:153
Consensus::Params
Parameters that influence chain consensus.
Definition: params.h:59
Config
Definition: config.h:17
ChainstateManager::ValidatedTip
CBlockIndex * ValidatedTip() const
Definition: validation.h:1210
CChainState::UnwindBlock
bool UnwindBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex, bool invalidate) EXCLUSIVE_LOCKS_REQUIRED(m_cs_chainstate)
Definition: validation.cpp:3175
protocol.h
MAX_BLOCKFILE_SIZE
static const unsigned int MAX_BLOCKFILE_SIZE
The maximum size of a blk?????.dat file (since 0.8)
Definition: validation.h:79
BlockManager::FindFilesToPruneManual
void FindFilesToPruneManual(std::set< int > &setFilesToPrune, int nManualPruneHeight, int chain_tip_height)
Calculate the block/rev files to delete based on height specified by user with RPC command pruneblock...
Definition: validation.cpp:4546
CheckInputsLimiter::check
bool check()
Definition: validation.h:312
CScriptCheck::swap
void swap(CScriptCheck &check)
Definition: validation.h:492
BlockValidationOptions::withCheckMerkleRoot
BlockValidationOptions withCheckMerkleRoot(bool _checkMerkleRoot=true) const
Definition: validation.h:202
CScriptCheck::CScriptCheck
CScriptCheck()
Definition: validation.h:475
CheckInputsLimiter::CheckInputsLimiter
CheckInputsLimiter(int64_t limit)
Definition: validation.h:305
fRequireStandard
bool fRequireStandard
Definition: validation.cpp:113
ActivateBestChain
bool ActivateBestChain(const Config &config, BlockValidationState &state, std::shared_ptr< const CBlock > pblock=std::shared_ptr< const CBlock >())
Find the best known block, and make it the tip of the block chain.
Definition: validation.cpp:3125
CChainState::PruneAndFlush
void PruneAndFlush()
Prune blockfiles from the disk if necessary and then flush chainstate changes if we pruned.
Definition: validation.cpp:2273
CChainState::IsBlockFinalized
bool IsBlockFinalized(const CBlockIndex *pindex) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Checks if a block is finalized.
Definition: validation.cpp:3530
CScriptCheck::GetScriptError
ScriptError GetScriptError() const
Definition: validation.h:505
CTxOut
An output of a transaction.
Definition: transaction.h:130
Consensus
Definition: blockdb.h:10
ChainstateManager::ActiveTip
CBlockIndex * ActiveTip() const
Definition: validation.h:1186
VersionBitsTipStatistics
BIP9Stats VersionBitsTipStatistics(const Consensus::Params &params, Consensus::DeploymentPos pos)
Get the numerical statistics for the BIP9 state for a given deployment at the current tip.
Definition: validation.cpp:5798
BlockValidationOptions::getExcessiveBlockSize
uint64_t getExcessiveBlockSize() const
Definition: validation.h:210
BlockValidationOptions::shouldValidateMerkleRoot
bool shouldValidateMerkleRoot() const
Definition: validation.h:209
nPruneTarget
uint64_t nPruneTarget
Number of MiB of block files that we're trying to stay below.
Definition: validation.cpp:116
CChainState::AcceptBlock
bool AcceptBlock(const Config &config, const std::shared_ptr< const CBlock > &pblock, BlockValidationState &state, bool fRequested, const FlatFilePos *dbp, bool *fNewBlock) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Store a block on disk.
Definition: validation.cpp:4241
FlatFilePos
Definition: flatfile.h:14
CChainState::LoadGenesisBlock
bool LoadGenesisBlock(const CChainParams &chainparams)
Definition: validation.cpp:5214
DEFAULT_CHECKPOINTS_ENABLED
static const bool DEFAULT_CHECKPOINTS_ENABLED
Definition: validation.h:85
ChainstateManager::ActiveHeight
int ActiveHeight() const
Definition: validation.h:1185
minRelayTxFee
CFeeRate minRelayTxFee
A fee rate smaller than this is considered zero fee (for relaying, mining and transaction creation)
Definition: validation.cpp:122
ChainstateManager::IsSnapshotValidated
bool IsSnapshotValidated() const
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1197
CChainState::UpdateFlags
void UpdateFlags(CBlockIndex *pindex, CBlockIndex *&pindexReset, F f, C fChild, AC fAncestorWasChanged) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3447
ChainTxData
Holds various statistics on transactions within a chain.
Definition: chainparams.h:34
consensus.h
ContextualCheckTransactionForCurrentBlock
bool ContextualCheckTransactionForCurrentBlock(const Consensus::Params &params, const CTransaction &tx, TxValidationState &state, int flags=-1) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
This is a variant of ContextualCheckTransaction which computes the contextual check for a transaction...
Definition: validation.cpp:3922
DEFAULT_MAX_TIP_AGE
static const int64_t DEFAULT_MAX_TIP_AGE
Definition: validation.h:84
CChainState::nLastPreciousChainwork
arith_uint256 nLastPreciousChainwork
chainwork for the last block that preciousblock has been applied to.
Definition: validation.h:763
CChainState::GUARDED_BY
const CBlockIndex *m_finalizedBlockIndex GUARDED_BY(cs_main)
The best finalized block.
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:156
CBlockTreeDB
Access to the block database (blocks/index/)
Definition: txdb.h:105
g_chainman
ChainstateManager g_chainman
Definition: validation.cpp:78
SynchronizationState::INIT_REINDEX
@ INIT_REINDEX
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:644
ChainstateManager::m_snapshot_chainstate
std::unique_ptr< CChainState > m_snapshot_chainstate
A chainstate initialized on the basis of a UTXO snapshot.
Definition: validation.h:1131
cs_main
RecursiveMutex cs_main
Global state.
Definition: validation.cpp:103
ConnectTrace
Used to track blocks whose transactions were applied to the UTXO state as a part of a single Activate...
Definition: validation.cpp:2412
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:5987
script_metrics.h
versionbits.h
PrecomputedTransactionData
Precompute sighash midstate to avoid quadratic hashing.
Definition: transaction.h:329
CChainState::MarkBlockAsFinal
bool MarkBlockAsFinal(BlockValidationState &state, const CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:2441
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:783
uint256
256-bit opaque blob.
Definition: uint256.h:127
CScriptCheck::txdata
PrecomputedTransactionData txdata
Definition: validation.h:470
TxId
A TxId is the identifier of a transaction.
Definition: txid.h:14
CScriptCheck::error
ScriptError error
Definition: validation.h:468
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:745
TxSigCheckLimiter::TxSigCheckLimiter
TxSigCheckLimiter(const TxSigCheckLimiter &rhs)
Definition: validation.h:320
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:1362
fHavePruned
bool fHavePruned
Pruning-related variables and constants.
Definition: validation.cpp:111
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:3589
Amount
Definition: amount.h:19
BlockValidationOptions::withCheckPoW
BlockValidationOptions withCheckPoW(bool _checkPoW=true) const
Definition: validation.h:195
CChainState::m_from_snapshot_blockhash
const BlockHash m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from.
Definition: validation.h:826
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:856
CheckInputScripts
bool CheckInputScripts(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &view, const uint32_t flags, bool sigCacheStore, bool scriptCacheStore, const PrecomputedTransactionData &txdata, int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks, CheckInputsLimiter *pBlockLimitSigChecks, std::vector< CScriptCheck > *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check whether all of this transaction's input scripts succeed.
Definition: validation.cpp:1132
coins.h
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:86
VersionBitsBlockState
ThresholdState VersionBitsBlockState(const Consensus::Params &params, Consensus::DeploymentPos pos, const CBlockIndex *pindex)
Get the BIP9 state for a given deployment at a given block.
Definition: validation.cpp:5791
BlockHash
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
ChainstateManager
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1099
CVerifyDB
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:549
GetTransaction
CTransactionRef GetTransaction(const CBlockIndex *const block_index, const CTxMemPool *const mempool, const TxId &txid, const Consensus::Params &consensusParams, BlockHash &hashBlock)
Return transaction from the block at block_index.
Definition: validation.cpp:786
CChainState::cs
bool m_mempool cs
Definition: validation.h:926
TxSigCheckLimiter
Definition: validation.h:315
UnparkBlockAndChildren
void UnparkBlockAndChildren(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove parked status from a block and its descendants.
Definition: validation.cpp:3522
CChainState::ParkBlock
bool ParkBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_chainstate)
Park a block.
Definition: validation.cpp:3370
BIP9Stats
Display status of an in-progress BIP9 softfork.
Definition: versionbits.h:44
CBlock
Definition: block.h:55
CScriptCheck::pBlockLimitSigChecks
CheckInputsLimiter * pBlockLimitSigChecks
Definition: validation.h:472
CChainState::IsInitialBlockDownload
bool IsInitialBlockDownload() const
Check whether we are doing an initial block download (synchronizing from disk or network)
Definition: validation.cpp:897
CConnman
Definition: net.h:221
UnloadBlockIndex
void UnloadBlockIndex(CTxMemPool *mempool, ChainstateManager &chainman)
Unload database information.
Definition: validation.cpp:5170
BlockManager::AcceptBlockHeader
bool AcceptBlockHeader(const Config &config, const CBlockHeader &block, BlockValidationState &state, 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:4050
CChain
An in-memory indexed chain of blocks.
Definition: chain.h:152
MIN_DISK_SPACE_FOR_BLOCK_FILES
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev?...
Definition: validation.h:127
hashAssumeValid
BlockHash hashAssumeValid
Block hash whose ancestors we will assume to have valid scripts without checking them.
Definition: validation.cpp:119
LOCKS_EXCLUDED
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:55
CChainState::nBlockReverseSequenceId
int32_t nBlockReverseSequenceId
Decreasing counter (used by subsequent preciousblock calls).
Definition: validation.h:761
CScriptCheck::nFlags
uint32_t nFlags
Definition: validation.h:466
BlockManager::AddToBlockIndex
CBlockIndex * AddToBlockIndex(const CBlockHeader &block) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3542
SynchronizationState::INIT_DOWNLOAD
@ INIT_DOWNLOAD
CCoinsViewCache
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:231
CheckInputsLimiter
Simple class for regulating resource usage during CheckInputScripts (and CScriptCheck),...
Definition: validation.h:300
ArgsManager
Definition: system.h:152
TestLockPointValidity
bool TestLockPointValidity(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:181
pcoinsTip
std::unique_ptr< CCoinsViewCache > pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
EXCLUSIVE_LOCKS_REQUIRED
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
script_error.h
CChainState::FinalizeBlock
bool FinalizeBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_chainstate)
Finalize a block.
Definition: validation.cpp:3379
CBlockFileInfo
Definition: blockfileinfo.h:13
LockPoints
Definition: txmempool.h:41
BlockValidationOptions::checkPoW
bool checkPoW
Definition: validation.h:183
g_best_block_cv
std::condition_variable g_best_block_cv
Definition: validation.cpp:107
CCoinsViewErrorCatcher
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Definition: coins.h:358
CChainState::m_blockman
BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all CChainState instances.
Definition: validation.h:776
CChainState::ConnectBlock
bool ConnectBlock(const CBlock &block, BlockValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, const CChainParams &params, BlockValidationOptions options, 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:1612
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:508
CTransactionRef
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:319
DEFAULT_UTXO_FEE
static const Amount DEFAULT_UTXO_FEE
Default for -excessutxocharge for transactions transactions.
Definition: validation.h:72
CScriptCheck
Check if transaction will be BIP 68 final in the next block to be created.
Definition: validation.h:461
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:877
CScriptCheck::cacheStore
bool cacheStore
Definition: validation.h:467
CChainState::RollforwardBlock
bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs, const Consensus::Params &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:5031
DEFAULT_BLOCKFILTERINDEX
static const char *const DEFAULT_BLOCKFILTERINDEX
Definition: validation.h:87
disconnectresult.h
fImporting
std::atomic_bool fImporting
LoadGenesisBlock
bool LoadGenesisBlock(const CChainParams &chainparams)
Ensures we have a genesis block in the block tree, possibly writing one to disk.
Definition: validation.cpp:5241
CChainState::ResetBlockFailureFlags
void ResetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:3478
DEFAULT_SCRIPTCHECK_THREADS
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:83
CScriptCheck::m_tx_out
CTxOut m_tx_out
Definition: validation.h:463
SynchronizationState
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:130
CoinsViews
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:694
pindexBestHeader
CBlockIndex * pindexBestHeader
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.cpp:105
DEFAULT_TXINDEX
static const bool DEFAULT_TXINDEX
Definition: validation.h:86
CScriptCheck::metrics
ScriptExecutionMetrics metrics
Definition: validation.h:469
lp
LockPoints lp
Definition: mempool_eviction.cpp:16
CChainState::m_mempool
CTxMemPool & m_mempool
mempool that is kept in sync with the chain
Definition: validation.h:779
CScriptCheck::pTxLimitSigChecks
TxSigCheckLimiter * pTxLimitSigChecks
Definition: validation.h:471
DisconnectedBlockTransactions
Definition: txmempool.h:981
ScriptExecutionMetrics
Struct for holding cumulative results from executing a script or a sequence of scripts.
Definition: script_metrics.h:12
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:48
BlockValidationOptions::checkMerkleRoot
bool checkMerkleRoot
Definition: validation.h:184
FlushStateMode::IF_NEEDED
@ IF_NEEDED
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:100
ThresholdState
ThresholdState
BIP 9 defines a finite-state-machine to deploy a softfork in multiple stages.
Definition: versionbits.h:26
nMinimumChainWork
arith_uint256 nMinimumChainWork
Minimum work we will assume exists on some valid chain.
Definition: validation.cpp:120
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:23
CChainState::ActivateBestChainStep
bool ActivateBestChainStep(const Config &config, 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:2838
AcceptToMemoryPool
bool AcceptToMemoryPool(const Config &config, CTxMemPool &pool, TxValidationState &state, const CTransactionRef &tx, bool bypass_limits, bool test_accept=false, Amount *fee_out=nullptr) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
(try to) add transaction to memory pool
Definition: validation.cpp:779
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:859
BlockManager::CChainState
friend CChainState
Definition: validation.h:580
VersionBitsTipState
ThresholdState VersionBitsTipState(const Consensus::Params &params, Consensus::DeploymentPos pos)
Get the BIP9 state for a given deployment at the current tip.
Definition: validation.cpp:5785
amount.h
CoinsViews::CoinsViews
CoinsViews(std::string ldb_name, size_t cache_size_bytes, bool in_memory, bool should_wipe)
This constructor initializes CCoinsViewDB and CCoinsViewErrorCatcher instances, but it does not creat...
Definition: validation.cpp:862
BlockValidity::UNKNOWN
@ UNKNOWN
Unused.
BlockValidationOptions::excessiveBlockSize
uint64_t excessiveBlockSize
Definition: validation.h:182
IsBlockPruned
bool IsBlockPruned(const CBlockIndex *pblockindex)
Check whether the block associated with this index entry is pruned or not.
Definition: validation.cpp:5978
CChainState::CoinsErrorCatcher
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:847
CChainState::CoinsTip
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:837
CChainState::ReplayBlocks
bool ReplayBlocks(const Consensus::Params &params)
Replay blocks that aren't fully applied to the database.
Definition: validation.cpp:5059
CScriptCheck::CScriptCheck
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn, const PrecomputedTransactionData &txdataIn, TxSigCheckLimiter *pTxLimitSigChecksIn=nullptr, CheckInputsLimiter *pBlockLimitSigChecksIn=nullptr)
Definition: validation.h:480
UnparkBlock
void UnparkBlock(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove parked status from a block.
Definition: validation.cpp:3526
CChainState::ActivateBestChain
bool ActivateBestChain(const Config &config, BlockValidationState &state, std::shared_ptr< const CBlock > pblock=std::shared_ptr< const CBlock >()) LOCKS_EXCLUDED(cs_main)
Make the best chain active, in multiple steps.
Definition: validation.cpp:2988
ChainstateActive
CChainState & ChainstateActive()
Please prefer the identical ChainstateManager::ActiveChainstate.
Definition: validation.cpp:80
txdb.h
blockfileinfo.h
PruneBlockFilesManual
void PruneBlockFilesManual(int nManualPruneHeight)
Prune block files up to a given height.
Definition: validation.cpp:4575
UpdateCoins
void UpdateCoins(const CTransaction &tx, CCoinsViewCache &inputs, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
CBlockUndo
Undo information for a CBlock.
Definition: undo.h:73
SynchronizationState::POST_INIT
@ POST_INIT
BlockValidationOptions::BlockValidationOptions
BlockValidationOptions(const Config &config)
Definition: validation.cpp:146
CChainState::m_chain
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:818
CChainState::UnparkBlockImpl
void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Remove parked status from a block and its descendants.
Definition: validation.cpp:3505
BlockManager::Unload
void Unload() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Clear all data members.
Definition: validation.cpp:4747
g_best_block
uint256 g_best_block
Definition: validation.cpp:108
RNGLevel::PERIODIC
@ PERIODIC
Called by RandAddPeriodic()
DEFAULT_CHECKBLOCKS
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:112
CChainState::InvalidateBlock
bool InvalidateBlock(const Config &config, BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(cs_main) EXCLUSIVE_LOCKS_REQUIRED(!m_cs_chainstate)
Mark a block as invalid.
Definition: validation.cpp:3360
VersionBitsTipStateSinceHeight
int VersionBitsTipStateSinceHeight(const Consensus::Params &params, Consensus::DeploymentPos pos)
Get the block height at which the BIP9 deployment switched into the state for the block building on t...
Definition: validation.cpp:5804
DumpMempool
bool DumpMempool(const CTxMemPool &pool)
Dump the mempool to disk.
Definition: validation.cpp:5915
ChainstateManager::m_ibd_chainstate
std::unique_ptr< CChainState > m_ibd_chainstate
The chainstate used under normal operation (i.e.
Definition: validation.h:1118
CChainState::InvalidChainFound
void InvalidChainFound(CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.cpp:1028