diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp index 8d94e1bd369..13f1041a516 100644 --- a/src/node/coinstats.cpp +++ b/src/node/coinstats.cpp @@ -93,7 +93,7 @@ static void ApplyStats(CCoinsStats& stats, const uint256& hash, const std::map -static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function& interruption_point, const CBlockIndex* pindex, CoinStatsHashType& hash_type) +static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function& interruption_point, const CBlockIndex* pindex, CoinStatsHashType& hash_type, bool index_requested) { std::unique_ptr pcursor(view->Cursor()); assert(pcursor); @@ -106,7 +106,7 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats.hashBlock = pindex->GetBlockHash(); // Use CoinStatsIndex if it is requested and available and a hash_type of Muhash or None was requested - if ((hash_type == CoinStatsHashType::MUHASH || hash_type == CoinStatsHashType::NONE) && g_coin_stats_index && stats.index_requested) { + if ((hash_type == CoinStatsHashType::MUHASH || hash_type == CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) { stats.index_used = true; return g_coin_stats_index->LookUpStats(pindex, stats); } @@ -144,19 +144,19 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& return true; } -bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function& interruption_point, const CBlockIndex* pindex) +bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function& interruption_point, const CBlockIndex* pindex, bool index_requested) { switch (hash_type) { case(CoinStatsHashType::HASH_SERIALIZED): { CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); - return GetUTXOStats(view, blockman, stats, ss, interruption_point, pindex, hash_type); + return GetUTXOStats(view, blockman, stats, ss, interruption_point, pindex, hash_type, index_requested); } case(CoinStatsHashType::MUHASH): { MuHash3072 muhash; - return GetUTXOStats(view, blockman, stats, muhash, interruption_point, pindex, hash_type); + return GetUTXOStats(view, blockman, stats, muhash, interruption_point, pindex, hash_type, index_requested); } case(CoinStatsHashType::NONE): { - return GetUTXOStats(view, blockman, stats, nullptr, interruption_point, pindex, hash_type); + return GetUTXOStats(view, blockman, stats, nullptr, interruption_point, pindex, hash_type, index_requested); } } // no default case, so the compiler can warn about missing cases assert(false); diff --git a/src/node/coinstats.h b/src/node/coinstats.h index ee3f3b00306..adc67eb0a60 100644 --- a/src/node/coinstats.h +++ b/src/node/coinstats.h @@ -41,8 +41,6 @@ struct CCoinsStats { //! The number of coins contained. uint64_t coins_count{0}; - //! Signals if the coinstatsindex should be used (when available). - bool index_requested{true}; //! Signals if the coinstatsindex was used to retrieve the statistics. bool index_used{false}; @@ -68,8 +66,16 @@ struct CCoinsStats { CAmount total_unspendables_unclaimed_rewards{0}; }; -//! Calculate statistics about the unspent transaction output set -bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function& interruption_point = {}, const CBlockIndex* pindex = nullptr); +/** + * Calculate statistics about the unspent transaction output set + * + * @param[in] index_requested Signals if the coinstatsindex should be used (when available). + */ +bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, + CCoinsStats& stats, CoinStatsHashType hash_type, + const std::function& interruption_point = {}, + const CBlockIndex* pindex = nullptr, + bool index_requested = true); uint64_t GetBogoSize(const CScript& script_pub_key); diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp index 3411f72a2cb..98c2deb4bf0 100644 --- a/src/rpc/blockchain.cpp +++ b/src/rpc/blockchain.cpp @@ -863,7 +863,7 @@ static RPCHelpMan gettxoutsetinfo() const CBlockIndex* pindex{nullptr}; const CoinStatsHashType hash_type{request.params[0].isNull() ? CoinStatsHashType::HASH_SERIALIZED : ParseHashType(request.params[0].get_str())}; CCoinsStats stats{}; - stats.index_requested = request.params[2].isNull() || request.params[2].get_bool(); + bool index_requested = request.params[2].isNull() || request.params[2].get_bool(); NodeContext& node = EnsureAnyNodeContext(request.context); ChainstateManager& chainman = EnsureChainman(node); @@ -891,7 +891,7 @@ static RPCHelpMan gettxoutsetinfo() pindex = ParseHashOrHeight(request.params[1], chainman); } - if (stats.index_requested && g_coin_stats_index) { + if (index_requested && g_coin_stats_index) { if (!g_coin_stats_index->BlockUntilSyncedToCurrentChain()) { const IndexSummary summary{g_coin_stats_index->GetSummary()}; @@ -903,7 +903,7 @@ static RPCHelpMan gettxoutsetinfo() } } - if (GetUTXOStats(coins_view, *blockman, stats, hash_type, node.rpc_interruption_point, pindex)) { + if (GetUTXOStats(coins_view, *blockman, stats, hash_type, node.rpc_interruption_point, pindex, index_requested)) { ret.pushKV("height", (int64_t)stats.nHeight); ret.pushKV("bestblock", stats.hashBlock.GetHex()); ret.pushKV("txouts", (int64_t)stats.nTransactionOutputs); @@ -925,7 +925,7 @@ static RPCHelpMan gettxoutsetinfo() CCoinsStats prev_stats{}; if (pindex->nHeight > 0) { - GetUTXOStats(coins_view, *blockman, prev_stats, hash_type, node.rpc_interruption_point, pindex->pprev); + GetUTXOStats(coins_view, *blockman, prev_stats, hash_type, node.rpc_interruption_point, pindex->pprev, index_requested); } UniValue block_info(UniValue::VOBJ);