|
19 | 19 | #include <hash.h> |
20 | 20 | #include <index/blockfilterindex.h> |
21 | 21 | #include <index/coinstatsindex.h> |
| 22 | +#include <kernel/coinstats.h> |
22 | 23 | #include <logging/timer.h> |
23 | 24 | #include <net.h> |
24 | 25 | #include <net_processing.h> |
25 | 26 | #include <node/blockstorage.h> |
26 | | -#include <node/coinstats.h> |
27 | 27 | #include <node/context.h> |
28 | 28 | #include <node/utxo_snapshot.h> |
29 | 29 | #include <primitives/transaction.h> |
@@ -55,7 +55,6 @@ using kernel::CCoinsStats; |
55 | 55 | using kernel::CoinStatsHashType; |
56 | 56 |
|
57 | 57 | using node::BlockManager; |
58 | | -using node::GetUTXOStats; |
59 | 58 | using node::NodeContext; |
60 | 59 | using node::ReadBlockFromDisk; |
61 | 60 | using node::SnapshotMetadata; |
@@ -809,6 +808,36 @@ CoinStatsHashType ParseHashType(const std::string& hash_type_input) |
809 | 808 | } |
810 | 809 | } |
811 | 810 |
|
| 811 | +/** |
| 812 | + * Calculate statistics about the unspent transaction output set |
| 813 | + * |
| 814 | + * @param[in] index_requested Signals if the coinstatsindex should be used (when available). |
| 815 | + */ |
| 816 | +static std::optional<kernel::CCoinsStats> GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, |
| 817 | + kernel::CoinStatsHashType hash_type, |
| 818 | + const std::function<void()>& interruption_point = {}, |
| 819 | + const CBlockIndex* pindex = nullptr, |
| 820 | + bool index_requested = true) |
| 821 | +{ |
| 822 | + // Use CoinStatsIndex if it is requested and available and a hash_type of Muhash or None was requested |
| 823 | + if ((hash_type == kernel::CoinStatsHashType::MUHASH || hash_type == kernel::CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) { |
| 824 | + if (pindex) { |
| 825 | + return g_coin_stats_index->LookUpStats(pindex); |
| 826 | + } else { |
| 827 | + CBlockIndex* block_index = WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view->GetBestBlock())); |
| 828 | + return g_coin_stats_index->LookUpStats(block_index); |
| 829 | + } |
| 830 | + } |
| 831 | + |
| 832 | + // If the coinstats index isn't requested or is otherwise not usable, the |
| 833 | + // pindex should either be null or equal to the view's best block. This is |
| 834 | + // because without the coinstats index we can only get coinstats about the |
| 835 | + // best block. |
| 836 | + CHECK_NONFATAL(!pindex || pindex->GetBlockHash() == view->GetBestBlock()); |
| 837 | + |
| 838 | + return kernel::ComputeUTXOStats(hash_type, view, blockman, interruption_point); |
| 839 | +} |
| 840 | + |
812 | 841 | static RPCHelpMan gettxoutsetinfo() |
813 | 842 | { |
814 | 843 | return RPCHelpMan{"gettxoutsetinfo", |
|
0 commit comments