mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-22 23:07:59 +01:00
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.
This commit is contained in:
parent
f100687566
commit
664a14ba7c
4 changed files with 31 additions and 76 deletions
|
@ -192,7 +192,6 @@ BITCOIN_CORE_H = \
|
||||||
node/caches.h \
|
node/caches.h \
|
||||||
node/chainstate.h \
|
node/chainstate.h \
|
||||||
node/coin.h \
|
node/coin.h \
|
||||||
node/coinstats.h \
|
|
||||||
node/context.h \
|
node/context.h \
|
||||||
node/miner.h \
|
node/miner.h \
|
||||||
node/minisketchwrapper.h \
|
node/minisketchwrapper.h \
|
||||||
|
@ -367,7 +366,6 @@ libbitcoin_node_a_SOURCES = \
|
||||||
node/caches.cpp \
|
node/caches.cpp \
|
||||||
node/chainstate.cpp \
|
node/chainstate.cpp \
|
||||||
node/coin.cpp \
|
node/coin.cpp \
|
||||||
node/coinstats.cpp \
|
|
||||||
node/context.cpp \
|
node/context.cpp \
|
||||||
node/interfaces.cpp \
|
node/interfaces.cpp \
|
||||||
node/miner.cpp \
|
node/miner.cpp \
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
// Copyright (c) 2010 Satoshi Nakamoto
|
|
||||||
// Copyright (c) 2009-2021 The Bitcoin Core developers
|
|
||||||
// Distributed under the MIT software license, see the accompanying
|
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
|
|
||||||
#include <node/coinstats.h>
|
|
||||||
|
|
||||||
#include <coins.h>
|
|
||||||
#include <index/coinstatsindex.h>
|
|
||||||
#include <optional>
|
|
||||||
#include <validation.h>
|
|
||||||
|
|
||||||
namespace node {
|
|
||||||
std::optional<kernel::CCoinsStats> GetUTXOStats(CCoinsView* view, BlockManager& blockman, kernel::CoinStatsHashType hash_type, const std::function<void()>& interruption_point, const CBlockIndex* pindex, bool index_requested)
|
|
||||||
{
|
|
||||||
// Use CoinStatsIndex if it is requested and available and a hash_type of Muhash or None was requested
|
|
||||||
if ((hash_type == kernel::CoinStatsHashType::MUHASH || hash_type == kernel::CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) {
|
|
||||||
if (pindex) {
|
|
||||||
return g_coin_stats_index->LookUpStats(pindex);
|
|
||||||
} else {
|
|
||||||
CBlockIndex* block_index = WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view->GetBestBlock()));
|
|
||||||
return g_coin_stats_index->LookUpStats(block_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// If the coinstats index isn't requested or is otherwise not usable, the
|
|
||||||
// pindex should either be null or equal to the view's best block. This is
|
|
||||||
// because without the coinstats index we can only get coinstats about the
|
|
||||||
// best block.
|
|
||||||
assert(!pindex || pindex->GetBlockHash() == view->GetBestBlock());
|
|
||||||
|
|
||||||
return kernel::ComputeUTXOStats(hash_type, view, blockman, interruption_point);
|
|
||||||
}
|
|
||||||
} // namespace node
|
|
|
@ -1,38 +0,0 @@
|
||||||
// Copyright (c) 2010 Satoshi Nakamoto
|
|
||||||
// Copyright (c) 2009-2021 The Bitcoin Core developers
|
|
||||||
// Distributed under the MIT software license, see the accompanying
|
|
||||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
||||||
|
|
||||||
#ifndef BITCOIN_NODE_COINSTATS_H
|
|
||||||
#define BITCOIN_NODE_COINSTATS_H
|
|
||||||
|
|
||||||
#include <kernel/coinstats.h>
|
|
||||||
|
|
||||||
#include <chain.h>
|
|
||||||
#include <coins.h>
|
|
||||||
#include <consensus/amount.h>
|
|
||||||
#include <streams.h>
|
|
||||||
#include <uint256.h>
|
|
||||||
|
|
||||||
#include <cstdint>
|
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
class CCoinsView;
|
|
||||||
namespace node {
|
|
||||||
class BlockManager;
|
|
||||||
} // namespace node
|
|
||||||
|
|
||||||
namespace node {
|
|
||||||
/**
|
|
||||||
* Calculate statistics about the unspent transaction output set
|
|
||||||
*
|
|
||||||
* @param[in] index_requested Signals if the coinstatsindex should be used (when available).
|
|
||||||
*/
|
|
||||||
std::optional<kernel::CCoinsStats> GetUTXOStats(CCoinsView* view, node::BlockManager& blockman,
|
|
||||||
kernel::CoinStatsHashType hash_type,
|
|
||||||
const std::function<void()>& interruption_point = {},
|
|
||||||
const CBlockIndex* pindex = nullptr,
|
|
||||||
bool index_requested = true);
|
|
||||||
} // namespace node
|
|
||||||
|
|
||||||
#endif // BITCOIN_NODE_COINSTATS_H
|
|
|
@ -19,11 +19,11 @@
|
||||||
#include <hash.h>
|
#include <hash.h>
|
||||||
#include <index/blockfilterindex.h>
|
#include <index/blockfilterindex.h>
|
||||||
#include <index/coinstatsindex.h>
|
#include <index/coinstatsindex.h>
|
||||||
|
#include <kernel/coinstats.h>
|
||||||
#include <logging/timer.h>
|
#include <logging/timer.h>
|
||||||
#include <net.h>
|
#include <net.h>
|
||||||
#include <net_processing.h>
|
#include <net_processing.h>
|
||||||
#include <node/blockstorage.h>
|
#include <node/blockstorage.h>
|
||||||
#include <node/coinstats.h>
|
|
||||||
#include <node/context.h>
|
#include <node/context.h>
|
||||||
#include <node/utxo_snapshot.h>
|
#include <node/utxo_snapshot.h>
|
||||||
#include <primitives/transaction.h>
|
#include <primitives/transaction.h>
|
||||||
|
@ -55,7 +55,6 @@ using kernel::CCoinsStats;
|
||||||
using kernel::CoinStatsHashType;
|
using kernel::CoinStatsHashType;
|
||||||
|
|
||||||
using node::BlockManager;
|
using node::BlockManager;
|
||||||
using node::GetUTXOStats;
|
|
||||||
using node::NodeContext;
|
using node::NodeContext;
|
||||||
using node::ReadBlockFromDisk;
|
using node::ReadBlockFromDisk;
|
||||||
using node::SnapshotMetadata;
|
using node::SnapshotMetadata;
|
||||||
|
@ -809,6 +808,36 @@ CoinStatsHashType ParseHashType(const std::string& hash_type_input)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate statistics about the unspent transaction output set
|
||||||
|
*
|
||||||
|
* @param[in] index_requested Signals if the coinstatsindex should be used (when available).
|
||||||
|
*/
|
||||||
|
static std::optional<kernel::CCoinsStats> GetUTXOStats(CCoinsView* view, node::BlockManager& blockman,
|
||||||
|
kernel::CoinStatsHashType hash_type,
|
||||||
|
const std::function<void()>& interruption_point = {},
|
||||||
|
const CBlockIndex* pindex = nullptr,
|
||||||
|
bool index_requested = true)
|
||||||
|
{
|
||||||
|
// Use CoinStatsIndex if it is requested and available and a hash_type of Muhash or None was requested
|
||||||
|
if ((hash_type == kernel::CoinStatsHashType::MUHASH || hash_type == kernel::CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) {
|
||||||
|
if (pindex) {
|
||||||
|
return g_coin_stats_index->LookUpStats(pindex);
|
||||||
|
} else {
|
||||||
|
CBlockIndex* block_index = WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view->GetBestBlock()));
|
||||||
|
return g_coin_stats_index->LookUpStats(block_index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the coinstats index isn't requested or is otherwise not usable, the
|
||||||
|
// pindex should either be null or equal to the view's best block. This is
|
||||||
|
// because without the coinstats index we can only get coinstats about the
|
||||||
|
// best block.
|
||||||
|
CHECK_NONFATAL(!pindex || pindex->GetBlockHash() == view->GetBestBlock());
|
||||||
|
|
||||||
|
return kernel::ComputeUTXOStats(hash_type, view, blockman, interruption_point);
|
||||||
|
}
|
||||||
|
|
||||||
static RPCHelpMan gettxoutsetinfo()
|
static RPCHelpMan gettxoutsetinfo()
|
||||||
{
|
{
|
||||||
return RPCHelpMan{"gettxoutsetinfo",
|
return RPCHelpMan{"gettxoutsetinfo",
|
||||||
|
|
Loading…
Add table
Reference in a new issue