Skip to content

Commit 664a14b

Browse files
committed
coinstats: Move GetUTXOStats to rpc/blockchain
rpc/blockchain.cpp is now the only user of the vestigial GetUTXOStats(...). And since GetUTXOStats(...)'s special fallback logic was only really relevant/meant for rpc/blockchain.cpp, we can just move it there.
1 parent f100687 commit 664a14b

File tree

4 files changed

+31
-76
lines changed

4 files changed

+31
-76
lines changed

src/Makefile.am

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ BITCOIN_CORE_H = \
192192
node/caches.h \
193193
node/chainstate.h \
194194
node/coin.h \
195-
node/coinstats.h \
196195
node/context.h \
197196
node/miner.h \
198197
node/minisketchwrapper.h \
@@ -367,7 +366,6 @@ libbitcoin_node_a_SOURCES = \
367366
node/caches.cpp \
368367
node/chainstate.cpp \
369368
node/coin.cpp \
370-
node/coinstats.cpp \
371369
node/context.cpp \
372370
node/interfaces.cpp \
373371
node/miner.cpp \

src/node/coinstats.cpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

src/node/coinstats.h

Lines changed: 0 additions & 38 deletions
This file was deleted.

src/rpc/blockchain.cpp

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@
1919
#include <hash.h>
2020
#include <index/blockfilterindex.h>
2121
#include <index/coinstatsindex.h>
22+
#include <kernel/coinstats.h>
2223
#include <logging/timer.h>
2324
#include <net.h>
2425
#include <net_processing.h>
2526
#include <node/blockstorage.h>
26-
#include <node/coinstats.h>
2727
#include <node/context.h>
2828
#include <node/utxo_snapshot.h>
2929
#include <primitives/transaction.h>
@@ -55,7 +55,6 @@ using kernel::CCoinsStats;
5555
using kernel::CoinStatsHashType;
5656

5757
using node::BlockManager;
58-
using node::GetUTXOStats;
5958
using node::NodeContext;
6059
using node::ReadBlockFromDisk;
6160
using node::SnapshotMetadata;
@@ -809,6 +808,36 @@ CoinStatsHashType ParseHashType(const std::string& hash_type_input)
809808
}
810809
}
811810

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+
812841
static RPCHelpMan gettxoutsetinfo()
813842
{
814843
return RPCHelpMan{"gettxoutsetinfo",

0 commit comments

Comments
 (0)