Inside Bitcoin
Opening the selected file…
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.
1// Copyright (c) 2020-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#ifndef BITCOIN_INDEX_COINSTATSINDEX_H6#define BITCOIN_INDEX_COINSTATSINDEX_H8#include <arith_uint256.h>9#include <consensus/amount.h>10#include <crypto/muhash.h>11#include <index/base.h>12#include <interfaces/chain.h>13#include <uint256.h>15#include <cstddef>16#include <cstdint>17#include <memory>18#include <optional>20class CBlockIndex;21namespace kernel {22struct CCoinsStats;23}25inline constexpr bool DEFAULT_COINSTATSINDEX{false};27/**28* CoinStatsIndex maintains statistics on the UTXO set.29*/30class CoinStatsIndex final : public BaseIndex31{32private:33std::unique_ptr<BaseIndex::DB> m_db;35MuHash3072 m_muhash;36uint64_t m_transaction_output_count{0};37uint64_t m_bogo_size{0};38CAmount m_total_amount{0};39CAmount m_total_subsidy{0};40arith_uint256 m_total_prevout_spent_amount{0};41arith_uint256 m_total_new_outputs_ex_coinbase_amount{0};42arith_uint256 m_total_coinbase_amount{0};43CAmount m_total_unspendables_genesis_block{0};44CAmount m_total_unspendables_bip30{0};45CAmount m_total_unspendables_scripts{0};46CAmount m_total_unspendables_unclaimed_rewards{0};48uint256 m_current_block_hash{};50[[nodiscard]] bool RevertBlock(const interfaces::BlockInfo& block);52bool AllowPrune() const override { return true; }54protected:55bool CustomInit(const std::optional<interfaces::BlockRef>& block) override;57bool CustomCommit(CDBBatch& batch) override;59bool CustomAppend(const interfaces::BlockInfo& block) override;61bool CustomRemove(const interfaces::BlockInfo& block) override;63BaseIndex::DB& GetDB() const override { return *m_db; }65public:66// Constructs the index, which becomes available to be queried.67explicit CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);69interfaces::Chain::NotifyOptions CustomOptions() override;71// Look up stats for a specific block using CBlockIndex72std::optional<kernel::CCoinsStats> LookUpStats(const CBlockIndex& block_index) const;73};75/// The global UTXO set hash object.76extern std::unique_ptr<CoinStatsIndex> g_coin_stats_index;78#endif // BITCOIN_INDEX_COINSTATSINDEX_H