Bitcoin Core 30.99.0
P2P Digital Currency
coinstatsindex.h
Go to the documentation of this file.
1// Copyright (c) 2020-2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#ifndef BITCOIN_INDEX_COINSTATSINDEX_H
6#define BITCOIN_INDEX_COINSTATSINDEX_H
7
8#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>
14
15#include <cstddef>
16#include <cstdint>
17#include <memory>
18#include <optional>
19
20class CBlockIndex;
21namespace kernel {
22struct CCoinsStats;
23}
24
25static constexpr bool DEFAULT_COINSTATSINDEX{false};
26
30class CoinStatsIndex final : public BaseIndex
31{
32private:
33 std::unique_ptr<BaseIndex::DB> m_db;
34
37 uint64_t m_bogo_size{0};
47
49
50 [[nodiscard]] bool RevertBlock(const interfaces::BlockInfo& block);
51
52 bool AllowPrune() const override { return true; }
53
54protected:
56
57 bool CustomInit(const std::optional<interfaces::BlockRef>& block) override;
58
59 bool CustomCommit(CDBBatch& batch) override;
60
61 bool CustomAppend(const interfaces::BlockInfo& block) override;
62
63 bool CustomRemove(const interfaces::BlockInfo& block) override;
64
65 BaseIndex::DB& GetDB() const override { return *m_db; }
66
67public:
68 // Constructs the index, which becomes available to be queried.
69 explicit CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
70
71 // Look up stats for a specific block using CBlockIndex
72 std::optional<kernel::CCoinsStats> LookUpStats(const CBlockIndex& block_index) const;
73};
74
76extern std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
77
78#endif // BITCOIN_INDEX_COINSTATSINDEX_H
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
The database stores a block locator of the chain the database is synced to so that the index can effi...
Definition: base.h:65
Base class for indices of blockchain data.
Definition: base.h:55
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:144
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:72
CoinStatsIndex maintains statistics on the UTXO set.
CAmount m_total_subsidy
arith_uint256 m_total_new_outputs_ex_coinbase_amount
bool AllowPrune() const override
interfaces::Chain::NotifyOptions CustomOptions() override
Return custom notification options for index.
bool CustomInit(const std::optional< interfaces::BlockRef > &block) override
Initialize internal state from the database and block index.
CAmount m_total_unspendables_genesis_block
bool CustomRemove(const interfaces::BlockInfo &block) override
Rewind index by one block during a chain reorg.
CoinStatsIndex(std::unique_ptr< interfaces::Chain > chain, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
CAmount m_total_unspendables_scripts
CAmount m_total_amount
uint64_t m_bogo_size
uint64_t m_transaction_output_count
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
arith_uint256 m_total_prevout_spent_amount
uint256 m_current_block_hash
MuHash3072 m_muhash
std::optional< kernel::CCoinsStats > LookUpStats(const CBlockIndex &block_index) const
std::unique_ptr< BaseIndex::DB > m_db
bool CustomCommit(CDBBatch &batch) override
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
BaseIndex::DB & GetDB() const override
arith_uint256 m_total_coinbase_amount
CAmount m_total_unspendables_bip30
CAmount m_total_unspendables_unclaimed_rewards
bool RevertBlock(const interfaces::BlockInfo &block)
A class representing MuHash sets.
Definition: muhash.h:103
256-bit unsigned big integer.
256-bit opaque blob.
Definition: uint256.h:196
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
static constexpr bool DEFAULT_COINSTATSINDEX
Block data sent with blockConnected, blockDisconnected notifications.
Definition: chain.h:79
Options specifying which chain notifications are required.
Definition: chain.h:325