Bitcoin ABC 0.30.9
P2P Digital Currency
validation.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-2019 The Bitcoin Core developers
3// Copyright (c) 2017-2020 The Bitcoin developers
4// Distributed under the MIT software license, see the accompanying
5// file COPYING or http://www.opensource.org/licenses/mit-license.php.
6
7#ifndef BITCOIN_VALIDATION_H
8#define BITCOIN_VALIDATION_H
9
10#if defined(HAVE_CONFIG_H)
11#include <config/bitcoin-config.h>
12#endif
13
14#include <arith_uint256.h>
15#include <attributes.h>
16#include <blockfileinfo.h>
18#include <chain.h>
19#include <common/bloom.h>
20#include <config.h>
21#include <consensus/amount.h>
22#include <consensus/consensus.h>
23#include <deploymentstatus.h>
24#include <disconnectresult.h>
25#include <flatfile.h>
26#include <kernel/chainparams.h>
28#include <kernel/cs_main.h>
29#include <node/blockstorage.h>
30#include <policy/packages.h>
31#include <script/script_error.h>
33#include <shutdown.h>
34#include <sync.h>
35#include <txdb.h>
36#include <txmempool.h> // For CTxMemPool::cs
37#include <uint256.h>
38#include <util/check.h>
39#include <util/fs.h>
40#include <util/result.h>
41#include <util/translation.h>
42
43#include <atomic>
44#include <cstdint>
45#include <map>
46#include <memory>
47#include <optional>
48#include <set>
49#include <string>
50#include <thread>
51#include <type_traits>
52#include <utility>
53#include <vector>
54
56class CChainParams;
57class Chainstate;
59class CScriptCheck;
60class CTxMemPool;
61class CTxUndo;
63
64struct ChainTxData;
65struct FlatFilePos;
67struct LockPoints;
68struct AssumeutxoData;
69namespace node {
70class SnapshotMetadata;
71} // namespace node
72namespace Consensus {
73struct Params;
74} // namespace Consensus
75namespace avalanche {
76class Processor;
77} // namespace avalanche
78
79#define MIN_TRANSACTION_SIZE \
80 (::GetSerializeSize(CTransaction(), PROTOCOL_VERSION))
81
83static const int MAX_SCRIPTCHECK_THREADS = 15;
85static const int DEFAULT_SCRIPTCHECK_THREADS = 0;
86
87static const bool DEFAULT_PEERBLOOMFILTERS = true;
88
90static const int DEFAULT_STOPATHEIGHT = 0;
95static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
96static const signed int DEFAULT_CHECKBLOCKS = 6;
97static constexpr int DEFAULT_CHECKLEVEL{3};
111static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
112
115
117extern std::condition_variable g_best_block_cv;
119extern const CBlockIndex *g_best_block;
120
122extern const std::vector<std::string> CHECKLEVEL_DOC;
123
125private:
127 bool checkPoW : 1;
129
130public:
131 // Do full validation by default
132 explicit BlockValidationOptions(const Config &config);
133 explicit BlockValidationOptions(uint64_t _excessiveBlockSize,
134 bool _checkPow = true,
135 bool _checkMerkleRoot = true)
136 : excessiveBlockSize(_excessiveBlockSize), checkPoW(_checkPow),
137 checkMerkleRoot(_checkMerkleRoot) {}
138
139 BlockValidationOptions withCheckPoW(bool _checkPoW = true) const {
140 BlockValidationOptions ret = *this;
141 ret.checkPoW = _checkPoW;
142 return ret;
143 }
144
146 withCheckMerkleRoot(bool _checkMerkleRoot = true) const {
147 BlockValidationOptions ret = *this;
148 ret.checkMerkleRoot = _checkMerkleRoot;
149 return ret;
150 }
151
152 bool shouldValidatePoW() const { return checkPoW; }
154 uint64_t getExcessiveBlockSize() const { return excessiveBlockSize; }
155};
156
160void StartScriptCheckWorkerThreads(int threads_num);
161
166
167Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams);
168
169bool AbortNode(BlockValidationState &state, const std::string &strMessage,
170 const bilingual_str &userMessage = bilingual_str{});
171
176double GuessVerificationProgress(const ChainTxData &data,
177 const CBlockIndex *pindex);
178
180void PruneBlockFilesManual(Chainstate &active_chainstate,
181 int nManualPruneHeight);
182
183// clang-format off
206// clang-format on
209 enum class ResultType {
211 VALID,
213 INVALID,
215 MEMPOOL_ENTRY,
216 };
219
222
227 const std::optional<int64_t> m_vsize;
229 const std::optional<Amount> m_base_fees;
237 const std::optional<CFeeRate> m_effective_feerate;
244 const std::optional<std::vector<TxId>> m_txids_fee_calculations;
245
247 return MempoolAcceptResult(state);
248 }
249
251 FeeFailure(TxValidationState state, CFeeRate effective_feerate,
252 const std::vector<TxId> &txids_fee_calculations) {
253 return MempoolAcceptResult(state, effective_feerate,
254 txids_fee_calculations);
255 }
256
259 Success(int64_t vsize, Amount fees, CFeeRate effective_feerate,
260 const std::vector<TxId> &txids_fee_calculations) {
261 return MempoolAcceptResult(ResultType::VALID, vsize, fees,
262 effective_feerate, txids_fee_calculations);
263 }
264
269 static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees) {
270 return MempoolAcceptResult(vsize, fees);
271 }
272
273 // Private constructors. Use static methods MempoolAcceptResult::Success,
274 // etc. to construct.
275private:
278 : m_result_type(ResultType::INVALID), m_state(state),
279 m_base_fees(std::nullopt) {
280 // Can be invalid or error
281 Assume(!state.IsValid());
282 }
283
286 ResultType result_type, int64_t vsize, Amount fees,
287 CFeeRate effective_feerate,
288 const std::vector<TxId> &txids_fee_calculations)
289 : m_result_type(result_type), m_vsize{vsize}, m_base_fees(fees),
290 m_effective_feerate(effective_feerate),
291 m_txids_fee_calculations(txids_fee_calculations) {}
292
295 TxValidationState state, CFeeRate effective_feerate,
296 const std::vector<TxId> &txids_fee_calculations)
297 : m_result_type(ResultType::INVALID), m_state(state),
298 m_effective_feerate(effective_feerate),
299 m_txids_fee_calculations(txids_fee_calculations) {}
300
302 explicit MempoolAcceptResult(int64_t vsize, Amount fees)
303 : m_result_type(ResultType::MEMPOOL_ENTRY), m_vsize{vsize},
304 m_base_fees(fees) {}
305};
306
319 std::map<TxId, MempoolAcceptResult> m_tx_results;
320
323 std::map<TxId, MempoolAcceptResult> &&results)
324 : m_state{state}, m_tx_results(std::move(results)) {}
325
330 explicit PackageMempoolAcceptResult(const TxId &txid,
331 const MempoolAcceptResult &result)
332 : m_tx_results{{txid, result}} {}
333};
334
358AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx,
359 int64_t accept_time, bool bypass_limits,
360 bool test_accept = false, unsigned int heightOverride = 0)
362
375ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool,
376 const Package &txns, bool test_accept)
378
384protected:
385 std::atomic<int64_t> remaining;
386
387public:
388 explicit CheckInputsLimiter(int64_t limit) : remaining(limit) {}
389
390 bool consume_and_check(int consumed) {
391 auto newvalue = (remaining -= consumed);
392 return newvalue >= 0;
393 }
394
395 bool check() { return remaining >= 0; }
396};
397
399public:
401
402 // Let's make this bad boy copiable.
404 : CheckInputsLimiter(rhs.remaining.load()) {}
405
407 remaining = rhs.remaining.load();
408 return *this;
409 }
410
412 TxSigCheckLimiter txLimiter;
413 // Historically, there has not been a transaction with more than 20k sig
414 // checks on testnet or mainnet, so this effectively disable sigchecks.
415 txLimiter.remaining = 20000;
416 return txLimiter;
417 }
418};
419
449bool CheckInputScripts(const CTransaction &tx, TxValidationState &state,
450 const CCoinsViewCache &view, const uint32_t flags,
451 bool sigCacheStore, bool scriptCacheStore,
452 const PrecomputedTransactionData &txdata,
453 int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks,
454 CheckInputsLimiter *pBlockLimitSigChecks,
455 std::vector<CScriptCheck> *pvChecks)
457
461static inline bool
462CheckInputScripts(const CTransaction &tx, TxValidationState &state,
463 const CCoinsViewCache &view, const uint32_t flags,
464 bool sigCacheStore, bool scriptCacheStore,
465 const PrecomputedTransactionData &txdata, int &nSigChecksOut)
467 TxSigCheckLimiter nSigChecksTxLimiter;
468 return CheckInputScripts(tx, state, view, flags, sigCacheStore,
469 scriptCacheStore, txdata, nSigChecksOut,
470 nSigChecksTxLimiter, nullptr, nullptr);
471}
472
476void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
477 int nHeight);
478
482void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo,
483 int nHeight);
484
503std::optional<LockPoints> CalculateLockPointsAtTip(CBlockIndex *tip,
504 const CCoinsView &coins_view,
505 const CTransaction &tx);
506
516bool CheckSequenceLocksAtTip(CBlockIndex *tip, const LockPoints &lock_points);
517
526private:
528 const CTransaction *ptxTo;
529 unsigned int nIn;
530 uint32_t nFlags;
537
538public:
539 CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn,
540 unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn,
541 const PrecomputedTransactionData &txdataIn,
542 TxSigCheckLimiter *pTxLimitSigChecksIn = nullptr,
543 CheckInputsLimiter *pBlockLimitSigChecksIn = nullptr)
544 : m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn),
545 cacheStore(cacheIn), txdata(txdataIn),
546 pTxLimitSigChecks(pTxLimitSigChecksIn),
547 pBlockLimitSigChecks(pBlockLimitSigChecksIn) {}
548
549 CScriptCheck(const CScriptCheck &) = delete;
553
554 bool operator()();
555
556 ScriptError GetScriptError() const { return error; }
557
559};
560
561// CScriptCheck is used a lot in std::vector, make sure that's efficient
562static_assert(std::is_nothrow_move_assignable_v<CScriptCheck>);
563static_assert(std::is_nothrow_move_constructible_v<CScriptCheck>);
564static_assert(std::is_nothrow_destructible_v<CScriptCheck>);
565
574bool CheckBlock(const CBlock &block, BlockValidationState &state,
575 const Consensus::Params &params,
576 BlockValidationOptions validationOptions);
577
585 const CBlockIndex &active_chain_tip, const Consensus::Params &params,
586 const CTransaction &tx, TxValidationState &state)
588
594 BlockValidationState &state, const CChainParams &params,
595 Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev,
596 const std::function<NodeClock::time_point()> &adjusted_time_callback,
598
602bool HasValidProofOfWork(const std::vector<CBlockHeader> &headers,
603 const Consensus::Params &consensusParams);
604
606arith_uint256 CalculateHeadersWork(const std::vector<CBlockHeader> &headers);
607
608enum class VerifyDBResult {
609 SUCCESS,
611 INTERRUPTED,
614};
615
621private:
623
624public:
626
627public:
628 explicit CVerifyDB(kernel::Notifications &notifications);
629 ~CVerifyDB();
630
631 [[nodiscard]] VerifyDBResult VerifyDB(Chainstate &chainstate,
632 CCoinsView &coinsview,
633 int nCheckLevel, int nCheckDepth)
635};
636
639
650public:
654
658
661 std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
662
671 CoinsViews(DBParams db_params, CoinsViewOptions options);
672
674 void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
675};
676
679 CRITICAL = 2,
681 LARGE = 1,
682 OK = 0
683};
684
700protected:
706
713 mutable std::atomic<bool> m_cached_finished_ibd{false};
714
718
721 std::unique_ptr<CoinsViews> m_coins_views;
722
735 bool m_disabled GUARDED_BY(::cs_main){false};
736
738
743 const CBlockIndex *m_avalancheFinalizedBlockIndex
744 GUARDED_BY(cs_avalancheFinalizedBlockIndex) = nullptr;
745
752 CRollingBloomFilter m_filterParkingPoliciesApplied =
753 CRollingBloomFilter{1000, 0.000001};
754
755 CBlockIndex const *m_best_fork_tip = nullptr;
756 CBlockIndex const *m_best_fork_base = nullptr;
757
759 const CBlockIndex *m_cached_snapshot_base GUARDED_BY(::cs_main){nullptr};
760
761public:
765
770
771 explicit Chainstate(
772 CTxMemPool *mempool, node::BlockManager &blockman,
773 ChainstateManager &chainman,
774 std::optional<BlockHash> from_snapshot_blockhash = std::nullopt);
775
782 void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe,
783 std::string leveldb_name = "chainstate");
784
787 void InitCoinsCache(size_t cache_size_bytes)
789
795 return m_coins_views && m_coins_views->m_cacheview;
796 }
797
801
808 const std::optional<BlockHash> m_from_snapshot_blockhash{};
809
815 const CBlockIndex *SnapshotBase() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
816
824 std::set<CBlockIndex *, CBlockIndexWorkComparator> setBlockIndexCandidates;
825
829 Assert(m_coins_views);
830 return *Assert(m_coins_views->m_cacheview);
831 }
832
836 return Assert(m_coins_views)->m_dbview;
837 }
838
840 CTxMemPool *GetMempool() { return m_mempool; }
841
847 return Assert(m_coins_views)->m_catcherview;
848 }
849
851 void ResetCoinsViews() { m_coins_views.reset(); }
852
854 bool HasCoinsViews() const { return (bool)m_coins_views; }
855
857 size_t m_coinsdb_cache_size_bytes{0};
858
860 size_t m_coinstip_cache_size_bytes{0};
861
864 bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
866
878 bool FlushStateToDisk(BlockValidationState &state, FlushStateMode mode,
879 int nManualPruneHeight = 0);
880
882 void ForceFlushStateToDisk();
883
886 void PruneAndFlush();
887
908 bool ActivateBestChain(BlockValidationState &state,
909 std::shared_ptr<const CBlock> pblock = nullptr,
910 avalanche::Processor *const avalanche = nullptr)
911 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
912 !cs_avalancheFinalizedBlockIndex)
914
915 // Block (dis)connection on a given view:
916 DisconnectResult DisconnectBlock(const CBlock &block,
917 const CBlockIndex *pindex,
918 CCoinsViewCache &view)
920 bool ConnectBlock(const CBlock &block, BlockValidationState &state,
921 CBlockIndex *pindex, CCoinsViewCache &view,
923 Amount *blockFees = nullptr, bool fJustCheck = false)
925
926 // Apply the effects of a block disconnection on the UTXO set.
927 bool DisconnectTip(BlockValidationState &state,
928 DisconnectedBlockTransactions *disconnectpool)
930
931 // Manual block validity manipulation:
937 bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex,
938 avalanche::Processor *const avalanche = nullptr)
939 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
940 !cs_avalancheFinalizedBlockIndex)
943 bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex)
945 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
946 !cs_avalancheFinalizedBlockIndex);
948 bool ParkBlock(BlockValidationState &state, CBlockIndex *pindex)
950 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex,
951 !cs_avalancheFinalizedBlockIndex);
952
956 bool AvalancheFinalizeBlock(CBlockIndex *pindex,
957 avalanche::Processor &avalanche)
958 EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
959
963 void ClearAvalancheFinalizedBlock()
964 EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
965
969 bool IsBlockAvalancheFinalized(const CBlockIndex *pindex) const
970 EXCLUSIVE_LOCKS_REQUIRED(!cs_avalancheFinalizedBlockIndex);
971
973 void ResetBlockFailureFlags(CBlockIndex *pindex)
975 template <typename F>
976 bool UpdateFlagsForBlock(CBlockIndex *pindexBase, CBlockIndex *pindex, F f)
978 template <typename F, typename C, typename AC>
979 void UpdateFlags(CBlockIndex *pindex, CBlockIndex *&pindexReset, F f,
980 C fChild, AC fAncestorWasChanged)
982
984 void UnparkBlockAndChildren(CBlockIndex *pindex)
986
988 void UnparkBlock(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
989
991 bool ReplayBlocks();
992
997 bool LoadGenesisBlock();
998
999 void TryAddBlockIndexCandidate(CBlockIndex *pindex)
1001
1002 void PruneBlockIndexCandidates();
1003
1004 void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1005
1010 bool IsInitialBlockDownload() const;
1011
1013 const CBlockIndex *FindForkInGlobalIndex(const CBlockLocator &locator) const
1015
1017 void
1018 LoadMempool(const fs::path &load_path,
1019 fsbridge::FopenFn mockable_fopen_function = fsbridge::fopen);
1020
1023 bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1024
1028 CoinsCacheSizeState GetCoinsCacheSizeState()
1030
1032 GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes,
1033 size_t max_mempool_size_bytes)
1035
1037
1040 RecursiveMutex *MempoolMutex() const LOCK_RETURNED(m_mempool->cs) {
1041 return m_mempool ? &m_mempool->cs : nullptr;
1042 }
1043
1044private:
1045 bool ActivateBestChainStep(
1046 BlockValidationState &state, CBlockIndex *pindexMostWork,
1047 const std::shared_ptr<const CBlock> &pblock, bool &fInvalidFound,
1048 const avalanche::Processor *const avalanche = nullptr)
1050 !cs_avalancheFinalizedBlockIndex);
1051 bool ConnectTip(BlockValidationState &state,
1052 BlockPolicyValidationState &blockPolicyState,
1053 CBlockIndex *pindexNew,
1054 const std::shared_ptr<const CBlock> &pblock,
1055 DisconnectedBlockTransactions &disconnectpool,
1056 const avalanche::Processor *const avalanche = nullptr)
1058 !cs_avalancheFinalizedBlockIndex);
1059 void InvalidBlockFound(CBlockIndex *pindex,
1060 const BlockValidationState &state)
1061 EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1062 CBlockIndex *
1063 FindMostWorkChain(std::vector<const CBlockIndex *> &blocksToReconcile,
1064 bool fAutoUnpark)
1065 EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1066
1067 bool RollforwardBlock(const CBlockIndex *pindex, CCoinsViewCache &inputs)
1069
1070 void UnparkBlockImpl(CBlockIndex *pindex, bool fClearChildren)
1072
1073 bool UnwindBlock(BlockValidationState &state, CBlockIndex *pindex,
1074 bool invalidate)
1075 EXCLUSIVE_LOCKS_REQUIRED(m_chainstate_mutex,
1076 !cs_avalancheFinalizedBlockIndex);
1077
1078 void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1079 void CheckForkWarningConditionsOnNewFork(CBlockIndex *pindexNewForkTip)
1081 void InvalidChainFound(CBlockIndex *pindexNew)
1082 EXCLUSIVE_LOCKS_REQUIRED(cs_main, !cs_avalancheFinalizedBlockIndex);
1083
1084 const CBlockIndex *FindBlockToFinalize(CBlockIndex *pindexNew)
1086
1090 void UpdateTip(const CBlockIndex *pindexNew)
1092
1093 std::chrono::microseconds m_last_write{0};
1094 std::chrono::microseconds m_last_flush{0};
1095
1100 [[nodiscard]] util::Result<void> InvalidateCoinsDBOnDisk()
1102
1104};
1105
1107 SUCCESS,
1108 SKIPPED,
1109
1110 // Expected assumeutxo configuration data is not found for the height of the
1111 // base block.
1113
1114 // Failed to generate UTXO statistics (to check UTXO set hash) for the
1115 // background chainstate.
1117
1118 // The UTXO set hash of the background validation chainstate does not match
1119 // the one expected by assumeutxo chainparams.
1121
1122 // The blockhash of the current tip of the background validation chainstate
1123 // does not match the one expected by the snapshot chainstate.
1125};
1126
1155private:
1171 std::unique_ptr<Chainstate> m_ibd_chainstate GUARDED_BY(::cs_main);
1172
1182 std::unique_ptr<Chainstate> m_snapshot_chainstate GUARDED_BY(::cs_main);
1183
1193 Chainstate *m_active_chainstate GUARDED_BY(::cs_main){nullptr};
1194
1195 CBlockIndex *m_best_invalid GUARDED_BY(::cs_main){nullptr};
1196 CBlockIndex *m_best_parked GUARDED_BY(::cs_main){nullptr};
1197
1199 [[nodiscard]] bool
1200 PopulateAndValidateSnapshot(Chainstate &snapshot_chainstate,
1201 AutoFile &coins_file,
1202 const node::SnapshotMetadata &metadata);
1211 bool AcceptBlockHeader(
1212 const CBlockHeader &block, BlockValidationState &state,
1213 CBlockIndex **ppindex, bool min_pow_checked,
1214 const std::optional<CCheckpointData> &test_checkpoints = std::nullopt)
1217
1219 const CBlockIndex *GetSnapshotBaseBlock() const
1221
1224 std::optional<int> GetSnapshotBaseHeight() const
1226
1232 bool IsUsable(const Chainstate *const pchainstate) const
1234 return pchainstate && !pchainstate->m_disabled;
1235 }
1236
1238 SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main){};
1239
1240public:
1242
1243 explicit ChainstateManager(Options options,
1244 node::BlockManager::Options blockman_options);
1245
1246 const Config &GetConfig() const { return m_options.config; }
1247
1248 const CChainParams &GetParams() const {
1249 return m_options.config.GetChainParams();
1250 }
1252 return m_options.config.GetChainParams().GetConsensus();
1253 }
1255 return *Assert(m_options.check_block_index);
1256 }
1258 return *Assert(m_options.minimum_chain_work);
1259 }
1261 return *Assert(m_options.assumed_valid_block);
1262 }
1264 return m_options.notifications;
1265 };
1266
1273 void CheckBlockIndex();
1274
1288 }
1289
1291 std::thread m_load_block;
1295
1301 std::atomic<int32_t> nBlockSequenceId{1};
1302
1304 int32_t nBlockReverseSequenceId = -1;
1306 arith_uint256 nLastPreciousChainwork = 0;
1307
1308 // Reset the memory-only sequence counters we use to track block arrival
1309 // (used by tests to reset state)
1312 nBlockSequenceId = 1;
1313 nBlockReverseSequenceId = -1;
1314 }
1315
1335 std::set<CBlockIndex *> m_failed_blocks;
1336
1341 CBlockIndex *m_best_header GUARDED_BY(::cs_main){nullptr};
1342
1345 int64_t m_total_coinstip_cache{0};
1346 //
1349 int64_t m_total_coinsdb_cache{0};
1350
1354 // constructor
1355 Chainstate &InitializeChainstate(CTxMemPool *mempool)
1357
1359 std::vector<Chainstate *> GetAll();
1360
1374 [[nodiscard]] bool ActivateSnapshot(AutoFile &coins_file,
1375 const node::SnapshotMetadata &metadata,
1376 bool in_memory);
1377
1385 SnapshotCompletionResult MaybeCompleteSnapshotValidation(
1386 std::function<void(bilingual_str)> shutdown_fnc =
1387 [](bilingual_str msg) { AbortNode(msg.original, msg); })
1389
1391 Chainstate &ActiveChainstate() const;
1393 return ActiveChainstate().m_chain;
1394 }
1395 int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) {
1396 return ActiveChain().Height();
1397 }
1399 return ActiveChain().Tip();
1400 }
1401
1404 return m_blockman.m_block_index;
1405 }
1406
1409 bool IsSnapshotActive() const;
1410
1411 std::optional<BlockHash> SnapshotBlockhash() const;
1412
1415 return m_snapshot_chainstate && m_ibd_chainstate &&
1416 m_ibd_chainstate->m_disabled;
1417 }
1449 void LoadExternalBlockFile(FILE *fileIn, FlatFilePos *dbp = nullptr,
1450 std::multimap<BlockHash, FlatFilePos>
1451 *blocks_with_unknown_parent = nullptr,
1452 avalanche::Processor *const avalanche = nullptr);
1453
1481 bool ProcessNewBlock(const std::shared_ptr<const CBlock> &block,
1482 bool force_processing, bool min_pow_checked,
1483 bool *new_block,
1484 avalanche::Processor *const avalanche = nullptr)
1486
1502 bool ProcessNewBlockHeaders(
1503 const std::vector<CBlockHeader> &block, bool min_pow_checked,
1504 BlockValidationState &state, const CBlockIndex **ppindex = nullptr,
1505 const std::optional<CCheckpointData> &test_checkpoints = std::nullopt)
1507
1526 bool AcceptBlock(const std::shared_ptr<const CBlock> &pblock,
1527 BlockValidationState &state, bool fRequested,
1528 const FlatFilePos *dbp, bool *fNewBlock,
1529 bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1530
1531 void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew,
1532 const FlatFilePos &pos)
1534
1543 [[nodiscard]] MempoolAcceptResult
1544 ProcessTransaction(const CTransactionRef &tx, bool test_accept = false)
1546
1549 bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1550
1553 void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1554
1561 void ReportHeadersPresync(const arith_uint256 &work, int64_t height,
1562 int64_t timestamp);
1563
1566 bool DetectSnapshotChainstate(CTxMemPool *mempool)
1568
1569 void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1570
1573 Chainstate &ActivateExistingSnapshot(CTxMemPool *mempool,
1574 BlockHash base_blockhash)
1576
1586 bool ValidatedSnapshotCleanup() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1587
1589 bool DumpRecentHeadersTime(const fs::path &filePath) const
1590 EXCLUSIVE_LOCKS_REQUIRED(GetMutex());
1592 bool LoadRecentHeadersTime(const fs::path &filePath)
1593 EXCLUSIVE_LOCKS_REQUIRED(GetMutex());
1594};
1595
1597template <typename DEP>
1598bool DeploymentActiveAfter(const CBlockIndex *pindexPrev,
1599 const ChainstateManager &chainman, DEP dep) {
1600 return DeploymentActiveAfter(pindexPrev, chainman.GetConsensus(), dep);
1601}
1602
1603template <typename DEP>
1605 const ChainstateManager &chainman, DEP dep) {
1606 return DeploymentActiveAt(index, chainman.GetConsensus(), dep);
1607}
1608
1616const AssumeutxoData *ExpectedAssumeutxo(const int height,
1617 const CChainParams &params);
1618
1619#endif // BITCOIN_VALIDATION_H
int flags
Definition: bitcoin-tx.cpp:541
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:19
#define Assert(val)
Identity function.
Definition: check.h:84
#define Assume(val)
Assume is the identity function.
Definition: check.h:97
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:528
uint64_t getExcessiveBlockSize() const
Definition: validation.h:154
BlockValidationOptions withCheckPoW(bool _checkPoW=true) const
Definition: validation.h:139
BlockValidationOptions(uint64_t _excessiveBlockSize, bool _checkPow=true, bool _checkMerkleRoot=true)
Definition: validation.h:133
BlockValidationOptions withCheckMerkleRoot(bool _checkMerkleRoot=true) const
Definition: validation.h:146
BlockValidationOptions(const Config &config)
Definition: validation.cpp:120
bool shouldValidatePoW() const
Definition: validation.h:152
uint64_t excessiveBlockSize
Definition: validation.h:126
bool shouldValidateMerkleRoot() const
Definition: validation.h:153
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:23
Definition: block.h:60
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
An in-memory indexed chain of blocks.
Definition: chain.h:134
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:80
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:221
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:65
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Definition: coins.h:374
Abstract view on the open txout dataset.
Definition: coins.h:163
Fee rate in satoshis per kilobyte: Amount / kB.
Definition: feerate.h:21
RollingBloomFilter is a probabilistic "keep track of most recently inserted" set.
Definition: bloom.h:115
Closure representing one script verification.
Definition: validation.h:525
CScriptCheck & operator=(CScriptCheck &&)=default
bool operator()()
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, unsigned int nInIn, uint32_t nFlagsIn, bool cacheIn, const PrecomputedTransactionData &txdataIn, TxSigCheckLimiter *pTxLimitSigChecksIn=nullptr, CheckInputsLimiter *pBlockLimitSigChecksIn=nullptr)
Definition: validation.h:539
ScriptError GetScriptError() const
Definition: validation.h:556
ScriptExecutionMetrics GetScriptExecutionMetrics() const
Definition: validation.h:558
CScriptCheck(const CScriptCheck &)=delete
uint32_t nFlags
Definition: validation.h:530
TxSigCheckLimiter * pTxLimitSigChecks
Definition: validation.h:535
ScriptExecutionMetrics metrics
Definition: validation.h:533
CTxOut m_tx_out
Definition: validation.h:527
CScriptCheck(CScriptCheck &&)=default
bool cacheStore
Definition: validation.h:531
ScriptError error
Definition: validation.h:532
PrecomputedTransactionData txdata
Definition: validation.h:534
const CTransaction * ptxTo
Definition: validation.h:528
unsigned int nIn
Definition: validation.h:529
CheckInputsLimiter * pBlockLimitSigChecks
Definition: validation.h:536
CScriptCheck & operator=(const CScriptCheck &)=delete
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:212
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:307
An output of a transaction.
Definition: transaction.h:128
Restore the UTXO in a Coin at a given COutPoint.
Definition: undo.h:62
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:620
VerifyDBResult VerifyDB(Chainstate &chainstate, CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
kernel::Notifications & m_notifications
Definition: validation.h:622
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:699
void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(
Initialize the in-memory coins cache (to be done after the health of the on-disk database is verified...
Definition: validation.h:793
Mutex m_chainstate_mutex
The ChainState Mutex.
Definition: validation.h:705
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:800
bool HasCoinsViews() const
Does this chainstate have a UTXO set attached?
Definition: validation.h:854
CTxMemPool * GetMempool()
Definition: validation.h:840
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: validation.h:844
Mutex cs_avalancheFinalizedBlockIndex
Definition: validation.h:737
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:717
bool m_disabled GUARDED_BY(::cs_main)
This toggle exists for use when doing background validation for UTXO snapshots.
Definition: validation.h:735
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:834
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:769
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:721
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:851
const CBlockIndex *m_avalancheFinalizedBlockIndex GUARDED_BY(cs_avalancheFinalizedBlockIndex)
The best block via avalanche voting.
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Definition: validation.h:764
const CBlockIndex *m_cached_snapshot_base GUARDED_BY(::cs_main)
Cached result of LookupBlockIndex(*m_from_snapshot_blockhash)
Definition: validation.h:759
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:1154
std::unique_ptr< Chainstate > m_ibd_chainstate GUARDED_BY(::cs_main)
The chainstate used under normal operation (i.e.
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1402
CBlockIndex *m_best_header GUARDED_BY(::cs_main)
Best header we've seen so far (used for getheaders queries' starting points).
Definition: validation.h:1341
const Config & GetConfig() const
Definition: validation.h:1246
kernel::Notifications & GetNotifications() const
Definition: validation.h:1263
SteadyMilliseconds m_last_presync_update GUARDED_BY(::cs_main)
Most recent headers presync progress update, for rate-limiting.
Definition: validation.h:1238
bool ShouldCheckBlockIndex() const
Definition: validation.h:1254
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1286
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1414
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1398
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Definition: validation.h:1195
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1395
const CChainParams & GetParams() const
Definition: validation.h:1248
const Consensus::Params & GetConsensus() const
Definition: validation.h:1251
CBlockIndex *m_best_parked GUARDED_BY(::cs_main)
Definition: validation.h:1196
const arith_uint256 & MinimumChainWork() const
Definition: validation.h:1257
const Options m_options
Definition: validation.h:1290
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1392
Chainstate *m_active_chainstate GUARDED_BY(::cs_main)
Points to either the ibd or snapshot chainstate; indicates our most-work chain.
Definition: validation.h:1193
std::thread m_load_block
Definition: validation.h:1291
const BlockHash & AssumedValidBlock() const
Definition: validation.h:1260
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
Definition: validation.h:1359
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:1335
std::unique_ptr< Chainstate > m_snapshot_chainstate GUARDED_BY(::cs_main)
A chainstate initialized on the basis of a UTXO snapshot.
void ResetBlockSequenceCounters() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1310
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1294
Simple class for regulating resource usage during CheckInputScripts (and CScriptCheck),...
Definition: validation.h:383
bool consume_and_check(int consumed)
Definition: validation.h:390
std::atomic< int64_t > remaining
Definition: validation.h:385
CheckInputsLimiter(int64_t limit)
Definition: validation.h:388
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:649
std::unique_ptr< CCoinsViewCache > m_cacheview GUARDED_BY(cs_main)
This is the top layer of the cache hierarchy - it keeps as many coins in memory as can fit per the db...
CCoinsViewErrorCatcher m_catcherview GUARDED_BY(cs_main)
This view wraps access to the leveldb instance and handles read errors gracefully.
CCoinsViewDB m_dbview GUARDED_BY(cs_main)
The lowest level of the CoinsViews cache hierarchy sits in a leveldb database on disk.
CoinsViews(DBParams db_params, CoinsViewOptions options)
This constructor initializes CCoinsViewDB and CCoinsViewErrorCatcher instances, but it does not creat...
Definition: config.h:19
Different type to mark Mutex at global scope.
Definition: sync.h:144
static TxSigCheckLimiter getDisabled()
Definition: validation.h:411
TxSigCheckLimiter & operator=(const TxSigCheckLimiter &rhs)
Definition: validation.h:406
TxSigCheckLimiter(const TxSigCheckLimiter &rhs)
Definition: validation.h:403
bool IsValid() const
Definition: validation.h:119
256-bit unsigned big integer.
A base class defining functions for notifying about certain kernel events.
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:73
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:21
static const uint64_t MAX_TX_SIGCHECKS
Allowed number of signature check operations per transaction.
Definition: consensus.h:22
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
DisconnectResult
static void LoadExternalBlockFile(benchmark::Bench &bench)
The LoadExternalBlockFile() function is used during -reindex and -loadblock.
unsigned int nHeight
static void pool cs
Filesystem operations and types.
Definition: fs.h:20
Bridge operations to C stdio.
Definition: fs.cpp:28
FILE * fopen(const fs::path &p, const char *mode)
Definition: fs.cpp:30
std::function< FILE *(const fs::path &, const char *)> FopenFn
Definition: fs.h:198
bool LoadMempool(CTxMemPool &pool, const fs::path &load_path, Chainstate &active_chainstate, FopenFn mockable_fopen_function)
Definition: init.h:28
std::unordered_map< BlockHash, CBlockIndex, BlockHasher > BlockMap
Definition: blockstorage.h:59
Implement std::hash so RCUPtr can be used as a key for maps or sets.
Definition: rcu.h:259
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:40
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:315
@ PERIODIC
Called by RandAddPeriodic()
ScriptError
Definition: script_error.h:11
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:100
Definition: amount.h:19
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:46
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:105
Holds various statistics on transactions within a chain.
Definition: chainparams.h:67
User-controlled performance and debug options.
Definition: txdb.h:56
Parameters that influence chain consensus.
Definition: params.h:34
Application-specific storage settings.
Definition: dbwrapper.h:32
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition: validation.h:207
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigchecks.
Definition: validation.h:227
MempoolAcceptResult(ResultType result_type, int64_t vsize, Amount fees, CFeeRate effective_feerate, const std::vector< TxId > &txids_fee_calculations)
Generic constructor for success cases.
Definition: validation.h:285
const ResultType m_result_type
Result type.
Definition: validation.h:218
const std::optional< std::vector< TxId > > m_txids_fee_calculations
Contains the txids of the transactions used for fee-related checks.
Definition: validation.h:244
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:277
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:221
MempoolAcceptResult(TxValidationState state, CFeeRate effective_feerate, const std::vector< TxId > &txids_fee_calculations)
Constructor for fee-related failure case.
Definition: validation.h:294
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:209
@ VALID
Fully validated, valid.
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:246
const std::optional< CFeeRate > m_effective_feerate
The feerate at which this transaction was considered.
Definition: validation.h:237
static MempoolAcceptResult FeeFailure(TxValidationState state, CFeeRate effective_feerate, const std::vector< TxId > &txids_fee_calculations)
Definition: validation.h:251
static MempoolAcceptResult Success(int64_t vsize, Amount fees, CFeeRate effective_feerate, const std::vector< TxId > &txids_fee_calculations)
Constructor for success case.
Definition: validation.h:259
static MempoolAcceptResult MempoolTx(int64_t vsize, Amount fees)
Constructor for already-in-mempool case.
Definition: validation.h:269
MempoolAcceptResult(int64_t vsize, Amount fees)
Constructor for already-in-mempool case.
Definition: validation.h:302
const std::optional< Amount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:229
std::chrono::time_point< NodeClock > time_point
Definition: time.h:19
Validation result for package mempool acceptance.
Definition: validation.h:310
PackageMempoolAcceptResult(const TxId &txid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a MempoolAcceptResult.
Definition: validation.h:330
PackageMempoolAcceptResult(PackageValidationState state, std::map< TxId, MempoolAcceptResult > &&results)
Definition: validation.h:321
PackageValidationState m_state
Definition: validation.h:311
std::map< TxId, MempoolAcceptResult > m_tx_results
Map from txid to finished MempoolAcceptResults.
Definition: validation.h:319
Precompute sighash midstate to avoid quadratic hashing.
Definition: transaction.h:325
Struct for holding cumulative results from executing a script or a sequence of scripts.
A TxId is the identifier of a transaction.
Definition: txid.h:14
Bilingual messages:
Definition: translation.h:17
std::string original
Definition: translation.h:18
An options struct for BlockManager, more ergonomically referred to as BlockManager::Options due to th...
An options struct for ChainstateManager, more ergonomically referred to as ChainstateManager::Options...
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:56
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:55
#define LOCK_RETURNED(x)
Definition: threadsafety.h:54
std::chrono::time_point< std::chrono::steady_clock, std::chrono::milliseconds > SteadyMilliseconds
Definition: time.h:31
bool ContextualCheckTransactionForCurrentBlock(const CBlockIndex &active_chain_tip, const Consensus::Params &params, const CTransaction &tx, TxValidationState &state)
AssertLockHeld(pool.cs)
void StartScriptCheckWorkerThreads(int threads_num)
Run instances of script checking worker threads.
bool ContextualCheckTransactionForCurrentBlock(const CBlockIndex &active_chain_tip, const Consensus::Params &params, const CTransaction &tx, TxValidationState &state) EXCLUSIVE_LOCKS_REQUIRED(bool TestBlockValidity(BlockValidationState &state, const CChainParams &params, Chainstate &chainstate, const CBlock &block, CBlockIndex *pindexPrev, const std::function< NodeClock::time_point()> &adjusted_time_callback, BlockValidationOptions validationOptions) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
This is a variant of ContextualCheckTransaction which computes the contextual check for a transaction...
Definition: validation.h:593
GlobalMutex g_best_block_mutex
Definition: validation.cpp:116
Amount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
std::condition_variable g_best_block_cv
Definition: validation.cpp:117
std::optional< LockPoints > CalculateLockPointsAtTip(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx)
Calculate LockPoints required to check if transaction will be BIP68 final in the next block to be cre...
Definition: validation.cpp:183
static constexpr int DEFAULT_CHECKLEVEL
Definition: validation.h:97
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &txns, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Validate (and maybe submit) a package to the mempool.
arith_uint256 CalculateHeadersWork(const std::vector< CBlockHeader > &headers)
Return the sum of the work on a given set of headers.
double GuessVerificationProgress(const ChainTxData &data, const CBlockIndex *pindex)
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev?...
Definition: validation.h:111
bool CheckSequenceLocksAtTip(CBlockIndex *tip, const LockPoints &lock_points)
Check if transaction will be BIP68 final in the next block to be created on top of tip.
Definition: validation.cpp:207
bool CheckInputScripts(const CTransaction &tx, TxValidationState &state, const CCoinsViewCache &view, const uint32_t flags, bool sigCacheStore, bool scriptCacheStore, const PrecomputedTransactionData &txdata, int &nSigChecksOut, TxSigCheckLimiter &txLimitSigChecks, CheckInputsLimiter *pBlockLimitSigChecks, std::vector< CScriptCheck > *pvChecks) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Check whether all of this transaction's input scripts succeed.
static const unsigned int MIN_BLOCKS_TO_KEEP
Block files containing a block-height within MIN_BLOCKS_TO_KEEP of ActiveChain().Tip() will not be pr...
Definition: validation.h:95
const CBlockIndex * g_best_block
Used to notify getblocktemplate RPC of new tips.
Definition: validation.cpp:118
bool HasValidProofOfWork(const std::vector< CBlockHeader > &headers, const Consensus::Params &consensusParams)
Check with the proof of work on each blockheader matches the value in nBits.
bool DeploymentActiveAfter(const CBlockIndex *pindexPrev, const ChainstateManager &chainman, DEP dep)
Deployment* info via ChainstateManager.
Definition: validation.h:1598
SnapshotCompletionResult
Definition: validation.h:1106
static const int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:83
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:114
static const int DEFAULT_SCRIPTCHECK_THREADS
-par default (number of script-checking threads, 0 = auto)
Definition: validation.h:85
bool AbortNode(BlockValidationState &state, const std::string &strMessage, const bilingual_str &userMessage=bilingual_str{})
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept=false, unsigned int heightOverride=0) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the mempool.
void StopScriptCheckWorkerThreads()
Stop all of the script checking worker threads.
VerifyDBResult
Definition: validation.h:608
void SpendCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
Mark all the coins corresponding to a given transaction inputs as spent.
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &params, BlockValidationOptions validationOptions)
Functions for validating blocks and updating the block tree.
const std::vector< std::string > CHECKLEVEL_DOC
Documentation for argument 'checklevel'.
Definition: validation.cpp:98
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
CoinsCacheSizeState
Definition: validation.h:677
@ LARGE
The cache is at >= 90% capacity.
@ CRITICAL
The coins cache is in immediate need of a flush.
bool DeploymentActiveAt(const CBlockIndex &index, const ChainstateManager &chainman, DEP dep)
Definition: validation.h:1604
void UpdateCoins(CCoinsViewCache &view, const CTransaction &tx, CTxUndo &txundo, int nHeight)
Apply the effects of this transaction on the UTXO set represented by view.
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:96
FlushStateMode
Definition: validation.h:638
const AssumeutxoData * ExpectedAssumeutxo(const int height, const CChainParams &params)
Return the expected assumeutxo value for a given height, if one exists.
static const bool DEFAULT_PEERBLOOMFILTERS
Definition: validation.h:87
static const int DEFAULT_STOPATHEIGHT
Default for -stopatheight.
Definition: validation.h:90