/root/bitcoin/src/kernel/coinstats.h
Line | Count | Source |
1 | | // Copyright (c) 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_KERNEL_COINSTATS_H |
6 | | #define BITCOIN_KERNEL_COINSTATS_H |
7 | | |
8 | | #include <arith_uint256.h> |
9 | | #include <consensus/amount.h> |
10 | | #include <crypto/muhash.h> |
11 | | #include <streams.h> |
12 | | #include <uint256.h> |
13 | | |
14 | | #include <cstdint> |
15 | | #include <functional> |
16 | | #include <optional> |
17 | | |
18 | | class CCoinsView; |
19 | | class Coin; |
20 | | class COutPoint; |
21 | | class CScript; |
22 | | namespace node { |
23 | | class BlockManager; |
24 | | } // namespace node |
25 | | |
26 | | namespace kernel { |
27 | | enum class CoinStatsHashType { |
28 | | HASH_SERIALIZED, |
29 | | MUHASH, |
30 | | NONE, |
31 | | }; |
32 | | |
33 | | struct CCoinsStats { |
34 | | int nHeight{0}; |
35 | | uint256 hashBlock{}; |
36 | | uint64_t nTransactions{0}; |
37 | | uint64_t nTransactionOutputs{0}; |
38 | | uint64_t nBogoSize{0}; |
39 | | uint256 hashSerialized{}; |
40 | | uint64_t nDiskSize{0}; |
41 | | //! The total amount, or nullopt if an overflow occurred calculating it |
42 | | std::optional<CAmount> total_amount{0}; |
43 | | |
44 | | //! The number of coins contained. |
45 | | uint64_t coins_count{0}; |
46 | | |
47 | | //! Signals if the coinstatsindex was used to retrieve the statistics. |
48 | | bool index_used{false}; |
49 | | |
50 | | // Following values are only available from coinstats index |
51 | | |
52 | | //! Total cumulative amount of block subsidies up to and including this block |
53 | | CAmount total_subsidy{0}; |
54 | | //! The unspendable coinbase amount from the genesis block |
55 | | CAmount total_unspendables_genesis_block{0}; |
56 | | //! The two unspendable coinbase outputs total amount caused by BIP30 |
57 | | CAmount total_unspendables_bip30{0}; |
58 | | //! Total cumulative amount of outputs sent to unspendable scripts (OP_RETURN for example) up to and including this block |
59 | | CAmount total_unspendables_scripts{0}; |
60 | | //! Total cumulative amount of coins lost due to unclaimed miner rewards up to and including this block |
61 | | CAmount total_unspendables_unclaimed_rewards{0}; |
62 | | |
63 | | // Despite containing amounts the following values use a uint256 type to prevent overflowing |
64 | | |
65 | | //! Total cumulative amount of prevouts spent up to and including this block |
66 | | arith_uint256 total_prevout_spent_amount{0}; |
67 | | //! Total cumulative amount of outputs created up to and including this block |
68 | | arith_uint256 total_new_outputs_ex_coinbase_amount{0}; |
69 | | //! Total cumulative amount of coinbase outputs up to and including this block |
70 | | arith_uint256 total_coinbase_amount{0}; |
71 | | |
72 | 0 | CCoinsStats() = default; |
73 | | CCoinsStats(int block_height, const uint256& block_hash); |
74 | | }; |
75 | | |
76 | | uint64_t GetBogoSize(const CScript& script_pub_key); |
77 | | |
78 | | void ApplyCoinHash(MuHash3072& muhash, const COutPoint& outpoint, const Coin& coin); |
79 | | void RemoveCoinHash(MuHash3072& muhash, const COutPoint& outpoint, const Coin& coin); |
80 | | |
81 | | std::optional<CCoinsStats> ComputeUTXOStats(CoinStatsHashType hash_type, CCoinsView* view, node::BlockManager& blockman, const std::function<void()>& interruption_point = {}); |
82 | | } // namespace kernel |
83 | | |
84 | | #endif // BITCOIN_KERNEL_COINSTATS_H |