Bitcoin Core 30.99.0
P2P Digital Currency
validation.h
Go to the documentation of this file.
1// Copyright (c) 2009-2010 Satoshi Nakamoto
2// Copyright (c) 2009-present The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#ifndef BITCOIN_VALIDATION_H
7#define BITCOIN_VALIDATION_H
8
9#include <arith_uint256.h>
10#include <attributes.h>
11#include <chain.h>
12#include <checkqueue.h>
13#include <consensus/amount.h>
14#include <cuckoocache.h>
15#include <deploymentstatus.h>
16#include <kernel/chain.h>
17#include <kernel/chainparams.h>
19#include <kernel/cs_main.h> // IWYU pragma: export
20#include <node/blockstorage.h>
21#include <policy/feerate.h>
22#include <policy/packages.h>
23#include <policy/policy.h>
24#include <script/script_error.h>
25#include <script/sigcache.h>
26#include <script/verify_flags.h>
27#include <sync.h>
28#include <txdb.h>
29#include <txmempool.h>
30#include <uint256.h>
31#include <util/byte_units.h>
32#include <util/check.h>
33#include <util/fs.h>
34#include <util/hasher.h>
35#include <util/result.h>
36#include <util/time.h>
37#include <util/translation.h>
38#include <versionbits.h>
39
40#include <algorithm>
41#include <atomic>
42#include <cstdint>
43#include <map>
44#include <memory>
45#include <optional>
46#include <set>
47#include <span>
48#include <string>
49#include <type_traits>
50#include <utility>
51#include <vector>
52
53class Chainstate;
54class CTxMemPool;
56struct ChainTxData;
59struct LockPoints;
60struct AssumeutxoData;
61namespace kernel {
62struct ChainstateRole;
63} // namespace kernel
64namespace node {
65class SnapshotMetadata;
66} // namespace node
67namespace Consensus {
68struct Params;
69} // namespace Consensus
70namespace util {
71class SignalInterrupt;
72} // namespace util
73
75static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
76static const signed int DEFAULT_CHECKBLOCKS = 6;
77static constexpr int DEFAULT_CHECKLEVEL{3};
78// Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat)
79// At 1MB per block, 288 blocks = 288MB.
80// Add 15% for Undo data = 331MB
81// Add 20% for Orphan block rate = 397MB
82// We want the low water mark after pruning to be at least 397 MB and since we prune in
83// full block file chunks, we need the high water mark which triggers the prune to be
84// one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
85// Setting the target to >= 550 MiB will make it likely we can respect the target.
86static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
87
89static constexpr int MAX_SCRIPTCHECK_THREADS{15};
90
96};
97
99extern const std::vector<std::string> CHECKLEVEL_DOC;
100
101CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
102
103bool FatalError(kernel::Notifications& notifications, BlockValidationState& state, const bilingual_str& message);
104
106void PruneBlockFilesManual(Chainstate& active_chainstate, int nManualPruneHeight);
107
132 enum class ResultType {
133 VALID,
134 INVALID,
135 MEMPOOL_ENTRY,
136 DIFFERENT_WITNESS,
137 };
140
143
145 const std::list<CTransactionRef> m_replaced_transactions;
147 const std::optional<int64_t> m_vsize;
149 const std::optional<CAmount> m_base_fees;
155 const std::optional<CFeeRate> m_effective_feerate;
161 const std::optional<std::vector<Wtxid>> m_wtxids_fee_calculations;
162
164 const std::optional<Wtxid> m_other_wtxid;
165
167 return MempoolAcceptResult(state);
168 }
169
171 CFeeRate effective_feerate,
172 const std::vector<Wtxid>& wtxids_fee_calculations) {
173 return MempoolAcceptResult(state, effective_feerate, wtxids_fee_calculations);
174 }
175
176 static MempoolAcceptResult Success(std::list<CTransactionRef>&& replaced_txns,
177 int64_t vsize,
178 CAmount fees,
179 CFeeRate effective_feerate,
180 const std::vector<Wtxid>& wtxids_fee_calculations) {
181 return MempoolAcceptResult(std::move(replaced_txns), vsize, fees,
182 effective_feerate, wtxids_fee_calculations);
183 }
184
185 static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees) {
186 return MempoolAcceptResult(vsize, fees);
187 }
188
190 return MempoolAcceptResult(other_wtxid);
191 }
192
193// Private constructors. Use static methods MempoolAcceptResult::Success, etc. to construct.
194private:
197 : m_result_type(ResultType::INVALID), m_state(state) {
198 Assume(!state.IsValid()); // Can be invalid or error
199 }
200
202 explicit MempoolAcceptResult(std::list<CTransactionRef>&& replaced_txns,
203 int64_t vsize,
204 CAmount fees,
205 CFeeRate effective_feerate,
206 const std::vector<Wtxid>& wtxids_fee_calculations)
207 : m_result_type(ResultType::VALID),
208 m_replaced_transactions(std::move(replaced_txns)),
209 m_vsize{vsize},
210 m_base_fees(fees),
211 m_effective_feerate(effective_feerate),
212 m_wtxids_fee_calculations(wtxids_fee_calculations) {}
213
216 CFeeRate effective_feerate,
217 const std::vector<Wtxid>& wtxids_fee_calculations)
218 : m_result_type(ResultType::INVALID),
219 m_state(state),
220 m_effective_feerate(effective_feerate),
221 m_wtxids_fee_calculations(wtxids_fee_calculations) {}
222
224 explicit MempoolAcceptResult(int64_t vsize, CAmount fees)
225 : m_result_type(ResultType::MEMPOOL_ENTRY), m_vsize{vsize}, m_base_fees(fees) {}
226
228 explicit MempoolAcceptResult(const Wtxid& other_wtxid)
229 : m_result_type(ResultType::DIFFERENT_WITNESS), m_other_wtxid(other_wtxid) {}
230};
231
236{
244 std::map<Wtxid, MempoolAcceptResult> m_tx_results;
245
247 std::map<Wtxid, MempoolAcceptResult>&& results)
248 : m_state{state}, m_tx_results(std::move(results)) {}
249
251 std::map<Wtxid, MempoolAcceptResult>&& results)
252 : m_state{state}, m_tx_results(std::move(results)) {}
253
255 explicit PackageMempoolAcceptResult(const Wtxid& wtxid, const MempoolAcceptResult& result)
256 : m_tx_results{ {wtxid, result} } {}
257};
258
274 int64_t accept_time, bool bypass_limits, bool test_accept)
276
288 const Package& txns, bool test_accept, const std::optional<CFeeRate>& client_maxfeerate)
290
291/* Mempool validation helper functions */
292
296bool CheckFinalTxAtTip(const CBlockIndex& active_chain_tip, const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
297
316std::optional<LockPoints> CalculateLockPointsAtTip(
317 CBlockIndex* tip,
318 const CCoinsView& coins_view,
319 const CTransaction& tx);
320
331 const LockPoints& lock_points);
332
338{
339private:
342 unsigned int nIn;
347
348public:
349 CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, SignatureCache& signature_cache, unsigned int nInIn, script_verify_flags flags, bool cacheIn, PrecomputedTransactionData* txdataIn) :
350 m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), m_flags(flags), cacheStore(cacheIn), txdata(txdataIn), m_signature_cache(&signature_cache) { }
351
352 CScriptCheck(const CScriptCheck&) = delete;
356
357 std::optional<std::pair<ScriptError, std::string>> operator()();
358};
359
360// CScriptCheck is used a lot in std::vector, make sure that's efficient
361static_assert(std::is_nothrow_move_assignable_v<CScriptCheck>);
362static_assert(std::is_nothrow_move_constructible_v<CScriptCheck>);
363static_assert(std::is_nothrow_destructible_v<CScriptCheck>);
364
370{
371private:
374
375public:
378
379 ValidationCache(size_t script_execution_cache_bytes, size_t signature_cache_bytes);
380
383
386};
387
391bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
392
411 Chainstate& chainstate,
412 const CBlock& block,
413 bool check_pow,
414 bool check_merkle_root) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
415
417bool HasValidProofOfWork(std::span<const CBlockHeader> headers, const Consensus::Params& consensusParams);
418
420bool IsBlockMutated(const CBlock& block, bool check_witness_root);
421
423arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers);
424
425enum class VerifyDBResult {
426 SUCCESS,
428 INTERRUPTED,
431};
432
435{
436private:
438
439public:
440 explicit CVerifyDB(kernel::Notifications& notifications);
441 ~CVerifyDB();
442 [[nodiscard]] VerifyDBResult VerifyDB(
443 Chainstate& chainstate,
444 const Consensus::Params& consensus_params,
445 CCoinsView& coinsview,
446 int nCheckLevel,
447 int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
448};
449
451{
452 DISCONNECT_OK, // All good.
453 DISCONNECT_UNCLEAN, // Rolled back, but UTXO set was inconsistent with block.
454 DISCONNECT_FAILED // Something else went wrong.
456
457class ConnectTrace;
458
460inline constexpr std::array FlushStateModeNames{"NONE", "IF_NEEDED", "PERIODIC", "FORCE_FLUSH", "FORCE_SYNC"};
461enum class FlushStateMode: uint8_t {
462 NONE,
463 IF_NEEDED,
464 PERIODIC,
467};
468
479
480public:
484
487
490 std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
491
494 std::unique_ptr<CCoinsViewCache> m_connect_block_view GUARDED_BY(cs_main);
495
502 CoinsViews(DBParams db_params, CoinsViewOptions options);
503
505 void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
506};
507
509{
511 CRITICAL = 2,
513 LARGE = 1,
514 OK = 0
515};
516
517constexpr int64_t LargeCoinsCacheThreshold(int64_t total_space) noexcept
518{
519 // No periodic flush needed if at least this much space is free
520 constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES{int64_t(10_MiB)};
521 return std::max((total_space * 9) / 10,
522 total_space - MAX_BLOCK_COINSDB_USAGE_BYTES);
523}
524
526enum class Assumeutxo {
528 VALIDATED,
532 INVALID,
533};
534
550{
551protected:
558
562
564 std::unique_ptr<CoinsViews> m_coins_views;
565
567 mutable const CBlockIndex* m_cached_snapshot_base GUARDED_BY(::cs_main){nullptr};
568
570 mutable const CBlockIndex* m_cached_target_block GUARDED_BY(::cs_main){nullptr};
571
572 std::optional<const char*> m_last_script_check_reason_logged GUARDED_BY(::cs_main){};
573
574public:
578
583
584 explicit Chainstate(
585 CTxMemPool* mempool,
586 node::BlockManager& blockman,
587 ChainstateManager& chainman,
588 std::optional<uint256> from_snapshot_blockhash = std::nullopt);
589
591 fs::path StoragePath() const;
592
598
605 void InitCoinsDB(
606 size_t cache_size_bytes,
607 bool in_memory,
608 bool should_wipe);
609
612 void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
613
616 bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
617 {
619 return m_coins_views && m_coins_views->m_cacheview;
620 }
621
625
630
636 const std::optional<uint256> m_from_snapshot_blockhash;
637
642 std::optional<uint256> m_target_blockhash GUARDED_BY(::cs_main);
643
646 std::optional<AssumeutxoHash> m_target_utxohash GUARDED_BY(::cs_main);
647
653 const CBlockIndex* SnapshotBase() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
654
658 const CBlockIndex* TargetBlock() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
662 void SetTargetBlock(CBlockIndex* block) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
665 void SetTargetBlockHash(uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
666
668 bool ReachedTarget() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
669 {
670 const CBlockIndex* target_block{TargetBlock()};
671 assert(!target_block || target_block->GetAncestor(m_chain.Height()) == m_chain.Tip());
672 return target_block && target_block == m_chain.Tip();
673 }
674
682 std::set<CBlockIndex*, node::CBlockIndexWorkComparator> setBlockIndexCandidates;
683
686 {
688 Assert(m_coins_views);
689 return *Assert(m_coins_views->m_cacheview);
690 }
691
694 {
696 return Assert(m_coins_views)->m_dbview;
697 }
698
701 {
702 return m_mempool;
703 }
704
708 {
710 return Assert(m_coins_views)->m_catcherview;
711 }
712
714 void ResetCoinsViews() { m_coins_views.reset(); }
715
717 size_t m_coinsdb_cache_size_bytes{0};
718
720 size_t m_coinstip_cache_size_bytes{0};
721
724 bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
726
738 bool FlushStateToDisk(
740 FlushStateMode mode,
741 int nManualPruneHeight = 0);
742
744 void ForceFlushStateToDisk(bool wipe_cache = true);
745
748 void PruneAndFlush();
749
771 bool ActivateBestChain(
773 std::shared_ptr<const CBlock> pblock = nullptr)
774 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
776
777 // Block (dis)connection on a given view:
778 DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view)
780 bool ConnectBlock(const CBlock& block, BlockValidationState& state, CBlockIndex* pindex,
781 CCoinsViewCache& view, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
782
783 // Apply the effects of a block disconnection on the UTXO set.
784 bool DisconnectTip(BlockValidationState& state, DisconnectedBlockTransactions* disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
785
786 // Manual block validity manipulation:
791 bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
792 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
794
797 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
799
801 void SetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
802
804 void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
805
807 bool ReplayBlocks();
808
810 [[nodiscard]] bool NeedsRedownload() const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
812 bool LoadGenesisBlock();
813
814 void TryAddBlockIndexCandidate(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
815
816 void PruneBlockIndexCandidates();
817
818 void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
819
821 const CBlockIndex* FindForkInGlobalIndex(const CBlockLocator& locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
822
824 bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
825
829 CoinsCacheSizeState GetCoinsCacheSizeState() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
830
831 CoinsCacheSizeState GetCoinsCacheSizeState(
832 size_t max_coins_cache_size_bytes,
833 size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
834
836
838 RecursiveMutex* MempoolMutex() const LOCK_RETURNED(m_mempool->cs)
839 {
840 return m_mempool ? &m_mempool->cs : nullptr;
841 }
842
846 std::pair<int, int> GetPruneRange(int last_height_can_prune) const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
847
848protected:
849 bool ActivateBestChainStep(BlockValidationState& state, CBlockIndex* pindexMostWork, const std::shared_ptr<const CBlock>& pblock, bool& fInvalidFound, ConnectTrace& connectTrace) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
850 bool ConnectTip(
852 CBlockIndex* pindexNew,
853 std::shared_ptr<const CBlock> block_to_connect,
854 ConnectTrace& connectTrace,
856
857 void InvalidBlockFound(CBlockIndex* pindex, const BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
858 CBlockIndex* FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
859
860 bool RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& inputs) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
861
862 void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
863 void InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
864
878 void MaybeUpdateMempoolForReorg(
879 DisconnectedBlockTransactions& disconnectpool,
880 bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
881
883 void UpdateTip(const CBlockIndex* pindexNew)
885
886 NodeClock::time_point m_next_write{NodeClock::time_point::max()};
887
892 [[nodiscard]] util::Result<void> InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
893
895};
896
898 SUCCESS,
899 SKIPPED,
900
901 // Expected assumeutxo configuration data is not found for the height of the
902 // base block.
904
905 // Failed to generate UTXO statistics (to check UTXO set hash) for the
906 // validated chainstate.
908
909 // The UTXO set hash of the validated chainstate does not match the one
910 // expected by assumeutxo chainparams.
912};
913
935{
936private:
937
939 CBlockIndex* m_last_notified_header GUARDED_BY(GetMutex()){nullptr};
940
941 bool NotifyHeaderTip() LOCKS_EXCLUDED(GetMutex());
942
950 [[nodiscard]] util::Result<void> PopulateAndValidateSnapshot(
951 Chainstate& snapshot_chainstate,
952 AutoFile& coins_file,
953 const node::SnapshotMetadata& metadata);
954
962 bool AcceptBlockHeader(
963 const CBlockHeader& block,
965 CBlockIndex** ppindex,
966 bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
968
970 MockableSteadyClock::time_point m_last_presync_update GUARDED_BY(GetMutex()){};
971
974
977 SteadyClock::duration GUARDED_BY(::cs_main) time_check{};
978 SteadyClock::duration GUARDED_BY(::cs_main) time_forks{};
979 SteadyClock::duration GUARDED_BY(::cs_main) time_connect{};
980 SteadyClock::duration GUARDED_BY(::cs_main) time_verify{};
981 SteadyClock::duration GUARDED_BY(::cs_main) time_undo{};
982 SteadyClock::duration GUARDED_BY(::cs_main) time_index{};
983 SteadyClock::duration GUARDED_BY(::cs_main) time_total{};
984 int64_t GUARDED_BY(::cs_main) num_blocks_total{0};
985 SteadyClock::duration GUARDED_BY(::cs_main) time_connect_total{};
986 SteadyClock::duration GUARDED_BY(::cs_main) time_flush{};
987 SteadyClock::duration GUARDED_BY(::cs_main) time_chainstate{};
988 SteadyClock::duration GUARDED_BY(::cs_main) time_post_connect{};
989
990protected:
991 CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
992
993public:
995
996 explicit ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager::Options blockman_options);
997
1000 std::function<void()> snapshot_download_completed = std::function<void()>();
1001
1002 const CChainParams& GetParams() const { return m_options.chainparams; }
1003 const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }
1004 bool ShouldCheckBlockIndex() const;
1005 const arith_uint256& MinimumChainWork() const { return *Assert(m_options.minimum_chain_work); }
1006 const uint256& AssumedValidBlock() const { return *Assert(m_options.assumed_valid_block); }
1007 kernel::Notifications& GetNotifications() const { return m_options.notifications; };
1008
1014 void CheckBlockIndex() const;
1015
1028
1034
1036
1044 std::atomic_bool m_cached_is_ibd{true};
1045
1053 int32_t nBlockSequenceId GUARDED_BY(::cs_main) = SEQ_ID_INIT_FROM_DISK + 1;
1055 int32_t nBlockReverseSequenceId = -1;
1057 arith_uint256 nLastPreciousChainwork = 0;
1058
1059 // Reset the memory-only sequence counters we use to track block arrival
1060 // (used by tests to reset state)
1062 {
1064 nBlockSequenceId = SEQ_ID_INIT_FROM_DISK + 1;
1065 nBlockReverseSequenceId = -1;
1066 }
1067
1068
1073 CBlockIndex* m_best_header GUARDED_BY(::cs_main){nullptr};
1074
1077 size_t m_total_coinstip_cache{0};
1078 //
1081 size_t m_total_coinsdb_cache{0};
1082
1086 // constructor
1087 Chainstate& InitializeChainstate(CTxMemPool* mempool) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1088
1101 AutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory);
1102
1111 SnapshotCompletionResult MaybeValidateSnapshot(Chainstate& validated_cs, Chainstate& unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1112
1115 {
1116 for (auto& cs : m_chainstates) {
1117 if (cs && cs->m_assumeutxo != Assumeutxo::INVALID && !cs->m_target_blockhash) return *cs;
1118 }
1119 abort();
1120 }
1121
1124 {
1125 for (auto& cs : m_chainstates) {
1126 if (cs && cs->m_assumeutxo != Assumeutxo::INVALID && cs->m_target_blockhash && !cs->m_target_utxohash) return cs.get();
1127 }
1128 return nullptr;
1129 }
1130
1135 {
1136 for (auto* cs : {&CurrentChainstate(), HistoricalChainstate()}) {
1137 if (cs && cs->m_assumeutxo == Assumeutxo::VALIDATED) return *cs;
1138 }
1139 abort();
1140 }
1141
1143 std::unique_ptr<Chainstate> RemoveChainstate(Chainstate& chainstate) EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
1144 {
1145 auto it{std::find_if(m_chainstates.begin(), m_chainstates.end(), [&](auto& cs) { return cs.get() == &chainstate; })};
1146 if (it != m_chainstates.end()) {
1147 auto ret{std::move(*it)};
1148 m_chainstates.erase(it);
1149 return ret;
1150 }
1151 return nullptr;
1152 }
1153
1159 Chainstate& ActiveChainstate() const;
1160 CChain& ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChainstate().m_chain; }
1161 int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Height(); }
1162 CBlockIndex* ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Tip(); }
1164
1176 void UpdateIBDStatus() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1177
1179 {
1181 return m_blockman.m_block_index;
1182 }
1183
1188
1190 bool IsInitialBlockDownload() const noexcept;
1191
1193 double GuessVerificationProgress(const CBlockIndex* pindex) const EXCLUSIVE_LOCKS_REQUIRED(GetMutex());
1194
1222 AutoFile& file_in,
1223 FlatFilePos* dbp = nullptr,
1224 std::multimap<uint256, FlatFilePos>* blocks_with_unknown_parent = nullptr);
1225
1250 bool ProcessNewBlock(const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked, bool* new_block) LOCKS_EXCLUDED(cs_main);
1251
1264 bool ProcessNewBlockHeaders(std::span<const CBlockHeader> headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
1265
1285 bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, BlockValidationState& state, CBlockIndex** ppindex, bool fRequested, const FlatFilePos* dbp, bool* fNewBlock, bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1286
1287 void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1288
1295 [[nodiscard]] MempoolAcceptResult ProcessTransaction(const CTransactionRef& tx, bool test_accept=false)
1297
1299 bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1300
1303 void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1304
1310 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev) const;
1311
1313 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev) const;
1314
1319 void ReportHeadersPresync(int64_t height, int64_t timestamp);
1320
1324 Chainstate* LoadAssumeutxoChainstate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1325
1327 Chainstate& AddChainstate(std::unique_ptr<Chainstate> chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1328
1329 void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1330
1333 [[nodiscard]] bool DeleteChainstate(Chainstate& chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1334
1344 bool ValidatedSnapshotCleanup(Chainstate& validated_cs, Chainstate& unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1345
1347 std::optional<std::pair<const CBlockIndex*, const CBlockIndex*>> GetHistoricalBlockRange() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1348
1350 util::Result<void> ActivateBestChains() LOCKS_EXCLUDED(::cs_main);
1351
1355 void RecalculateBestHeader() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1356
1357 CCheckQueue<CScriptCheck>& GetCheckQueue() { return m_script_check_queue; }
1358
1360
1368 std::vector<std::unique_ptr<Chainstate>> m_chainstates GUARDED_BY(::cs_main);
1369};
1370
1372template<typename DEP>
1373bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const ChainstateManager& chainman, DEP dep)
1374{
1375 return DeploymentActiveAfter(pindexPrev, chainman.GetConsensus(), dep, chainman.m_versionbitscache);
1376}
1377
1378template<typename DEP>
1379bool DeploymentActiveAt(const CBlockIndex& index, const ChainstateManager& chainman, DEP dep)
1380{
1381 return DeploymentActiveAt(index, chainman.GetConsensus(), dep, chainman.m_versionbitscache);
1382}
1383
1384template<typename DEP>
1385bool DeploymentEnabled(const ChainstateManager& chainman, DEP dep)
1386{
1387 return DeploymentEnabled(chainman.GetConsensus(), dep);
1388}
1389
1391bool IsBIP30Repeat(const CBlockIndex& block_index);
1392
1394bool IsBIP30Unspendable(const uint256& block_hash, int block_height);
1395
1396// Returns the script flags which should be checked for a given block
1397script_verify_flags GetBlockScriptFlags(const CBlockIndex& block_index, const ChainstateManager& chainman);
1398
1399#endif // BITCOIN_VALIDATION_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static void pool cs
int ret
int flags
Definition: bitcoin-tx.cpp:529
void InvalidateBlock(ChainstateManager &chainman, const uint256 block_hash)
static constexpr int32_t SEQ_ID_INIT_FROM_DISK
Definition: chain.h:40
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
Definition: check.h:113
#define Assume(val)
Assume is the identity function.
Definition: check.h:125
static void CheckBlockIndex(benchmark::Bench &bench)
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:373
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:27
Definition: block.h:74
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:95
An in-memory indexed chain of blocks.
Definition: chain.h:381
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
Definition: chain.h:397
int Height() const
Return the maximal height in the chain.
Definition: chain.h:426
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:77
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:355
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:35
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Definition: coins.h:529
Abstract view on the open txout dataset.
Definition: coins.h:302
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
Definition: feerate.h:35
A hasher class for SHA-256.
Definition: sha256.h:14
Closure representing one script verification Note that this stores references to the spending transac...
Definition: validation.h:338
CScriptCheck & operator=(CScriptCheck &&)=default
SignatureCache * m_signature_cache
Definition: validation.h:346
CScriptCheck(const CScriptCheck &)=delete
PrecomputedTransactionData * txdata
Definition: validation.h:345
CTxOut m_tx_out
Definition: validation.h:340
script_verify_flags m_flags
Definition: validation.h:343
CScriptCheck(CScriptCheck &&)=default
bool cacheStore
Definition: validation.h:344
std::optional< std::pair< ScriptError, std::string > > operator()()
const CTransaction * ptxTo
Definition: validation.h:341
unsigned int nIn
Definition: validation.h:342
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, SignatureCache &signature_cache, unsigned int nInIn, script_verify_flags flags, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:349
CScriptCheck & operator=(const CScriptCheck &)=delete
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:281
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:188
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:261
An output of a transaction.
Definition: transaction.h:140
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:435
VerifyDBResult VerifyDB(Chainstate &chainstate, const Consensus::Params &consensus_params, CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
kernel::Notifications & m_notifications
Definition: validation.h:437
CVerifyDB(kernel::Notifications &notifications)
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:550
Mutex m_chainstate_mutex
The ChainState Mutex A lock that must be held when modifying this ChainState - held in ActivateBestCh...
Definition: validation.h:557
std::optional< uint256 > m_target_blockhash GUARDED_BY(::cs_main)
Target block for this chainstate.
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:624
CTxMemPool * GetMempool()
Definition: validation.h:700
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:685
const std::optional< uint256 > m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from.
Definition: validation.h:636
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:561
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:693
std::optional< const char * > m_last_script_check_reason_logged GUARDED_BY(::cs_main)
Definition: validation.h:572
const CBlockIndex *m_cached_target_block GUARDED_BY(::cs_main)
Cached result of LookupBlockIndex(*m_target_blockhash)
Definition: validation.h:570
std::set< CBlockIndex *, node::CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries that have as much work as our current tip or more,...
Definition: validation.h:682
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:582
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:564
Assumeutxo m_assumeutxo GUARDED_BY(::cs_main)
Assumeutxo state indicating whether all blocks in the chain were validated, or if the chainstate is b...
std::optional< AssumeutxoHash > m_target_utxohash GUARDED_BY(::cs_main)
Hash of the UTXO set at the target block, computed when the chainstate reaches the target block,...
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:714
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Definition: validation.h:577
const CBlockIndex *m_cached_snapshot_base GUARDED_BY(::cs_main)
Cached result of LookupBlockIndex(*m_from_snapshot_blockhash)
Definition: validation.h:567
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:707
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
Definition: validation.h:935
SteadyClock::duration GUARDED_BY(::cs_main) time_connect_total
Definition: validation.h:985
Chainstate * HistoricalChainstate() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Return historical chainstate targeting a specific block, if any.
Definition: validation.h:1123
const uint256 & AssumedValidBlock() const
Definition: validation.h:1006
CBlockIndex *m_best_header GUARDED_BY(::cs_main)
Best header we've seen so far for which the block is not known to be invalid (used,...
Definition: validation.h:1073
ValidationCache m_validation_cache
Definition: validation.h:1035
int64_t GUARDED_BY(::cs_main) num_blocks_total
Definition: validation.h:984
SteadyClock::duration GUARDED_BY(::cs_main) time_undo
Definition: validation.h:981
SteadyClock::duration GUARDED_BY(::cs_main) time_index
Definition: validation.h:982
SteadyClock::duration GUARDED_BY(::cs_main) time_post_connect
Definition: validation.h:988
std::unique_ptr< Chainstate > RemoveChainstate(Chainstate &chainstate) EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Remove a chainstate.
Definition: validation.h:1143
kernel::Notifications & GetNotifications() const
Definition: validation.h:1007
SteadyClock::duration GUARDED_BY(::cs_main) time_check
Timers and counters used for benchmarking validation in both background and active chainstates.
Definition: validation.h:977
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1027
SteadyClock::duration GUARDED_BY(::cs_main) time_total
Definition: validation.h:983
SteadyClock::duration GUARDED_BY(::cs_main) time_chainstate
Definition: validation.h:987
CCheckQueue< CScriptCheck > m_script_check_queue
A queue for script verifications that have to be performed by worker threads.
Definition: validation.h:973
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1162
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Definition: validation.h:991
SnapshotCompletionResult MaybeValidateSnapshot(Chainstate &validated_cs, Chainstate &unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(Chainstate & CurrentChainstate() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Try to validate an assumeutxo snapshot by using a validated historical chainstate targeted at the sna...
Definition: validation.h:1114
SteadyClock::duration GUARDED_BY(::cs_main) time_forks
Definition: validation.h:978
CBlockIndex *m_last_notified_header GUARDED_BY(GetMutex())
The last header for which a headerTip notification was issued.
Definition: validation.h:939
std::vector< std::unique_ptr< Chainstate > > m_chainstates GUARDED_BY(::cs_main)
List of chainstates.
const util::SignalInterrupt & m_interrupt
Definition: validation.h:1029
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1161
VersionBitsCache m_versionbitscache
Track versionbit status.
Definition: validation.h:1187
Chainstate & ValidatedChainstate() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Return fully validated chainstate that should be used for indexing, to support indexes that need to i...
Definition: validation.h:1134
const CChainParams & GetParams() const
Definition: validation.h:1002
const Consensus::Params & GetConsensus() const
Definition: validation.h:1003
const arith_uint256 & MinimumChainWork() const
Definition: validation.h:1005
const Options m_options
Definition: validation.h:1030
int32_t nBlockSequenceId GUARDED_BY(::cs_main)
Every received block is assigned a unique and increasing identifier, so we know which one to give pri...
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(util::Result< CBlockIndex * ActivateSnapshot)(AutoFile &coins_file, const node::SnapshotMetadata &metadata, bool in_memory)
Instantiate a new chainstate.
Definition: validation.h:1100
SteadyClock::duration GUARDED_BY(::cs_main) time_verify
Definition: validation.h:980
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1160
SteadyClock::duration GUARDED_BY(::cs_main) time_connect
Definition: validation.h:979
void ResetBlockSequenceCounters() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1061
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1033
SteadyClock::duration GUARDED_BY(::cs_main) time_flush
Definition: validation.h:986
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:478
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.
std::unique_ptr< CCoinsViewCache > m_connect_block_view GUARDED_BY(cs_main)
Temporary CCoinsViewCache layered on top of m_cacheview and passed to ConnectBlock().
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...
Used to track blocks whose transactions were applied to the UTXO state as a part of a single Activate...
DisconnectedBlockTransactions.
Valid signature cache, to avoid doing expensive ECDSA signature checking twice for every transaction ...
Definition: sigcache.h:39
Convenience class for initializing and passing the script execution cache and signature cache.
Definition: validation.h:370
ValidationCache(size_t script_execution_cache_bytes, size_t signature_cache_bytes)
CuckooCache::cache< uint256, SignatureCacheHasher > m_script_execution_cache
Definition: validation.h:376
ValidationCache & operator=(const ValidationCache &)=delete
ValidationCache(const ValidationCache &)=delete
CSHA256 ScriptExecutionCacheHasher() const
Return a copy of the pre-initialized hasher.
Definition: validation.h:385
CSHA256 m_script_execution_cache_hasher
Pre-initialized hasher to avoid having to recreate it for every hash calculation.
Definition: validation.h:373
SignatureCache m_signature_cache
Definition: validation.h:377
bool IsValid() const
Definition: validation.h:105
BIP 9 allows multiple softforks to be deployed in parallel.
Definition: versionbits.h:77
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:192
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:38
transaction_identifier represents the two canonical transaction identifier types (txid,...
256-bit opaque blob.
Definition: uint256.h:195
Helper class that manages an interrupt flag, and allows a thread or signal to interrupt another threa...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:8
static void LoadExternalBlockFile(benchmark::Bench &bench)
The LoadExternalBlockFile() function is used during -reindex and -loadblock.
unsigned int nHeight
Transaction validation functions.
Definition: messages.h:21
std::unordered_map< uint256, CBlockIndex, BlockHasher > BlockMap
Definition: blockstorage.h:135
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:246
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:45
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:403
@ OK
The message verification was successful.
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:34
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:117
Holds various statistics on transactions within a chain.
Definition: chainparams.h:57
User-controlled performance and debug options.
Definition: txdb.h:26
Parameters that influence chain consensus.
Definition: params.h:84
Application-specific storage settings.
Definition: dbwrapper.h:33
Validation result for a transaction evaluated by MemPoolAccept (single or package).
Definition: validation.h:130
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigops.
Definition: validation.h:147
const ResultType m_result_type
Result type.
Definition: validation.h:139
MempoolAcceptResult(int64_t vsize, CAmount fees)
Constructor for already-in-mempool case.
Definition: validation.h:224
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:149
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:196
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:142
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:132
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:166
static MempoolAcceptResult FeeFailure(TxValidationState state, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Definition: validation.h:170
const std::optional< CFeeRate > m_effective_feerate
The feerate at which this transaction was considered.
Definition: validation.h:155
MempoolAcceptResult(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Constructor for success case.
Definition: validation.h:202
const std::optional< Wtxid > m_other_wtxid
The wtxid of the transaction in the mempool which has the same txid but different witness.
Definition: validation.h:164
const std::list< CTransactionRef > m_replaced_transactions
Mempool transactions replaced by the tx.
Definition: validation.h:145
MempoolAcceptResult(const Wtxid &other_wtxid)
Constructor for witness-swapped case.
Definition: validation.h:228
static MempoolAcceptResult MempoolTxDifferentWitness(const Wtxid &other_wtxid)
Definition: validation.h:189
static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees)
Definition: validation.h:185
static MempoolAcceptResult Success(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Definition: validation.h:176
MempoolAcceptResult(TxValidationState state, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Constructor for fee-related failure case.
Definition: validation.h:215
const std::optional< std::vector< Wtxid > > m_wtxids_fee_calculations
Contains the wtxids of the transactions used for fee-related checks.
Definition: validation.h:161
Version of SteadyClock that is mockable in the context of tests (set the current value with SetMockTi...
Definition: time.h:38
Mockable clock in the context of tests, otherwise the system clock.
Definition: time.h:18
Validation result for package mempool acceptance.
Definition: validation.h:236
PackageValidationState m_state
Definition: validation.h:237
PackageMempoolAcceptResult(const Wtxid &wtxid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a single MempoolAcceptResult.
Definition: validation.h:255
PackageMempoolAcceptResult(PackageValidationState state, CFeeRate feerate, std::map< Wtxid, MempoolAcceptResult > &&results)
Definition: validation.h:250
PackageMempoolAcceptResult(PackageValidationState state, std::map< Wtxid, MempoolAcceptResult > &&results)
Definition: validation.h:246
std::map< Wtxid, MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
Definition: validation.h:244
Bilingual messages:
Definition: translation.h:24
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...
Information about chainstate that notifications are sent from.
Definition: types.h:18
#define EXCLUSIVE_LOCKS_REQUIRED(...)
Definition: threadsafety.h:51
#define LOCKS_EXCLUDED(...)
Definition: threadsafety.h:50
#define LOCK_RETURNED(x)
Definition: threadsafety.h:49
bool CheckFinalTxAtTip(const CBlockIndex &active_chain_tip, const CTransaction &tx)
Definition: validation.cpp:149
AssertLockHeld(pool.cs)
assert(!tx.IsCoinBase())
bool IsBlockMutated(const CBlock &block, bool check_witness_root)
Check if a block has been mutated (with respect to its merkle root and witness commitments).
script_verify_flags GetBlockScriptFlags(const CBlockIndex &block_index, const ChainstateManager &chainman)
static constexpr int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
Definition: validation.h:89
static constexpr int DEFAULT_CHECKLEVEL
Definition: validation.h:77
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:86
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
bool HasValidProofOfWork(std::span< const CBlockHeader > headers, const Consensus::Params &consensusParams)
Check that the proof of work on each blockheader matches the value in nBits.
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:248
bool FatalError(kernel::Notifications &notifications, BlockValidationState &state, const bilingual_str &message)
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:75
MempoolAcceptResult AcceptToMemoryPool(Chainstate &active_chainstate, const CTransactionRef &tx, int64_t accept_time, bool bypass_limits, bool test_accept) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the mempool.
bool DeploymentActiveAfter(const CBlockIndex *pindexPrev, const ChainstateManager &chainman, DEP dep)
Deployment* info via ChainstateManager.
Definition: validation.h:1373
BlockValidationState TestBlockValidity(Chainstate &chainstate, const CBlock &block, bool check_pow, bool check_merkle_root) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Verify a block, including transactions.
SnapshotCompletionResult
Definition: validation.h:897
bool DeploymentEnabled(const ChainstateManager &chainman, DEP dep)
Definition: validation.h:1385
Assumeutxo
Chainstate assumeutxo validity.
Definition: validation.h:526
@ VALIDATED
Every block in the chain has been validated.
@ UNVALIDATED
Blocks after an assumeutxo snapshot have been validated but the snapshot itself has not been validate...
@ INVALID
The assumeutxo snapshot failed validation.
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:92
constexpr std::array FlushStateModeNames
Definition: validation.h:460
bool CheckFinalTxAtTip(const CBlockIndex &active_chain_tip, const CTransaction &tx) EXCLUSIVE_LOCKS_REQUIRED(std::optional< LockPoints > CalculateLockPointsAtTip(CBlockIndex *tip, const CCoinsView &coins_view, const CTransaction &tx)
Check if transaction will be final in the next block to be created.
Definition: validation.h:316
PackageMempoolAcceptResult ProcessNewPackage(Chainstate &active_chainstate, CTxMemPool &pool, const Package &txns, bool test_accept, const std::optional< CFeeRate > &client_maxfeerate) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Validate (and maybe submit) a package to the mempool.
constexpr int64_t LargeCoinsCacheThreshold(int64_t total_space) noexcept
Definition: validation.h:517
arith_uint256 CalculateClaimedHeadersWork(std::span< const CBlockHeader > headers)
Return the sum of the claimed work on a given set of headers.
VerifyDBResult
Definition: validation.h:425
bool CheckBlock(const CBlock &block, BlockValidationState &state, const Consensus::Params &consensusParams, bool fCheckPOW=true, bool fCheckMerkleRoot=true)
Functions for validating blocks and updating the block tree.
const std::vector< std::string > CHECKLEVEL_DOC
Documentation for argument 'checklevel'.
Definition: validation.cpp:102
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
FlushStateMode
Definition: validation.h:461
CoinsCacheSizeState
Definition: validation.h:509
@ 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:1379
bool IsBIP30Repeat(const CBlockIndex &block_index)
Identifies blocks that overwrote an existing coinbase output in the UTXO set (see BIP30)
static const signed int DEFAULT_CHECKBLOCKS
Definition: validation.h:76
DisconnectResult
Definition: validation.h:451
@ DISCONNECT_FAILED
Definition: validation.h:454
@ DISCONNECT_UNCLEAN
Definition: validation.h:453
@ DISCONNECT_OK
Definition: validation.h:452
bool IsBIP30Unspendable(const uint256 &block_hash, int block_height)
Identifies blocks which coinbase output was subsequently overwritten in the UTXO set (see BIP30)