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.
751{752StopFetching();753CCoinsViewCache::Reset();754}756public:757explicit CoinsViewOverlay(CCoinsView* in_base, std::shared_ptr<ThreadPool> thread_pool,758bool deterministic = false) noexcept759: CCoinsViewCache{in_base, deterministic}, m_thread_pool{std::move(thread_pool)}760{761Assert(m_thread_pool);762}764~CoinsViewOverlay() noexcept override { StopFetching(); }766//! Start fetching inputs from block.767[[nodiscard]] ResetGuard StartFetching(const CBlock& block LIFETIMEBOUND) noexcept;769void Flush(bool reallocate_cache = true) override770{771if (!Assume(AllInputsConsumed())) {772LogWarning("Block %s input prevout prefetch queue was not fully consumed; inputs were accessed out of order, so prefetching degraded to serial lookups for this block.", GetBestBlock().ToString());773}774StopFetching();775CCoinsViewCache::Flush(reallocate_cache);776}778//! Swapping the backend or writing through to it with Sync() is not supported while fetching.779void SetBackend(CCoinsView&) = delete;780void Sync() = delete;782//! Verify that all parallel fetched input prevouts have been consumed.783bool AllInputsConsumed() const noexcept { return m_input_tail == m_inputs.size(); }784};786//! Utility function to add all of a transaction's outputs to a cache.787//! When check is false, this assumes that overwrites are only possible for coinbase transactions.788//! When check is true, the underlying view may be queried to determine whether an addition is789//! an overwrite.790// TODO: pass in a boolean to limit these possible overwrites to known791// (pre-BIP34) cases.792void AddCoins(CCoinsViewCache& cache, const CTransaction& tx, int nHeight, bool check = false);794//! Utility function to find any unspent output with a given txid.795//! This function can be quite expensive because in the event of a transaction796//! which is not found in the cache, it can cause up to MAX_OUTPUTS_PER_BLOCK797//! lookups to database, so it should be used with care.798const Coin& AccessByTxid(const CCoinsViewCache& cache, const Txid& txid);800/**801* This is a minimally invasive approach to shutdown on LevelDB read errors from the802* chainstate, while keeping user interface out of the common library, which is shared803* between bitcoind, and bitcoin-qt and non-server tools.804*805* Writes do not need similar protection, as failure to write is handled by the caller.806*/807class CCoinsViewErrorCatcher final : public CCoinsViewBacked808{809public:810explicit CCoinsViewErrorCatcher(CCoinsView* view) : CCoinsViewBacked(view) {}812void AddReadErrCallback(std::function<void()> f) {813m_err_callbacks.emplace_back(std::move(f));814}816std::optional<Coin> GetCoin(const COutPoint& outpoint) const override;817bool HaveCoin(const COutPoint& outpoint) const override;818std::optional<Coin> PeekCoin(const COutPoint& outpoint) const override;820private:821/** A list of callbacks to execute upon leveldb read error. */822std::vector<std::function<void()>> m_err_callbacks;824};826#endif // BITCOIN_COINS_H