Skip to content

Commit 8097098

Browse files
committed
coinstats: Split node/coinstats.h to kernel/coinstats.h
Most of this commit is pure-move. After this change: - kernel/coinstats.h -> Contains declarations for: - enum class CoinStatsHashType - struct CCoinsStats - GetBogoSize(...) - TxOutSer(...) - ComputeUTXOStats(...) - node/coinstats.h -> Just GetUTXOStats, which will be removed as we change callers to directly use the hashing/indexing codepaths in future commits.
1 parent 35f73ce commit 8097098

File tree

4 files changed

+82
-55
lines changed

4 files changed

+82
-55
lines changed

src/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ BITCOIN_CORE_H = \
172172
interfaces/node.h \
173173
interfaces/wallet.h \
174174
kernel/chainstatemanager_opts.h \
175+
kernel/coinstats.h \
175176
key.h \
176177
key_io.h \
177178
logging.h \

src/kernel/coinstats.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Distributed under the MIT software license, see the accompanying
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44

5-
#include <node/coinstats.h>
5+
#include <kernel/coinstats.h>
66

77
#include <coins.h>
88
#include <crypto/muhash.h>

src/kernel/coinstats.h

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

src/node/coinstats.h

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#ifndef BITCOIN_NODE_COINSTATS_H
77
#define BITCOIN_NODE_COINSTATS_H
88

9+
#include <kernel/coinstats.h>
10+
911
#include <chain.h>
1012
#include <coins.h>
1113
#include <consensus/amount.h>
@@ -21,54 +23,6 @@ class BlockManager;
2123
} // namespace node
2224

2325
namespace node {
24-
enum class CoinStatsHashType {
25-
HASH_SERIALIZED,
26-
MUHASH,
27-
NONE,
28-
};
29-
30-
struct CCoinsStats {
31-
int nHeight{0};
32-
uint256 hashBlock{};
33-
uint64_t nTransactions{0};
34-
uint64_t nTransactionOutputs{0};
35-
uint64_t nBogoSize{0};
36-
uint256 hashSerialized{};
37-
uint64_t nDiskSize{0};
38-
//! The total amount, or nullopt if an overflow occurred calculating it
39-
std::optional<CAmount> total_amount{0};
40-
41-
//! The number of coins contained.
42-
uint64_t coins_count{0};
43-
44-
//! Signals if the coinstatsindex was used to retrieve the statistics.
45-
bool index_used{false};
46-
47-
// Following values are only available from coinstats index
48-
49-
//! Total cumulative amount of block subsidies up to and including this block
50-
CAmount total_subsidy{0};
51-
//! Total cumulative amount of unspendable coins up to and including this block
52-
CAmount total_unspendable_amount{0};
53-
//! Total cumulative amount of prevouts spent up to and including this block
54-
CAmount total_prevout_spent_amount{0};
55-
//! Total cumulative amount of outputs created up to and including this block
56-
CAmount total_new_outputs_ex_coinbase_amount{0};
57-
//! Total cumulative amount of coinbase outputs up to and including this block
58-
CAmount total_coinbase_amount{0};
59-
//! The unspendable coinbase amount from the genesis block
60-
CAmount total_unspendables_genesis_block{0};
61-
//! The two unspendable coinbase outputs total amount caused by BIP30
62-
CAmount total_unspendables_bip30{0};
63-
//! Total cumulative amount of outputs sent to unspendable scripts (OP_RETURN for example) up to and including this block
64-
CAmount total_unspendables_scripts{0};
65-
//! Total cumulative amount of coins lost due to unclaimed miner rewards up to and including this block
66-
CAmount total_unspendables_unclaimed_rewards{0};
67-
68-
CCoinsStats() = default;
69-
CCoinsStats(int block_height, const uint256& block_hash);
70-
};
71-
7226
/**
7327
* Calculate statistics about the unspent transaction output set
7428
*
@@ -79,12 +33,6 @@ std::optional<CCoinsStats> GetUTXOStats(CCoinsView* view, node::BlockManager& bl
7933
const std::function<void()>& interruption_point = {},
8034
const CBlockIndex* pindex = nullptr,
8135
bool index_requested = true);
82-
83-
uint64_t GetBogoSize(const CScript& script_pub_key);
84-
85-
CDataStream TxOutSer(const COutPoint& outpoint, const Coin& coin);
86-
87-
std::optional<CCoinsStats> ComputeUTXOStats(CoinStatsHashType hash_type, CCoinsView* view, BlockManager& blockman, const std::function<void()>& interruption_point = {});
8836
} // namespace node
8937

9038
#endif // BITCOIN_NODE_COINSTATS_H

0 commit comments

Comments
 (0)