Now that the index is passed in as a nullable pointer, index_requested is redundant. GetUTXOStats only reads it as coin_stats_index && index_requested, so gettxoutsetinfo can pass nullptr when use_index is false and the bool parameter can go.
<details>
<summary>Suggested diff</summary>
diff --git a/src/rpc/blockchain.cpp b/src/rpc/blockchain.cpp
index ab061346c9..92c8cfdf57 100644
--- a/src/rpc/blockchain.cpp
+++ b/src/rpc/blockchain.cpp
@@ -1012,17 +1012,16 @@ CoinStatsHashType ParseHashType(std::string_view hash_type_input)
/**
* Calculate statistics about the unspent transaction output set
*
- * [@param](/bitcoin-bitcoin/contributor/param/)[in] index_requested Signals if the coinstatsindex should be used (when available).
+ * [@param](/bitcoin-bitcoin/contributor/param/)[in] coin_stats_index The coinstatsindex to use, or nullptr to compute the statistics from the view.
*/
static std::optional<kernel::CCoinsStats> GetUTXOStats(const CCoinsViewDB& view, node::BlockManager& blockman,
const CoinStatsIndex* coin_stats_index,
kernel::CoinStatsHashType hash_type,
const std::function<void()>& interruption_point = {},
- const CBlockIndex* pindex = nullptr,
- bool index_requested = true)
+ const CBlockIndex* pindex = nullptr)
{
- // 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) && coin_stats_index && index_requested) {
+ // Use CoinStatsIndex if it is provided and a hash_type of Muhash or None was requested
+ if ((hash_type == kernel::CoinStatsHashType::MUHASH || hash_type == kernel::CoinStatsHashType::NONE) && coin_stats_index) {
if (pindex) {
return coin_stats_index->LookUpStats(*pindex);
} else {
@@ -1102,6 +1101,7 @@ static RPCMethod gettxoutsetinfo()
const bool index_requested{self.Arg<bool>("use_index")};
NodeContext& node = EnsureAnyNodeContext(request.context);
+ const CoinStatsIndex* const coin_stats_index{index_requested ? node.coin_stats_index.get() : nullptr};
ChainstateManager& chainman = EnsureChainman(node);
Chainstate& active_chainstate = chainman.ActiveChainstate();
active_chainstate.ForceFlushStateToDisk(/*wipe_cache=*/false);
@@ -1125,9 +1125,9 @@ static RPCMethod gettxoutsetinfo()
pindex = ParseHashOrHeight(request.params[1], chainman);
}
- if (index_requested && node.coin_stats_index) {
- if (!node.coin_stats_index->BlockUntilSyncedToCurrentChain()) {
- const IndexSummary summary{node.coin_stats_index->GetSummary()};
+ if (coin_stats_index) {
+ if (!coin_stats_index->BlockUntilSyncedToCurrentChain()) {
+ const IndexSummary summary{coin_stats_index->GetSummary()};
// If a specific block was requested and the index has already synced past that height, we can return the
// data already even though the index is not fully synced yet.
@@ -1137,7 +1137,7 @@ static RPCMethod gettxoutsetinfo()
}
}
- const std::optional<CCoinsStats> maybe_stats = GetUTXOStats(coins_view, blockman, node.coin_stats_index.get(), hash_type, node.rpc_interruption_point, pindex, index_requested);
+ const std::optional<CCoinsStats> maybe_stats = GetUTXOStats(coins_view, blockman, coin_stats_index, hash_type, node.rpc_interruption_point, pindex);
if (maybe_stats.has_value()) {
const CCoinsStats& stats = maybe_stats.value();
ret.pushKV("height", stats.nHeight);
@@ -1159,7 +1159,7 @@ static RPCMethod gettxoutsetinfo()
CCoinsStats prev_stats{};
if (stats.nHeight > 0) {
const CBlockIndex& block_index = *CHECK_NONFATAL(WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(stats.hashBlock)));
- const std::optional<CCoinsStats> maybe_prev_stats = GetUTXOStats(coins_view, blockman, node.coin_stats_index.get(), hash_type, node.rpc_interruption_point, block_index.pprev, index_requested);
+ const std::optional<CCoinsStats> maybe_prev_stats = GetUTXOStats(coins_view, blockman, coin_stats_index, hash_type, node.rpc_interruption_point, block_index.pprev);
if (!maybe_prev_stats) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "Unable to read UTXO set");
}
</details>