Bitcoin Core  24.1.0
P2P Digital Currency
coinstatsindex.h
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 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 <crypto/muhash.h>
9 #include <index/base.h>
10 
11 class CBlockIndex;
12 class CDBBatch;
13 namespace kernel {
14 struct CCoinsStats;
15 }
16 
20 class CoinStatsIndex final : public BaseIndex
21 {
22 private:
23  std::unique_ptr<BaseIndex::DB> m_db;
24 
27  uint64_t m_bogo_size{0};
38 
39  bool ReverseBlock(const CBlock& block, const CBlockIndex* pindex);
40 
41  bool AllowPrune() const override { return true; }
42 
43 protected:
44  bool CustomInit(const std::optional<interfaces::BlockKey>& block) override;
45 
46  bool CustomCommit(CDBBatch& batch) override;
47 
48  bool CustomAppend(const interfaces::BlockInfo& block) override;
49 
50  bool CustomRewind(const interfaces::BlockKey& current_tip, const interfaces::BlockKey& new_tip) override;
51 
52  BaseIndex::DB& GetDB() const override { return *m_db; }
53 
54 public:
55  // Constructs the index, which becomes available to be queried.
56  explicit CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
57 
58  // Look up stats for a specific block using CBlockIndex
59  std::optional<kernel::CCoinsStats> LookUpStats(const CBlockIndex& block_index) const;
60 };
61 
63 extern std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
64 
65 #endif // BITCOIN_INDEX_COINSTATSINDEX_H
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:59
Definition: block.h:68
bool CustomCommit(CDBBatch &batch) override
Virtual method called internally by Commit that can be overridden to atomically commit more index sta...
bool CustomRewind(const interfaces::BlockKey &current_tip, const interfaces::BlockKey &new_tip) override
Rewind index to an earlier chain tip during a chain reorg.
uint64_t m_bogo_size
BaseIndex::DB & GetDB() const override
std::unique_ptr< BaseIndex::DB > m_db
CAmount m_total_amount
CAmount m_total_unspendables_genesis_block
bool CustomAppend(const interfaces::BlockInfo &block) override
Write update index entries for a newly connected block.
The database stores a block locator of the chain the database is synced to so that the index can effi...
Definition: base.h:43
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
bool CustomInit(const std::optional< interfaces::BlockKey > &block) override
Initialize internal state from the database and block index.
Block data sent with blockConnected, blockDisconnected notifications.
Definition: chain.h:81
Base class for indices of blockchain data.
Definition: base.h:33
CAmount m_total_new_outputs_ex_coinbase_amount
std::optional< kernel::CCoinsStats > LookUpStats(const CBlockIndex &block_index) const
CoinStatsIndex maintains statistics on the UTXO set.
CAmount m_total_subsidy
bool ReverseBlock(const CBlock &block, const CBlockIndex *pindex)
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:151
Hash/height pair to help track and identify blocks.
Definition: chain.h:42
bool AllowPrune() const override
A class representing MuHash sets.
Definition: muhash.h:94
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
CoinStatsIndex(std::unique_ptr< interfaces::Chain > chain, size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
uint64_t m_transaction_output_count
CAmount m_total_unspendable_amount
CAmount m_total_unspendables_unclaimed_rewards
CAmount m_total_unspendables_bip30
CAmount m_total_unspendables_scripts
CAmount m_total_prevout_spent_amount
CAmount m_total_coinbase_amount
MuHash3072 m_muhash