Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1251* Process an incoming block. This only returns after the best known valid1252* block is made active. Note that it does not, however, guarantee that the1253* specific block passed to it has been checked for validity!1254*1255* If you want to *possibly* get feedback on whether block is valid, you must1256* install a CValidationInterface (see validationinterface.h) - this will have1257* its BlockChecked method called whenever *any* block completes validation.1258*1259* Note that we guarantee that either the proof-of-work is valid on block, or1260* (and possibly also) BlockChecked will have been called.1261*1262* May not be called in a validationinterface callback.1263*1264* @param[in] block The block we want to process.1265* @param[in] force_processing Process this block even if unrequested; used for non-network block sources.1266* @param[in] min_pow_checked True if proof-of-work anti-DoS checks have1267* been done by caller for headers chain1268* (note: only affects headers acceptance; if1269* block header is already present in block1270* index then this parameter has no effect)1271* @param[out] new_block A boolean which is set to indicate if the block was first received via this call1272* @returns If the block was processed, independently of block validity1273*/1274bool ProcessNewBlock(const std::shared_ptr<const CBlock>& block, bool force_processing, bool min_pow_checked, bool* new_block) LOCKS_EXCLUDED(cs_main);1276/**1277* Process incoming block headers.1278*1279* May not be called in a1280* validationinterface callback.1281*1282* @param[in] headers The block headers themselves1283* @param[in] min_pow_checked True if proof-of-work anti-DoS checks have been done by caller for headers chain1284* @param[out] state This may be set to an Error state if any error occurred processing them1285* @param[out] ppindex If set, the pointer will be set to point to the last new block index object for the given headers1286* @returns false if AcceptBlockHeader fails on any of the headers, true otherwise (including if headers were already known)1287*/1288bool ProcessNewBlockHeaders(std::span<const CBlockHeader> headers, bool min_pow_checked, BlockValidationState& state, const CBlockIndex** ppindex = nullptr) LOCKS_EXCLUDED(cs_main);1290/**1291* Sufficiently validate a block for disk storage (and store on disk).1292*1293* @param[in] pblock The block we want to process.1294* @param[in] fRequested Whether we requested this block from a1295* peer.1296* @param[in] dbp The location on disk, if we are importing1297* this block from prior storage.1298* @param[in] min_pow_checked True if proof-of-work anti-DoS checks have1299* been done by caller for headers chain1300*1301* @param[out] state The state of the block validation.1302* @param[out] ppindex Optional return parameter to get the1303* CBlockIndex pointer for this block.1304* @param[out] fNewBlock Optional return parameter to indicate if the1305* block is new to our storage.1306*1307* @returns False if the block or header is invalid, or if saving to disk fails (likely a fatal error); true otherwise.1308*/1309bool 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);1311void ReceivedBlockTransactions(const CBlock& block, CBlockIndex* pindexNew, const FlatFilePos& pos) EXCLUSIVE_LOCKS_REQUIRED(cs_main);1313/**1314* Try to add a transaction to the memory pool.1315*1316* @param[in] tx The transaction to submit for mempool acceptance.1317* @param[in] test_accept When true, run validation checks but don't submit to mempool.1318*/1319[[nodiscard]] MempoolAcceptResult ProcessTransaction(const CTransactionRef& tx, bool test_accept=false)1320EXCLUSIVE_LOCKS_REQUIRED(cs_main);1322//! Load the block tree and coins database from disk, initializing state if we're running with -reindex1323bool LoadBlockIndex() EXCLUSIVE_LOCKS_REQUIRED(cs_main);1325//! Check to see if caches are out of balance and if so, call1326//! ResizeCoinsCaches() as needed.1327void MaybeRebalanceCaches() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);1329/**1330* Update uncommitted block structures (currently: only the witness reserved1331* value). This is safe for submitted blocks as long as they honor1332* default_witness_commitment from the template.1333*/1334void UpdateUncommittedBlockStructures(CBlock& block, const CBlockIndex* pindexPrev) const;1336/** Produce the necessary coinbase commitment for a block (modifies the hash, don't call for mined blocks). */1337void GenerateCoinbaseCommitment(CBlock& block, const CBlockIndex* pindexPrev) const;1339/** This is used by net_processing to report pre-synchronization progress of headers, as1340* headers are not yet fed to validation during that time, but validation is (for now)1341* responsible for logging and signalling through NotifyHeaderTip, so it needs this1342* information. */1343void ReportHeadersPresync(int64_t height, int64_t timestamp);1345//! When starting up, search the datadir for a chainstate based on a UTXO1346//! snapshot that is in the process of being validated and load it if found.1347//! Return pointer to the Chainstate if it is loaded.1348Chainstate* LoadAssumeutxoChainstate() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);1350//! Add new chainstate.1351Chainstate& AddChainstate(std::unique_ptr<Chainstate> chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);1353void ResetChainstates() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);1355//! Remove the chainstate and all on-disk artifacts.1356//! Used when reindex{-chainstate} is called during snapshot use.1357[[nodiscard]] bool DeleteChainstate(Chainstate& chainstate) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);1359//! If we have validated a snapshot chain during this runtime, copy its1360//! chainstate directory over to the main `chainstate` location, completing1361//! validation of the snapshot.1362//!1363//! If the cleanup succeeds, the caller will need to ensure chainstates are1364//! reinitialized, since ResetChainstates() will be called before leveldb1365//! directories are moved or deleted.1366//!1367//! @sa node/chainstate:LoadChainstate()1368bool ValidatedSnapshotCleanup(Chainstate& validated_cs, Chainstate& unvalidated_cs) EXCLUSIVE_LOCKS_REQUIRED(::cs_main);1370//! Get range of historical blocks to download.1371std::optional<std::pair<const CBlockIndex*, const CBlockIndex*>> GetHistoricalBlockRange() const EXCLUSIVE_LOCKS_REQUIRED(::cs_main);1373//! Call ActivateBestChain() on every chainstate.1374util::Result<void> ActivateBestChains() LOCKS_EXCLUDED(::cs_main);1376//! If, due to invalidation / reconsideration of blocks, the previous1377//! best header is no longer valid / guaranteed to be the most-work1378//! header in our block-index not known to be invalid, recalculate it.1379void RecalculateBestHeader() EXCLUSIVE_LOCKS_REQUIRED(::cs_main);1381//! Returns how many blocks the best header is ahead of the current tip,1382//! or nullopt if the best header does not extend the tip.1383std::optional<int> BlocksAheadOfTip() const LOCKS_EXCLUDED(::cs_main);1385CCheckQueue<CScriptCheck>& GetCheckQueue() { return m_script_check_queue; }1387~ChainstateManager();1389//! List of chainstates. Note: in general, it is not safe to delete1390//! Chainstate objects once they are added to this list because there is no1391//! mutex that can be locked to prevent Chainstate pointers from being used1392//! while they are deleted. (cs_main doesn't work because it is too narrow1393//! and is released in the middle of Chainstate::ActivateBestChain to let1394//! notifications be processed. m_chainstate_mutex doesn't work because it1395//! is not locked at other times when the chainstate is in use.)1396std::vector<std::unique_ptr<Chainstate>> m_chainstates GUARDED_BY(::cs_main);1397};1399/** Deployment* info via ChainstateManager */1400template<typename DEP>1401bool DeploymentActiveAfter(const CBlockIndex* pindexPrev, const ChainstateManager& chainman, DEP dep)1402{1403return DeploymentActiveAfter(pindexPrev, chainman.GetConsensus(), dep, chainman.m_versionbitscache);1404}1406template<typename DEP>1407bool DeploymentActiveAt(const CBlockIndex& index, const ChainstateManager& chainman, DEP dep)1408{1409return DeploymentActiveAt(index, chainman.GetConsensus(), dep, chainman.m_versionbitscache);1410}1412template<typename DEP>1413bool DeploymentEnabled(const ChainstateManager& chainman, DEP dep)1414{1415return DeploymentEnabled(chainman.GetConsensus(), dep);1416}1418/** Identifies blocks that overwrote an existing coinbase output in the UTXO set (see BIP30) */1419bool IsBIP30Repeat(const CBlockIndex& block_index);1421/** Identifies blocks which coinbase output was subsequently overwritten in the UTXO set (see BIP30) */1422bool IsBIP30Unspendable(const uint256& block_hash, int block_height);1424// Returns the script flags which should be checked for a given block1425script_verify_flags GetBlockScriptFlags(const CBlockIndex& block_index, const ChainstateManager& chainman);1427#endif // BITCOIN_VALIDATION_H
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.