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 node {
62class SnapshotMetadata;
63} // namespace node
64namespace Consensus {
65struct Params;
66} // namespace Consensus
67namespace util {
68class SignalInterrupt;
69} // namespace util
70
72static const unsigned int MIN_BLOCKS_TO_KEEP = 288;
73static const signed int DEFAULT_CHECKBLOCKS = 6;
74static constexpr int DEFAULT_CHECKLEVEL{3};
75// Require that user allocate at least 550 MiB for block & undo files (blk???.dat and rev???.dat)
76// At 1MB per block, 288 blocks = 288MB.
77// Add 15% for Undo data = 331MB
78// Add 20% for Orphan block rate = 397MB
79// We want the low water mark after pruning to be at least 397 MB and since we prune in
80// full block file chunks, we need the high water mark which triggers the prune to be
81// one 128MB block file + added 15% undo data = 147MB greater for a total of 545MB
82// Setting the target to >= 550 MiB will make it likely we can respect the target.
83static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES = 550 * 1024 * 1024;
84
86static constexpr int MAX_SCRIPTCHECK_THREADS{15};
87
93};
94
96extern const std::vector<std::string> CHECKLEVEL_DOC;
97
98CAmount GetBlockSubsidy(int nHeight, const Consensus::Params& consensusParams);
99
100bool FatalError(kernel::Notifications& notifications, BlockValidationState& state, const bilingual_str& message);
101
103void PruneBlockFilesManual(Chainstate& active_chainstate, int nManualPruneHeight);
104
129 enum class ResultType {
130 VALID,
131 INVALID,
132 MEMPOOL_ENTRY,
133 DIFFERENT_WITNESS,
134 };
137
140
142 const std::list<CTransactionRef> m_replaced_transactions;
144 const std::optional<int64_t> m_vsize;
146 const std::optional<CAmount> m_base_fees;
152 const std::optional<CFeeRate> m_effective_feerate;
158 const std::optional<std::vector<Wtxid>> m_wtxids_fee_calculations;
159
161 const std::optional<Wtxid> m_other_wtxid;
162
164 return MempoolAcceptResult(state);
165 }
166
168 CFeeRate effective_feerate,
169 const std::vector<Wtxid>& wtxids_fee_calculations) {
170 return MempoolAcceptResult(state, effective_feerate, wtxids_fee_calculations);
171 }
172
173 static MempoolAcceptResult Success(std::list<CTransactionRef>&& replaced_txns,
174 int64_t vsize,
175 CAmount fees,
176 CFeeRate effective_feerate,
177 const std::vector<Wtxid>& wtxids_fee_calculations) {
178 return MempoolAcceptResult(std::move(replaced_txns), vsize, fees,
179 effective_feerate, wtxids_fee_calculations);
180 }
181
182 static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees) {
183 return MempoolAcceptResult(vsize, fees);
184 }
185
187 return MempoolAcceptResult(other_wtxid);
188 }
189
190// Private constructors. Use static methods MempoolAcceptResult::Success, etc. to construct.
191private:
194 : m_result_type(ResultType::INVALID), m_state(state) {
195 Assume(!state.IsValid()); // Can be invalid or error
196 }
197
199 explicit MempoolAcceptResult(std::list<CTransactionRef>&& replaced_txns,
200 int64_t vsize,
201 CAmount fees,
202 CFeeRate effective_feerate,
203 const std::vector<Wtxid>& wtxids_fee_calculations)
204 : m_result_type(ResultType::VALID),
205 m_replaced_transactions(std::move(replaced_txns)),
206 m_vsize{vsize},
207 m_base_fees(fees),
208 m_effective_feerate(effective_feerate),
209 m_wtxids_fee_calculations(wtxids_fee_calculations) {}
210
213 CFeeRate effective_feerate,
214 const std::vector<Wtxid>& wtxids_fee_calculations)
215 : m_result_type(ResultType::INVALID),
216 m_state(state),
217 m_effective_feerate(effective_feerate),
218 m_wtxids_fee_calculations(wtxids_fee_calculations) {}
219
221 explicit MempoolAcceptResult(int64_t vsize, CAmount fees)
222 : m_result_type(ResultType::MEMPOOL_ENTRY), m_vsize{vsize}, m_base_fees(fees) {}
223
225 explicit MempoolAcceptResult(const Wtxid& other_wtxid)
226 : m_result_type(ResultType::DIFFERENT_WITNESS), m_other_wtxid(other_wtxid) {}
227};
228
233{
241 std::map<Wtxid, MempoolAcceptResult> m_tx_results;
242
244 std::map<Wtxid, MempoolAcceptResult>&& results)
245 : m_state{state}, m_tx_results(std::move(results)) {}
246
248 std::map<Wtxid, MempoolAcceptResult>&& results)
249 : m_state{state}, m_tx_results(std::move(results)) {}
250
252 explicit PackageMempoolAcceptResult(const Wtxid& wtxid, const MempoolAcceptResult& result)
253 : m_tx_results{ {wtxid, result} } {}
254};
255
271 int64_t accept_time, bool bypass_limits, bool test_accept)
273
285 const Package& txns, bool test_accept, const std::optional<CFeeRate>& client_maxfeerate)
287
288/* Mempool validation helper functions */
289
293bool CheckFinalTxAtTip(const CBlockIndex& active_chain_tip, const CTransaction& tx) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
294
313std::optional<LockPoints> CalculateLockPointsAtTip(
314 CBlockIndex* tip,
315 const CCoinsView& coins_view,
316 const CTransaction& tx);
317
328 const LockPoints& lock_points);
329
335{
336private:
339 unsigned int nIn;
344
345public:
346 CScriptCheck(const CTxOut& outIn, const CTransaction& txToIn, SignatureCache& signature_cache, unsigned int nInIn, script_verify_flags flags, bool cacheIn, PrecomputedTransactionData* txdataIn) :
347 m_tx_out(outIn), ptxTo(&txToIn), nIn(nInIn), m_flags(flags), cacheStore(cacheIn), txdata(txdataIn), m_signature_cache(&signature_cache) { }
348
349 CScriptCheck(const CScriptCheck&) = delete;
353
354 std::optional<std::pair<ScriptError, std::string>> operator()();
355};
356
357// CScriptCheck is used a lot in std::vector, make sure that's efficient
358static_assert(std::is_nothrow_move_assignable_v<CScriptCheck>);
359static_assert(std::is_nothrow_move_constructible_v<CScriptCheck>);
360static_assert(std::is_nothrow_destructible_v<CScriptCheck>);
361
367{
368private:
371
372public:
375
376 ValidationCache(size_t script_execution_cache_bytes, size_t signature_cache_bytes);
377
380
383};
384
388bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensus::Params& consensusParams, bool fCheckPOW = true, bool fCheckMerkleRoot = true);
389
408 Chainstate& chainstate,
409 const CBlock& block,
410 bool check_pow,
411 bool check_merkle_root) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
412
414bool HasValidProofOfWork(const std::vector<CBlockHeader>& headers, const Consensus::Params& consensusParams);
415
417bool IsBlockMutated(const CBlock& block, bool check_witness_root);
418
420arith_uint256 CalculateClaimedHeadersWork(std::span<const CBlockHeader> headers);
421
422enum class VerifyDBResult {
423 SUCCESS,
425 INTERRUPTED,
428};
429
432{
433private:
435
436public:
437 explicit CVerifyDB(kernel::Notifications& notifications);
438 ~CVerifyDB();
439 [[nodiscard]] VerifyDBResult VerifyDB(
440 Chainstate& chainstate,
441 const Consensus::Params& consensus_params,
442 CCoinsView& coinsview,
443 int nCheckLevel,
444 int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
445};
446
448{
449 DISCONNECT_OK, // All good.
450 DISCONNECT_UNCLEAN, // Rolled back, but UTXO set was inconsistent with block.
451 DISCONNECT_FAILED // Something else went wrong.
453
454class ConnectTrace;
455
457inline constexpr std::array FlushStateModeNames{"NONE", "IF_NEEDED", "PERIODIC", "ALWAYS"};
458enum class FlushStateMode: uint8_t {
459 NONE,
460 IF_NEEDED,
461 PERIODIC,
462 ALWAYS
463};
464
475
476public:
480
483
486 std::unique_ptr<CCoinsViewCache> m_cacheview GUARDED_BY(cs_main);
487
494 CoinsViews(DBParams db_params, CoinsViewOptions options);
495
497 void InitCache() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
498};
499
501{
503 CRITICAL = 2,
505 LARGE = 1,
506 OK = 0
507};
508
509constexpr int64_t LargeCoinsCacheThreshold(int64_t total_space) noexcept
510{
511 // No periodic flush needed if at least this much space is free
512 constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES{int64_t(10_MiB)};
513 return std::max((total_space * 9) / 10,
514 total_space - MAX_BLOCK_COINSDB_USAGE_BYTES);
515}
516
532{
533protected:
540
544
546 std::unique_ptr<CoinsViews> m_coins_views;
547
559 bool m_disabled GUARDED_BY(::cs_main) {false};
560
562 mutable const CBlockIndex* m_cached_snapshot_base GUARDED_BY(::cs_main){nullptr};
563
564 std::optional<const char*> m_last_script_check_reason_logged GUARDED_BY(::cs_main){};
565
566public:
570
575
576 explicit Chainstate(
577 CTxMemPool* mempool,
578 node::BlockManager& blockman,
579 ChainstateManager& chainman,
580 std::optional<uint256> from_snapshot_blockhash = std::nullopt);
581
587
594 void InitCoinsDB(
595 size_t cache_size_bytes,
596 bool in_memory,
597 bool should_wipe,
598 fs::path leveldb_name = "chainstate");
599
602 void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
603
606 bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main)
607 {
609 return m_coins_views && m_coins_views->m_cacheview;
610 }
611
615
621 const std::optional<uint256> m_from_snapshot_blockhash;
622
628 const CBlockIndex* SnapshotBase() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
629
637 std::set<CBlockIndex*, node::CBlockIndexWorkComparator> setBlockIndexCandidates;
638
641 {
643 Assert(m_coins_views);
644 return *Assert(m_coins_views->m_cacheview);
645 }
646
649 {
651 return Assert(m_coins_views)->m_dbview;
652 }
653
656 {
657 return m_mempool;
658 }
659
663 {
665 return Assert(m_coins_views)->m_catcherview;
666 }
667
669 void ResetCoinsViews() { m_coins_views.reset(); }
670
672 bool HasCoinsViews() const { return (bool)m_coins_views; }
673
675 size_t m_coinsdb_cache_size_bytes{0};
676
678 size_t m_coinstip_cache_size_bytes{0};
679
682 bool ResizeCoinsCaches(size_t coinstip_size, size_t coinsdb_size)
684
696 bool FlushStateToDisk(
698 FlushStateMode mode,
699 int nManualPruneHeight = 0);
700
702 void ForceFlushStateToDisk();
703
706 void PruneAndFlush();
707
729 bool ActivateBestChain(
731 std::shared_ptr<const CBlock> pblock = nullptr)
732 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
734
735 // Block (dis)connection on a given view:
736 DisconnectResult DisconnectBlock(const CBlock& block, const CBlockIndex* pindex, CCoinsViewCache& view)
738 bool ConnectBlock(const CBlock& block, BlockValidationState& state, CBlockIndex* pindex,
739 CCoinsViewCache& view, bool fJustCheck = false) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
740
741 // Apply the effects of a block disconnection on the UTXO set.
742 bool DisconnectTip(BlockValidationState& state, DisconnectedBlockTransactions* disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
743
744 // Manual block validity manipulation:
749 bool PreciousBlock(BlockValidationState& state, CBlockIndex* pindex)
750 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
752
755 EXCLUSIVE_LOCKS_REQUIRED(!m_chainstate_mutex)
757
759 void SetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
760
762 void ResetBlockFailureFlags(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
763
765 bool ReplayBlocks();
766
768 [[nodiscard]] bool NeedsRedownload() const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
770 bool LoadGenesisBlock();
771
772 void TryAddBlockIndexCandidate(CBlockIndex* pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
773
774 void PruneBlockIndexCandidates();
775
776 void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
777
779 const CBlockIndex* FindForkInGlobalIndex(const CBlockLocator& locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main);
780
782 bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
783
787 CoinsCacheSizeState GetCoinsCacheSizeState() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
788
789 CoinsCacheSizeState GetCoinsCacheSizeState(
790 size_t max_coins_cache_size_bytes,
791 size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
792
794
796 RecursiveMutex* MempoolMutex() const LOCK_RETURNED(m_mempool->cs)
797 {
798 return m_mempool ? &m_mempool->cs : nullptr;
799 }
800
801protected:
802 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);
803 bool ConnectTip(
805 CBlockIndex* pindexNew,
806 std::shared_ptr<const CBlock> block_to_connect,
807 ConnectTrace& connectTrace,
809
810 void InvalidBlockFound(CBlockIndex* pindex, const BlockValidationState& state) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
811 CBlockIndex* FindMostWorkChain() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
812
813 bool RollforwardBlock(const CBlockIndex* pindex, CCoinsViewCache& inputs) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
814
815 void CheckForkWarningConditions() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
816 void InvalidChainFound(CBlockIndex* pindexNew) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
817
831 void MaybeUpdateMempoolForReorg(
832 DisconnectedBlockTransactions& disconnectpool,
833 bool fAddToMempool) EXCLUSIVE_LOCKS_REQUIRED(cs_main, m_mempool->cs);
834
836 void UpdateTip(const CBlockIndex* pindexNew)
838
839 NodeClock::time_point m_next_write{NodeClock::time_point::max()};
840
845 [[nodiscard]] util::Result<void> InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
846
848};
849
851 SUCCESS,
852 SKIPPED,
853
854 // Expected assumeutxo configuration data is not found for the height of the
855 // base block.
857
858 // Failed to generate UTXO statistics (to check UTXO set hash) for the background
859 // chainstate.
861
862 // The UTXO set hash of the background validation chainstate does not match
863 // the one expected by assumeutxo chainparams.
865
866 // The blockhash of the current tip of the background validation chainstate does
867 // not match the one expected by the snapshot chainstate.
869};
870
899{
900private:
917 std::unique_ptr<Chainstate> m_ibd_chainstate GUARDED_BY(::cs_main);
918
929 std::unique_ptr<Chainstate> m_snapshot_chainstate GUARDED_BY(::cs_main);
930
933 Chainstate* m_active_chainstate GUARDED_BY(::cs_main) {nullptr};
934
935 CBlockIndex* m_best_invalid GUARDED_BY(::cs_main){nullptr};
936
938 CBlockIndex* m_last_notified_header GUARDED_BY(GetMutex()){nullptr};
939
940 bool NotifyHeaderTip() LOCKS_EXCLUDED(GetMutex());
941
949 [[nodiscard]] util::Result<void> PopulateAndValidateSnapshot(
950 Chainstate& snapshot_chainstate,
951 AutoFile& coins_file,
952 const node::SnapshotMetadata& metadata);
953
961 bool AcceptBlockHeader(
962 const CBlockHeader& block,
964 CBlockIndex** ppindex,
965 bool min_pow_checked) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
967
969 MockableSteadyClock::time_point m_last_presync_update GUARDED_BY(GetMutex()){};
970
977 return cs && !cs->m_disabled;
978 }
979
982
985 SteadyClock::duration GUARDED_BY(::cs_main) time_check{};
986 SteadyClock::duration GUARDED_BY(::cs_main) time_forks{};
987 SteadyClock::duration GUARDED_BY(::cs_main) time_connect{};
988 SteadyClock::duration GUARDED_BY(::cs_main) time_verify{};
989 SteadyClock::duration GUARDED_BY(::cs_main) time_undo{};
990 SteadyClock::duration GUARDED_BY(::cs_main) time_index{};
991 SteadyClock::duration GUARDED_BY(::cs_main) time_total{};
992 int64_t GUARDED_BY(::cs_main) num_blocks_total{0};
993 SteadyClock::duration GUARDED_BY(::cs_main) time_connect_total{};
994 SteadyClock::duration GUARDED_BY(::cs_main) time_flush{};
995 SteadyClock::duration GUARDED_BY(::cs_main) time_chainstate{};
996 SteadyClock::duration GUARDED_BY(::cs_main) time_post_connect{};
997
998public:
1000
1001 explicit ChainstateManager(const util::SignalInterrupt& interrupt, Options options, node::BlockManager::Options blockman_options);
1002
1005 std::function<void()> snapshot_download_completed = std::function<void()>();
1006
1007 const CChainParams& GetParams() const { return m_options.chainparams; }
1008 const Consensus::Params& GetConsensus() const { return m_options.chainparams.GetConsensus(); }
1009 bool ShouldCheckBlockIndex() const;
1010 const arith_uint256& MinimumChainWork() const { return *Assert(m_options.minimum_chain_work); }
1011 const uint256& AssumedValidBlock() const { return *Assert(m_options.assumed_valid_block); }
1012 kernel::Notifications& GetNotifications() const { return m_options.notifications; };
1013
1019 void CheckBlockIndex() const;
1020
1033
1039
1041
1049 mutable std::atomic<bool> m_cached_finished_ibd{false};
1050
1056 int32_t nBlockSequenceId GUARDED_BY(::cs_main) = 1;
1058 int32_t nBlockReverseSequenceId = -1;
1060 arith_uint256 nLastPreciousChainwork = 0;
1061
1062 // Reset the memory-only sequence counters we use to track block arrival
1063 // (used by tests to reset state)
1065 {
1067 nBlockSequenceId = 1;
1068 nBlockReverseSequenceId = -1;
1069 }
1070
1071
1076 CBlockIndex* m_best_header GUARDED_BY(::cs_main){nullptr};
1077
1080 size_t m_total_coinstip_cache{0};
1081 //
1084 size_t m_total_coinsdb_cache{0};
1085
1089 // constructor
1090 Chainstate& InitializeChainstate(CTxMemPool* mempool) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1091
1093 std::vector<Chainstate*> GetAll();
1094
1107 [[nodiscard]] util::Result<CBlockIndex*> ActivateSnapshot(
1108 AutoFile& coins_file, const node::SnapshotMetadata& metadata, bool in_memory);
1109
1117 SnapshotCompletionResult MaybeCompleteSnapshotValidation() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1118
1120 const CBlockIndex* GetSnapshotBaseBlock() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1121
1123 Chainstate& ActiveChainstate() const;
1124 CChain& ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChainstate().m_chain; }
1125 int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Height(); }
1126 CBlockIndex* ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex()) { return ActiveChain().Tip(); }
1127
1130 return IsUsable(m_snapshot_chainstate.get()) && IsUsable(m_ibd_chainstate.get());
1131 }
1132
1135 return BackgroundSyncInProgress() ? m_ibd_chainstate->m_chain.Tip() : nullptr;
1136 }
1137
1139 {
1141 return m_blockman.m_block_index;
1142 }
1143
1148
1151 bool IsSnapshotActive() const;
1152
1153 std::optional<uint256> SnapshotBlockhash() const;
1154
1157 {
1158 return m_snapshot_chainstate && m_ibd_chainstate && m_ibd_chainstate->m_disabled;
1159 }
1160
1162 bool IsInitialBlockDownload() const;
1163
1165 double GuessVerificationProgress(const CBlockIndex* pindex) const EXCLUSIVE_LOCKS_REQUIRED(GetMutex());
1166
1194 AutoFile& file_in,
1195 FlatFilePos* dbp = nullptr,
1196 std::multimap<uint256, FlatFilePos>* blocks_with_unknown_parent = nullptr);
1197
1222 bool ProcessNewBlock(const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked, bool* new_block) LOCKS_EXCLUDED(cs_main);
1223
1236 bool ProcessNewBlockHeaders(std::span<const CBlockHeader> headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);
1237
1257 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);
1258
1259 void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos) EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1260
1267 [[nodiscard]] MempoolAcceptResult ProcessTransaction(const CTransactionRef& tx, bool test_accept=false)
1269
1271 bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);
1272
1275 void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1276
1278 void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev) const;
1279
1281 std::vector<unsigned char> GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev) const;
1282
1287 void ReportHeadersPresync(const arith_uint256& work, int64_t height, int64_t timestamp);
1288
1291 bool DetectSnapshotChainstate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1292
1293 void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1294
1297 [[nodiscard]] bool DeleteSnapshotChainstate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1298
1301 Chainstate& ActivateExistingSnapshot(uint256 base_blockhash) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1302
1312 bool ValidatedSnapshotCleanup() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1313
1322 Chainstate& GetChainstateForIndexing() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1323
1327 std::pair<int, int> GetPruneRange(
1328 const Chainstate& chainstate, int last_height_can_prune) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1329
1332 std::optional<int> GetSnapshotBaseHeight() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1333
1337 void RecalculateBestHeader() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);
1338
1339 CCheckQueue<CScriptCheck>& GetCheckQueue() { return m_script_check_queue; }
1340
1342};
1343
1345template<typename DEP>
1346bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const ChainstateManager& chainman, DEP dep)
1347{
1348 return DeploymentActiveAfter(pindexPrev, chainman.GetConsensus(), dep, chainman.m_versionbitscache);
1349}
1350
1351template<typename DEP>
1352bool DeploymentActiveAt(const CBlockIndex& index, const ChainstateManager& chainman, DEP dep)
1353{
1354 return DeploymentActiveAt(index, chainman.GetConsensus(), dep, chainman.m_versionbitscache);
1355}
1356
1357template<typename DEP>
1358bool DeploymentEnabled(const ChainstateManager& chainman, DEP dep)
1359{
1360 return DeploymentEnabled(chainman.GetConsensus(), dep);
1361}
1362
1364bool IsBIP30Repeat(const CBlockIndex& block_index);
1365
1367bool IsBIP30Unspendable(const uint256& block_hash, int block_height);
1368
1369// Returns the script flags which should be checked for a given block
1370script_verify_flags GetBlockScriptFlags(const CBlockIndex& block_index, const ChainstateManager& chainman);
1371
1372#endif // BITCOIN_VALIDATION_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
static void pool cs
int flags
Definition: bitcoin-tx.cpp:529
void InvalidateBlock(ChainstateManager &chainman, const uint256 block_hash)
const CChainParams & Params()
Return the currently selected parameters.
#define Assert(val)
Identity function.
Definition: check.h:115
#define Assume(val)
Assume is the identity function.
Definition: check.h:127
static void CheckBlockIndex(benchmark::Bench &bench)
Non-refcounted RAII wrapper for FILE*.
Definition: streams.h:371
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:22
Definition: block.h:69
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:141
An in-memory indexed chain of blocks.
Definition: chain.h:417
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Definition: chainparams.h:78
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: coins.h:361
CCoinsView backed by the coin database (chainstate/)
Definition: txdb.h:38
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Definition: coins.h:510
Abstract view on the open txout dataset.
Definition: coins.h:308
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:335
CScriptCheck & operator=(CScriptCheck &&)=default
SignatureCache * m_signature_cache
Definition: validation.h:343
CScriptCheck(const CScriptCheck &)=delete
PrecomputedTransactionData * txdata
Definition: validation.h:342
CTxOut m_tx_out
Definition: validation.h:337
script_verify_flags m_flags
Definition: validation.h:340
CScriptCheck(CScriptCheck &&)=default
bool cacheStore
Definition: validation.h:341
std::optional< std::pair< ScriptError, std::string > > operator()()
const CTransaction * ptxTo
Definition: validation.h:338
unsigned int nIn
Definition: validation.h:339
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, SignatureCache &signature_cache, unsigned int nInIn, script_verify_flags flags, bool cacheIn, PrecomputedTransactionData *txdataIn)
Definition: validation.h:346
CScriptCheck & operator=(const CScriptCheck &)=delete
The basic transaction that is broadcasted on the network and contained in blocks.
Definition: transaction.h:296
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
Definition: txmempool.h:281
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
Definition: txmempool.h:367
An output of a transaction.
Definition: transaction.h:150
RAII wrapper for VerifyDB: Verify consistency of the block and coin databases.
Definition: validation.h:432
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:434
CVerifyDB(kernel::Notifications &notifications)
Chainstate stores and provides an API to update our local knowledge of the current best chain.
Definition: validation.h:532
Mutex m_chainstate_mutex
The ChainState Mutex A lock that must be held when modifying this ChainState - held in ActivateBestCh...
Definition: validation.h:539
CChain m_chain
The current chain of blockheaders we consult and build on.
Definition: validation.h:614
bool HasCoinsViews() const
Does this chainstate have a UTXO set attached?
Definition: validation.h:672
CTxMemPool * GetMempool()
Definition: validation.h:655
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:621
CTxMemPool * m_mempool
Optional mempool that is kept in sync with the chain.
Definition: validation.h:543
bool m_disabled GUARDED_BY(::cs_main)
This toggle exists for use when doing background validation for UTXO snapshots.
Definition: validation.h:559
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:648
std::optional< const char * > m_last_script_check_reason_logged GUARDED_BY(::cs_main)
Definition: validation.h:564
ChainstateManager & m_chainman
The chainstate manager that owns this chainstate.
Definition: validation.h:574
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
Definition: validation.h:546
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
Definition: validation.h:669
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all Chainstate instances.
Definition: validation.h:569
const CBlockIndex *m_cached_snapshot_base GUARDED_BY(::cs_main)
Cached result of LookupBlockIndex(*m_from_snapshot_blockhash)
Definition: validation.h:562
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:662
Provides an interface for creating and interacting with one or two chainstates: an IBD chainstate gen...
Definition: validation.h:899
SteadyClock::duration GUARDED_BY(::cs_main) time_connect_total
Definition: validation.h:993
std::unique_ptr< Chainstate > m_ibd_chainstate GUARDED_BY(::cs_main)
The chainstate used under normal operation (i.e.
const uint256 & AssumedValidBlock() const
Definition: validation.h:1011
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
Definition: validation.h:1138
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:1076
ValidationCache m_validation_cache
Definition: validation.h:1040
int64_t GUARDED_BY(::cs_main) num_blocks_total
Definition: validation.h:992
SteadyClock::duration GUARDED_BY(::cs_main) time_undo
Definition: validation.h:989
SteadyClock::duration GUARDED_BY(::cs_main) time_index
Definition: validation.h:990
const CBlockIndex * GetBackgroundSyncTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
The tip of the background sync chain.
Definition: validation.h:1134
SteadyClock::duration GUARDED_BY(::cs_main) time_post_connect
Definition: validation.h:996
kernel::Notifications & GetNotifications() const
Definition: validation.h:1012
SteadyClock::duration GUARDED_BY(::cs_main) time_check
Timers and counters used for benchmarking validation in both background and active chainstates.
Definition: validation.h:985
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
Definition: validation.h:1032
SteadyClock::duration GUARDED_BY(::cs_main) time_total
Definition: validation.h:991
SteadyClock::duration GUARDED_BY(::cs_main) time_chainstate
Definition: validation.h:995
bool IsSnapshotValidated() const EXCLUSIVE_LOCKS_REQUIRED(
Is there a snapshot in use and has it been fully validated?
Definition: validation.h:1156
CCheckQueue< CScriptCheck > m_script_check_queue
A queue for script verifications that have to be performed by worker threads.
Definition: validation.h:981
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1126
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Definition: validation.h:935
SteadyClock::duration GUARDED_BY(::cs_main) time_forks
Definition: validation.h:986
bool BackgroundSyncInProgress() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
The state of a background sync (for net processing)
Definition: validation.h:1129
CBlockIndex *m_last_notified_header GUARDED_BY(GetMutex())
The last header for which a headerTip notification was issued.
Definition: validation.h:938
const util::SignalInterrupt & m_interrupt
Definition: validation.h:1034
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Definition: validation.h:1125
VersionBitsCache m_versionbitscache
Track versionbit status.
Definition: validation.h:1147
const CChainParams & GetParams() const
Definition: validation.h:1007
const Consensus::Params & GetConsensus() const
Definition: validation.h:1008
const arith_uint256 & MinimumChainWork() const
Definition: validation.h:1010
const Options m_options
Definition: validation.h:1035
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...
SteadyClock::duration GUARDED_BY(::cs_main) time_verify
Definition: validation.h:988
Chainstate *m_active_chainstate GUARDED_BY(::cs_main)
Points to either the ibd or snapshot chainstate; indicates our most-work chain.
Definition: validation.h:933
Chainstate &InitializeChainstate(CTxMemPool *mempool) EXCLUSIVE_LOCKS_REQUIRED(std::vector< Chainstate * GetAll)()
Instantiate a new chainstate.
Definition: validation.h:1093
SteadyClock::duration GUARDED_BY(::cs_main) time_connect
Definition: validation.h:987
bool IsUsable(const Chainstate *const cs) const EXCLUSIVE_LOCKS_REQUIRED(
Return true if a chainstate is considered usable.
Definition: validation.h:976
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:1064
node::BlockManager m_blockman
A single BlockManager instance is shared across each constructed chainstate to avoid duplicating bloc...
Definition: validation.h:1038
SteadyClock::duration GUARDED_BY(::cs_main) time_flush
Definition: validation.h:994
A convenience class for constructing the CCoinsView* hierarchy used to facilitate access to the UTXO ...
Definition: validation.h:474
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...
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:367
ValidationCache(size_t script_execution_cache_bytes, size_t signature_cache_bytes)
CuckooCache::cache< uint256, SignatureCacheHasher > m_script_execution_cache
Definition: validation.h:373
ValidationCache & operator=(const ValidationCache &)=delete
ValidationCache(const ValidationCache &)=delete
CSHA256 ScriptExecutionCacheHasher() const
Return a copy of the pre-initialized hasher.
Definition: validation.h:382
CSHA256 m_script_execution_cache_hasher
Pre-initialized hasher to avoid having to recreate it for every hash calculation.
Definition: validation.h:370
SignatureCache m_signature_cache
Definition: validation.h:374
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:139
Metadata describing a serialized version of a UTXO set from which an assumeutxo Chainstate can be con...
Definition: utxo_snapshot.h:34
transaction_identifier represents the two canonical transaction identifier types (txid,...
256-bit opaque blob.
Definition: uint256.h:196
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
ChainstateRole
This enum describes the various roles a specific Chainstate instance can take.
Definition: chain.h:25
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:87
std::string ToString(const T &t)
Locale-independent version of std::to_string.
Definition: string.h:245
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
Definition: packages.h:50
std::shared_ptr< const CTransaction > CTransactionRef
Definition: transaction.h:423
@ OK
The message verification was successful.
Holds configuration for use during UTXO snapshot load and validation.
Definition: chainparams.h:35
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:124
Holds various statistics on transactions within a chain.
Definition: chainparams.h:58
User-controlled performance and debug options.
Definition: txdb.h:28
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:127
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigops.
Definition: validation.h:144
const ResultType m_result_type
Result type.
Definition: validation.h:136
MempoolAcceptResult(int64_t vsize, CAmount fees)
Constructor for already-in-mempool case.
Definition: validation.h:221
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
Definition: validation.h:146
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
Definition: validation.h:193
const TxValidationState m_state
Contains information about why the transaction failed.
Definition: validation.h:139
ResultType
Used to indicate the results of mempool validation.
Definition: validation.h:129
static MempoolAcceptResult Failure(TxValidationState state)
Definition: validation.h:163
static MempoolAcceptResult FeeFailure(TxValidationState state, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Definition: validation.h:167
const std::optional< CFeeRate > m_effective_feerate
The feerate at which this transaction was considered.
Definition: validation.h:152
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:199
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:161
const std::list< CTransactionRef > m_replaced_transactions
Mempool transactions replaced by the tx.
Definition: validation.h:142
MempoolAcceptResult(const Wtxid &other_wtxid)
Constructor for witness-swapped case.
Definition: validation.h:225
static MempoolAcceptResult MempoolTxDifferentWitness(const Wtxid &other_wtxid)
Definition: validation.h:186
static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees)
Definition: validation.h:182
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:173
MempoolAcceptResult(TxValidationState state, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Constructor for fee-related failure case.
Definition: validation.h:212
const std::optional< std::vector< Wtxid > > m_wtxids_fee_calculations
Contains the wtxids of the transactions used for fee-related checks.
Definition: validation.h:158
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:233
PackageValidationState m_state
Definition: validation.h:234
PackageMempoolAcceptResult(const Wtxid &wtxid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a single MempoolAcceptResult.
Definition: validation.h:252
PackageMempoolAcceptResult(PackageValidationState state, CFeeRate feerate, std::map< Wtxid, MempoolAcceptResult > &&results)
Definition: validation.h:247
PackageMempoolAcceptResult(PackageValidationState state, std::map< Wtxid, MempoolAcceptResult > &&results)
Definition: validation.h:243
std::map< Wtxid, MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
Definition: validation.h:241
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...
#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:148
AssertLockHeld(pool.cs)
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:86
static constexpr int DEFAULT_CHECKLEVEL
Definition: validation.h:74
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
Definition: validation.h:83
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
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:247
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:72
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 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:1346
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:850
bool DeploymentEnabled(const ChainstateManager &chainman, DEP dep)
Definition: validation.h:1358
SynchronizationState
Current sync state passed to tip changed callbacks.
Definition: validation.h:89
constexpr std::array FlushStateModeNames
Definition: validation.h:457
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:313
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:509
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:422
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:101
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
FlushStateMode
Definition: validation.h:458
CoinsCacheSizeState
Definition: validation.h:501
@ 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:1352
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:73
DisconnectResult
Definition: validation.h:448
@ DISCONNECT_FAILED
Definition: validation.h:451
@ DISCONNECT_UNCLEAN
Definition: validation.h:450
@ DISCONNECT_OK
Definition: validation.h:449
bool IsBIP30Unspendable(const uint256 &block_hash, int block_height)
Identifies blocks which coinbase output was subsequently overwritten in the UTXO set (see BIP30)