6#ifndef BITCOIN_VALIDATION_H
7#define BITCOIN_VALIDATION_H
173 const std::vector<Wtxid>& wtxids_fee_calculations) {
181 const std::vector<Wtxid>& wtxids_fee_calculations) {
183 effective_feerate, wtxids_fee_calculations);
207 const std::vector<Wtxid>& wtxids_fee_calculations)
218 const std::vector<Wtxid>& wtxids_fee_calculations)
248 std::map<Wtxid, MempoolAcceptResult>&& results)
252 std::map<Wtxid, MempoolAcceptResult>&& results)
275 int64_t accept_time,
bool bypass_limits,
bool test_accept)
289 const Package& txns,
bool test_accept,
const std::optional<CFeeRate>& client_maxfeerate)
358 std::optional<std::pair<ScriptError, std::string>>
operator()();
362static_assert(std::is_nothrow_move_assignable_v<CScriptCheck>);
363static_assert(std::is_nothrow_move_constructible_v<CScriptCheck>);
364static_assert(std::is_nothrow_destructible_v<CScriptCheck>);
380 ValidationCache(
size_t script_execution_cache_bytes,
size_t signature_cache_bytes);
461inline constexpr std::array
FlushStateModeNames{
"NONE",
"IF_NEEDED",
"PERIODIC",
"FORCE_FLUSH",
"FORCE_SYNC"};
521 constexpr int64_t MAX_BLOCK_COINSDB_USAGE_BYTES{int64_t(10_MiB)};
522 return std::max((total_space * 9) / 10,
523 total_space - MAX_BLOCK_COINSDB_USAGE_BYTES);
589 std::optional<uint256> from_snapshot_blockhash = std::nullopt);
607 size_t cache_size_bytes,
673 return target_block && target_block ==
m_chain.Tip();
725 bool ResizeCoinsCaches(
size_t coinstip_size,
size_t coinsdb_size)
739 bool FlushStateToDisk(
742 int nManualPruneHeight = 0);
745 void ForceFlushStateToDisk(
bool wipe_cache =
true);
749 void PruneAndFlush();
772 bool ActivateBestChain(
774 std::shared_ptr<const CBlock> pblock =
nullptr)
837 size_t max_coins_cache_size_bytes,
858 std::shared_ptr<const CBlock> block_to_connect,
883 void MaybeUpdateMempoolForReorg(
955 [[nodiscard]]
util::Result<
void> PopulateAndValidateSnapshot(
967 bool AcceptBlockHeader(
1009 bool ShouldCheckBlockIndex()
const;
1121 for (
auto&
cs : m_chainstates) {
1130 for (
auto&
cs : m_chainstates) {
1150 auto it{std::find_if(m_chainstates.begin(), m_chainstates.end(), [&](
auto&
cs) { return cs.get() == &chainstate; })};
1151 if (it != m_chainstates.end()) {
1152 auto ret{std::move(*it)};
1153 m_chainstates.erase(it);
1381template<
typename DEP>
1387template<
typename DEP>
1393template<
typename DEP>
1406script_verify_flags
GetBlockScriptFlags(
const CBlockIndex& block_index,
const ChainstateManager& chainman);
int64_t CAmount
Amount in satoshis (Can be negative).
std::string ToString(const T &t)
Locale-independent version of std::to_string.
void InvalidateBlock(ChainstateManager &chainman, const uint256 block_hash)
static constexpr int32_t SEQ_ID_INIT_FROM_DISK
#define Assert(val)
Identity function.
#define Assume(val)
Assume is the identity function.
static void CheckBlockIndex(benchmark::Bench &bench)
Non-refcounted RAII wrapper for FILE*.
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
An in-memory indexed chain of blocks.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
Queue for verifications that have to be performed.
CCoinsView that adds a memory cache for transactions to another CCoinsView.
CCoinsView backed by the coin database (chainstate/).
This is a minimally invasive approach to shutdown on LevelDB read errors from the chainstate,...
Abstract view on the open txout dataset.
Fee rate in satoshis per virtualbyte: CAmount / vB the feerate is represented internally as FeeFrac.
A hasher class for SHA-256.
Closure representing one script verification Note that this stores references to the spending transac...
CScriptCheck & operator=(CScriptCheck &&)=default
SignatureCache * m_signature_cache
CScriptCheck(const CScriptCheck &)=delete
PrecomputedTransactionData * txdata
script_verify_flags m_flags
CScriptCheck(CScriptCheck &&)=default
std::optional< std::pair< ScriptError, std::string > > operator()()
const CTransaction * ptxTo
CScriptCheck(const CTxOut &outIn, const CTransaction &txToIn, SignatureCache &signature_cache, unsigned int nInIn, script_verify_flags flags, bool cacheIn, PrecomputedTransactionData *txdataIn)
CScriptCheck & operator=(const CScriptCheck &)=delete
The basic transaction that is broadcasted on the network and contained in blocks.
CTxMemPool stores valid-according-to-the-current-best-chain transactions that may be included in the ...
RecursiveMutex cs
This mutex needs to be locked when accessing mapTx or other members that are guarded by it.
An output of a transaction.
VerifyDBResult VerifyDB(Chainstate &chainstate, const Consensus::Params &consensus_params, CCoinsView &coinsview, int nCheckLevel, int nCheckDepth) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
kernel::Notifications & m_notifications
CVerifyDB(kernel::Notifications ¬ifications)
Chainstate stores and provides an API to update our local knowledge of the current best chain.
void InitCoinsCache(size_t cache_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(bool CanFlushToDisk() const EXCLUSIVE_LOCKS_REQUIRED(
Mutex m_chainstate_mutex
The ChainState Mutex A lock that must be held when modifying this ChainState - held in ActivateBestCh...
std::optional< uint256 > m_target_blockhash GUARDED_BY(::cs_main)
CTxMemPool * GetMempool()
size_t m_coinstip_cache_size_bytes
The cache size of the in-memory coins view.
void UpdateTip(const CBlockIndex *pindexNew) EXCLUSIVE_LOCKS_REQUIRED(NodeClock::time_poin m_next_write)
Check warning conditions and do some notifications on new chain tip set.
CCoinsViewCache & CoinsTip() EXCLUSIVE_LOCKS_REQUIRED(
bool LoadChainTip() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Update the chain tip based on database information, i.e.
size_t m_coinsdb_cache_size_bytes
The cache size of the on-disk coins view.
bool PreciousBlock(BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(bool InvalidateBlock(BlockValidationState &state, CBlockIndex *pindex) LOCKS_EXCLUDED(void SetBlockFailureFlags(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(voi ResetBlockFailureFlags)(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark a block as precious and reorganize.
const CBlockIndex *SnapshotBase() const EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex *TargetBlock() const EXCLUSIVE_LOCKS_REQUIRED(void SetTargetBlock(CBlockIndex *block) EXCLUSIVE_LOCKS_REQUIRED(void SetTargetBlockHash(uint256 block_hash) EXCLUSIVE_LOCKS_REQUIRED(boo ReachedTarget)() const EXCLUSIVE_LOCKS_REQUIRED(
The base of the snapshot this chainstate was created from.
bool LoadGenesisBlock()
Ensures we have a genesis block in the block tree, possibly writing one to disk.
kernel::ChainstateRole GetRole() const EXCLUSIVE_LOCKS_REQUIRED(void InitCoinsDB(size_t cache_size_bytes, bool in_memory, bool should_wipe)
Initialize the CoinsViews UTXO set database management data structures.
const std::optional< uint256 > m_from_snapshot_blockhash
The blockhash which is the base of the snapshot this chainstate was created from.
bool ActivateBestChain(BlockValidationState &state, std::shared_ptr< const CBlock > pblock=nullptr) LOCKS_EXCLUDED(DisconnectResult DisconnectBlock(const CBlock &block, const CBlockIndex *pindex, CCoinsViewCache &view) EXCLUSIVE_LOCKS_REQUIRED(boo ConnectBlock)(const CBlock &block, BlockValidationState &state, CBlockIndex *pindex, CCoinsViewCache &view, bool fJustCheck=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Find the best known block, and make it the tip of the block chain.
CCoinsViewDB & CoinsDB() EXCLUSIVE_LOCKS_REQUIRED(
std::optional< const char * > m_last_script_check_reason_logged GUARDED_BY(::cs_main)
const CBlockIndex *m_cached_target_block GUARDED_BY(::cs_main)
Cached result of LookupBlockIndex(*m_target_blockhash).
bool DisconnectTip(BlockValidationState &state, DisconnectedBlockTransactions *disconnectpool) EXCLUSIVE_LOCKS_REQUIRED(cs_main
Disconnect m_chain's tip.
std::set< CBlockIndex *, node::CBlockIndexWorkComparator > setBlockIndexCandidates
The set of all CBlockIndex entries that have as much work as our current tip or more,...
util::Result< void > InvalidateCoinsDBOnDisk() EXCLUSIVE_LOCKS_REQUIRED(friend ChainstateManager
In case of an invalid snapshot, rename the coins leveldb directory so that it can be examined for iss...
ChainstateManager & m_chainman
std::unique_ptr< CoinsViews > m_coins_views
Manages the UTXO set, which is a reflection of the contents of m_chain.
bool ReplayBlocks()
Replay blocks that aren't fully applied to the database.
void PruneBlockIndexCandidates()
Delete all entries in setBlockIndexCandidates that are worse than the current tip.
Assumeutxo m_assumeutxo GUARDED_BY(::cs_main)
std::optional< AssumeutxoHash > m_target_utxohash GUARDED_BY(::cs_main)
void ResetCoinsViews()
Destructs all objects related to accessing the UTXO set.
void TryAddBlockIndexCandidate(CBlockIndex *pindex) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Add a block to the candidate set if it has as much work as the current tip.
node::BlockManager & m_blockman
const CBlockIndex *m_cached_snapshot_base GUARDED_BY(::cs_main)
Cached result of LookupBlockIndex(*m_from_snapshot_blockhash).
CCoinsViewErrorCatcher & CoinsErrorCatcher() EXCLUSIVE_LOCKS_REQUIRED(
void ClearBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(void PopulateBlockIndexCandidates() EXCLUSIVE_LOCKS_REQUIRED(const CBlockIndex * FindForkInGlobalIndex(const CBlockLocator &locator) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Populate the candidate set by calling TryAddBlockIndexCandidate on all valid block indices.
Chainstate(CTxMemPool *mempool, node::BlockManager &blockman, ChainstateManager &chainman, std::optional< uint256 > from_snapshot_blockhash=std::nullopt)
fs::path StoragePath() const
Return path to chainstate leveldb directory.
bool NeedsRedownload() const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Whether the chain state needs to be redownloaded due to lack of witness data.
CoinsCacheSizeState GetCoinsCacheSizeState() EXCLUSIVE_LOCKS_REQUIRED(CoinsCacheSizeState GetCoinsCacheSizeState(size_t max_coins_cache_size_bytes, size_t max_mempool_size_bytes) EXCLUSIVE_LOCKS_REQUIRED(std::string ToString() EXCLUSIVE_LOCKS_REQUIRED(RecursiveMutex * MempoolMutex() const LOCK_RETURNED(m_mempool -> cs)
Indirection necessary to make lock annotations work with an optional mempool.
Interface for managing multiple Chainstate objects, where each chainstate is associated with chainsta...
SteadyClock::duration GUARDED_BY(::cs_main) time_connect_total
kernel::ChainstateManagerOpts Options
Chainstate * HistoricalChainstate() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Return historical chainstate targeting a specific block, if any.
Chainstate *LoadAssumeutxoChainstate() EXCLUSIVE_LOCKS_REQUIRED(Chainstate &AddChainstate(std::unique_ptr< Chainstate > chainstate) EXCLUSIVE_LOCKS_REQUIRED(void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(bool DeleteChainstate(Chainstate &chainstate) EXCLUSIVE_LOCKS_REQUIRED(bool ValidatedSnapshotCleanup(Chainstate &validated_cs, Chainstate &unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(std::optional< std::pair< const CBlockIndex *, const CBlockIndex * > > GetHistoricalBlockRange() const EXCLUSIVE_LOCKS_REQUIRED(util::Result< void > ActivateBestChains() LOCKS_EXCLUDED(void RecalculateBestHeader() EXCLUSIVE_LOCKS_REQUIRED(std::optional< int > BlocksAheadOfTip() const LOCKS_EXCLUDED(CCheckQueue< CScriptCheck > GetCheckQueue)()
Add new chainstate.
const uint256 & AssumedValidBlock() const
node::BlockMap & BlockIndex() EXCLUSIVE_LOCKS_REQUIRED(
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,...
ValidationCache m_validation_cache
int64_t GUARDED_BY(::cs_main) num_blocks_total
SteadyClock::duration GUARDED_BY(::cs_main) time_undo
SteadyClock::duration GUARDED_BY(::cs_main) time_index
SnapshotCompletionResult MaybeValidateSnapshot(Chainstate &validated_cs, Chainstate &unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(Chainstate CurrentChainstate)() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Return current chainstate targeting the most-work, network tip.
double GuessVerificationProgress(const CBlockIndex *pindex) const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Guess verification progress (as a fraction between 0.0=genesis and 1.0=current tip).
bool IsInitialBlockDownload() const noexcept
Check whether we are doing an initial block download (synchronizing from disk or network).
size_t m_total_coinstip_cache
MempoolAcceptResult ProcessTransaction(const CTransactionRef &tx, bool test_accept=false) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Try to add a transaction to the memory pool.
SteadyClock::duration GUARDED_BY(::cs_main) time_post_connect
std::unique_ptr< Chainstate > RemoveChainstate(Chainstate &chainstate) EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
Remove a chainstate.
kernel::Notifications & GetNotifications() const
void ReceivedBlockTransactions(const CBlock &block, CBlockIndex *pindexNew, const FlatFilePos &pos) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Mark a block as having its data received and checked (up to BLOCK_VALID_TRANSACTIONS).
SteadyClock::duration GUARDED_BY(::cs_main) time_check
RecursiveMutex & GetMutex() const LOCK_RETURNED(
Alias for cs_main.
SteadyClock::duration GUARDED_BY(::cs_main) time_total
SteadyClock::duration GUARDED_BY(::cs_main) time_chainstate
CCheckQueue< CScriptCheck > m_script_check_queue
A queue for script verifications that have to be performed by worker threads.
CBlockIndex * ActiveTip() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
CBlockIndex *m_best_invalid GUARDED_BY(::cs_main)
Chainstate & ActiveChainstate() const
SteadyClock::duration GUARDED_BY(::cs_main) time_forks
bool ProcessNewBlock(const std::shared_ptr< const CBlock > &block, bool force_processing, bool min_pow_checked, bool *new_block) LOCKS_EXCLUDED(cs_main)
Process an incoming block.
size_t m_total_coinsdb_cache
CBlockIndex *m_last_notified_header GUARDED_BY(GetMutex())
The last header for which a headerTip notification was issued.
std::vector< std::unique_ptr< Chainstate > > m_chainstates GUARDED_BY(::cs_main)
const util::SignalInterrupt & m_interrupt
void LoadExternalBlockFile(AutoFile &file_in, FlatFilePos *dbp=nullptr, std::multimap< uint256, FlatFilePos > *blocks_with_unknown_parent=nullptr)
Import blocks from an external file.
int ActiveHeight() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
VersionBitsCache m_versionbitscache
Track versionbit status.
Chainstate & ValidatedChainstate() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
std::function< void()> snapshot_download_completed
const CChainParams & GetParams() const
void GenerateCoinbaseCommitment(CBlock &block, const CBlockIndex *pindexPrev) const
Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks...
bool ProcessNewBlockHeaders(std::span< const CBlockHeader > headers, bool min_pow_checked, BlockValidationState &state, const CBlockIndex **ppindex=nullptr) LOCKS_EXCLUDED(cs_main)
Process incoming block headers.
const Consensus::Params & GetConsensus() const
ChainstateManager(const util::SignalInterrupt &interrupt, Options options, node::BlockManager::Options blockman_options)
const arith_uint256 & MinimumChainWork() const
bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Load the block tree and coins database from disk, initializing state if we're running with -reindex.
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)
SteadyClock::duration GUARDED_BY(::cs_main) time_verify
CChain & ActiveChain() const EXCLUSIVE_LOCKS_REQUIRED(GetMutex())
arith_uint256 nLastPreciousChainwork
chainwork for the last block that preciousblock has been applied to.
void ReportHeadersPresync(int64_t height, int64_t timestamp)
This is used by net_processing to report pre-synchronization progress of headers, as headers are not ...
std::atomic_bool m_cached_is_ibd
Whether initial block download (IBD) is ongoing.
void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(void UpdateUncommittedBlockStructures(CBlock &block, const CBlockIndex *pindexPrev) const
Update uncommitted block structures (currently: only the witness reserved value).
SteadyClock::duration GUARDED_BY(::cs_main) time_connect
void ResetBlockSequenceCounters() EXCLUSIVE_LOCKS_REQUIRED(
int32_t nBlockReverseSequenceId
Decreasing counter (used by subsequent preciousblock calls).
node::BlockManager m_blockman
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)
Sufficiently validate a block for disk storage (and store on disk).
SteadyClock::duration GUARDED_BY(::cs_main) time_flush
std::unique_ptr< CCoinsViewCache > m_cacheview GUARDED_BY(cs_main)
CCoinsViewErrorCatcher m_catcherview GUARDED_BY(cs_main)
This view wraps access to the leveldb instance and handles read errors gracefully.
std::unique_ptr< CoinsViewOverlay > m_connect_block_view GUARDED_BY(cs_main)
CCoinsViewDB m_dbview GUARDED_BY(cs_main)
CoinsViews(DBParams db_params, CoinsViewOptions options)
Used to track blocks whose transactions were applied to the UTXO state as a part of a single Activate...
cache implements a cache with properties similar to a cuckoo-set.
DisconnectedBlockTransactions.
Valid signature cache, to avoid doing expensive ECDSA signature checking twice for every transaction ...
Convenience class for initializing and passing the script execution cache and signature cache.
ValidationCache(size_t script_execution_cache_bytes, size_t signature_cache_bytes)
CuckooCache::cache< uint256, SignatureCacheHasher > m_script_execution_cache
ValidationCache & operator=(const ValidationCache &)=delete
ValidationCache(const ValidationCache &)=delete
CSHA256 ScriptExecutionCacheHasher() const
Return a copy of the pre-initialized hasher.
CSHA256 m_script_execution_cache_hasher
Pre-initialized hasher to avoid having to recreate it for every hash calculation.
SignatureCache m_signature_cache
BIP 9 allows multiple softforks to be deployed in parallel.
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...
kernel::BlockManagerOpts Options
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.
bool DeploymentActiveAfter(const CBlockIndex *pindexPrev, const Consensus::Params ¶ms, Consensus::BuriedDeployment dep, VersionBitsCache &versionbitscache)
Determine if a deployment is active for the next block.
bool DeploymentEnabled(const Consensus::Params ¶ms, Consensus::BuriedDeployment dep)
Determine if a deployment is enabled (can ever be active).
bool DeploymentActiveAt(const CBlockIndex &index, const Consensus::Params ¶ms, Consensus::BuriedDeployment dep, VersionBitsCache &versionbitscache)
Determine if a deployment is active for this block.
Transaction validation functions.
std::vector< CTransactionRef > Package
A package is an ordered list of transactions.
std::shared_ptr< const CTransaction > CTransactionRef
Holds configuration for use during UTXO snapshot load and validation.
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Holds various statistics on transactions within a chain.
User-controlled performance and debug options.
Parameters that influence chain consensus.
Application-specific storage settings.
Validation result for a transaction evaluated by MemPoolAccept (single or package).
const std::optional< int64_t > m_vsize
Virtual size as used by the mempool, calculated using serialized size and sigops.
const ResultType m_result_type
Result type.
MempoolAcceptResult(int64_t vsize, CAmount fees)
Constructor for already-in-mempool case.
const std::optional< CAmount > m_base_fees
Raw base fees in satoshis.
MempoolAcceptResult(TxValidationState state)
Constructor for failure case.
const TxValidationState m_state
Contains information about why the transaction failed.
ResultType
Used to indicate the results of mempool validation.
static MempoolAcceptResult Failure(TxValidationState state)
static MempoolAcceptResult FeeFailure(TxValidationState state, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
const std::optional< CFeeRate > m_effective_feerate
The feerate at which this transaction was considered.
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.
const std::optional< Wtxid > m_other_wtxid
The wtxid of the transaction in the mempool which has the same txid but different witness.
const std::list< CTransactionRef > m_replaced_transactions
Mempool transactions replaced by the tx.
MempoolAcceptResult(const Wtxid &other_wtxid)
Constructor for witness-swapped case.
static MempoolAcceptResult MempoolTxDifferentWitness(const Wtxid &other_wtxid)
static MempoolAcceptResult MempoolTx(int64_t vsize, CAmount fees)
static MempoolAcceptResult Success(std::list< CTransactionRef > &&replaced_txns, int64_t vsize, CAmount fees, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
MempoolAcceptResult(TxValidationState state, CFeeRate effective_feerate, const std::vector< Wtxid > &wtxids_fee_calculations)
Constructor for fee-related failure case.
const std::optional< std::vector< Wtxid > > m_wtxids_fee_calculations
Contains the wtxids of the transactions used for fee-related checks.
Version of SteadyClock that is mockable in the context of tests (set the current value with SetMockTi...
Mockable clock in the context of tests, otherwise the system clock.
Validation result for package mempool acceptance.
PackageValidationState m_state
PackageMempoolAcceptResult(const Wtxid &wtxid, const MempoolAcceptResult &result)
Constructor to create a PackageMempoolAcceptResult from a single MempoolAcceptResult.
PackageMempoolAcceptResult(PackageValidationState state, CFeeRate feerate, std::map< Wtxid, MempoolAcceptResult > &&results)
PackageMempoolAcceptResult(PackageValidationState state, std::map< Wtxid, MempoolAcceptResult > &&results)
std::map< Wtxid, MempoolAcceptResult > m_tx_results
Map from wtxid to finished MempoolAcceptResults.
An options struct for ChainstateManager, more ergonomically referred to as ChainstateManager::Options...
Information about chainstate that notifications are sent from.
AnnotatedMixin< std::mutex > Mutex
Wrapped mutex: supports waiting but not recursive locking.
AnnotatedMixin< std::recursive_mutex > RecursiveMutex
Wrapped mutex: supports recursive locking, but no waiting TODO: We should move away from using the re...
#define AssertLockHeld(cs)
#define EXCLUSIVE_LOCKS_REQUIRED(...)
#define LOCKS_EXCLUDED(...)
transaction_identifier< true > Wtxid
Wtxid commits to all transaction fields including the witness.
script_verify_flags GetBlockScriptFlags(const CBlockIndex &block_index, const ChainstateManager &chainman)
std::unordered_map< uint256, CBlockIndex, BlockHasher > BlockMap
bool CheckFinalTxAtTip(const CBlockIndex &active_chain_tip, const CTransaction &tx)
const std::vector< std::string > CHECKLEVEL_DOC
Documentation for argument 'checklevel'.
bool IsBIP30Repeat(const CBlockIndex &block_index)
Identifies blocks that overwrote an existing coinbase output in the UTXO set (see BIP30).
bool IsBIP30Unspendable(const uint256 &block_hash, int block_height)
Identifies blocks which coinbase output was subsequently overwritten in the UTXO set (see BIP30).
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).
static constexpr int MAX_SCRIPTCHECK_THREADS
Maximum number of dedicated script-checking threads allowed.
static constexpr int DEFAULT_CHECKLEVEL
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.
static const uint64_t MIN_DISK_SPACE_FOR_BLOCK_FILES
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.
bool FatalError(kernel::Notifications ¬ifications, 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...
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.
BlockValidationState TestBlockValidity(Chainstate &chainstate, const CBlock &block, bool check_pow, bool check_merkle_root) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Verify a block, including transactions.
Assumeutxo
Chainstate assumeutxo validity.
@ 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.
constexpr std::array FlushStateModeNames
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
arith_uint256 CalculateClaimedHeadersWork(std::span< const CBlockHeader > headers)
Return the sum of the claimed work on a given set of headers.
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.
void PruneBlockFilesManual(Chainstate &active_chainstate, int nManualPruneHeight)
Prune block files up to a given height.
@ LARGE
The cache is at >= 90% capacity.
@ CRITICAL
The coins cache is in immediate need of a flush.
static const signed int DEFAULT_CHECKBLOCKS