Skip to content

Commit 46eb9fc

Browse files
committed
coinstats: Extract index_requested in-member to in-param
This change removes CCoinsStats' index_requested in-param member and adds it to the relevant functions instead.
1 parent a789f3f commit 46eb9fc

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/node/coinstats.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static void ApplyStats(CCoinsStats& stats, const uint256& hash, const std::map<u
9393

9494
//! Calculate statistics about the unspent transaction output set
9595
template <typename T>
96-
static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point, const CBlockIndex* pindex, CoinStatsHashType& hash_type)
96+
static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point, const CBlockIndex* pindex, CoinStatsHashType& hash_type, bool index_requested)
9797
{
9898
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
9999
assert(pcursor);
@@ -106,7 +106,7 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats&
106106
stats.hashBlock = pindex->GetBlockHash();
107107

108108
// Use CoinStatsIndex if it is requested and available and a hash_type of Muhash or None was requested
109-
if ((hash_type == CoinStatsHashType::MUHASH || hash_type == CoinStatsHashType::NONE) && g_coin_stats_index && stats.index_requested) {
109+
if ((hash_type == CoinStatsHashType::MUHASH || hash_type == CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) {
110110
stats.index_used = true;
111111
return g_coin_stats_index->LookUpStats(pindex, stats);
112112
}
@@ -144,19 +144,19 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats&
144144
return true;
145145
}
146146

147-
bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function<void()>& interruption_point, const CBlockIndex* pindex)
147+
bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function<void()>& interruption_point, const CBlockIndex* pindex, bool index_requested)
148148
{
149149
switch (hash_type) {
150150
case(CoinStatsHashType::HASH_SERIALIZED): {
151151
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION);
152-
return GetUTXOStats(view, blockman, stats, ss, interruption_point, pindex, hash_type);
152+
return GetUTXOStats(view, blockman, stats, ss, interruption_point, pindex, hash_type, index_requested);
153153
}
154154
case(CoinStatsHashType::MUHASH): {
155155
MuHash3072 muhash;
156-
return GetUTXOStats(view, blockman, stats, muhash, interruption_point, pindex, hash_type);
156+
return GetUTXOStats(view, blockman, stats, muhash, interruption_point, pindex, hash_type, index_requested);
157157
}
158158
case(CoinStatsHashType::NONE): {
159-
return GetUTXOStats(view, blockman, stats, nullptr, interruption_point, pindex, hash_type);
159+
return GetUTXOStats(view, blockman, stats, nullptr, interruption_point, pindex, hash_type, index_requested);
160160
}
161161
} // no default case, so the compiler can warn about missing cases
162162
assert(false);

src/node/coinstats.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,6 @@ struct CCoinsStats {
4141
//! The number of coins contained.
4242
uint64_t coins_count{0};
4343

44-
//! Signals if the coinstatsindex should be used (when available).
45-
bool index_requested{true};
4644
//! Signals if the coinstatsindex was used to retrieve the statistics.
4745
bool index_used{false};
4846

@@ -68,8 +66,16 @@ struct CCoinsStats {
6866
CAmount total_unspendables_unclaimed_rewards{0};
6967
};
7068

71-
//! Calculate statistics about the unspent transaction output set
72-
bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function<void()>& interruption_point = {}, const CBlockIndex* pindex = nullptr);
69+
/**
70+
* Calculate statistics about the unspent transaction output set
71+
*
72+
* @param[in] index_requested Signals if the coinstatsindex should be used (when available).
73+
*/
74+
bool GetUTXOStats(CCoinsView* view, node::BlockManager& blockman,
75+
CCoinsStats& stats, CoinStatsHashType hash_type,
76+
const std::function<void()>& interruption_point = {},
77+
const CBlockIndex* pindex = nullptr,
78+
bool index_requested = true);
7379

7480
uint64_t GetBogoSize(const CScript& script_pub_key);
7581

src/rpc/blockchain.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ static RPCHelpMan gettxoutsetinfo()
863863
const CBlockIndex* pindex{nullptr};
864864
const CoinStatsHashType hash_type{request.params[0].isNull() ? CoinStatsHashType::HASH_SERIALIZED : ParseHashType(request.params[0].get_str())};
865865
CCoinsStats stats{};
866-
stats.index_requested = request.params[2].isNull() || request.params[2].get_bool();
866+
bool index_requested = request.params[2].isNull() || request.params[2].get_bool();
867867

868868
NodeContext& node = EnsureAnyNodeContext(request.context);
869869
ChainstateManager& chainman = EnsureChainman(node);
@@ -891,7 +891,7 @@ static RPCHelpMan gettxoutsetinfo()
891891
pindex = ParseHashOrHeight(request.params[1], chainman);
892892
}
893893

894-
if (stats.index_requested && g_coin_stats_index) {
894+
if (index_requested && g_coin_stats_index) {
895895
if (!g_coin_stats_index->BlockUntilSyncedToCurrentChain()) {
896896
const IndexSummary summary{g_coin_stats_index->GetSummary()};
897897

@@ -903,7 +903,7 @@ static RPCHelpMan gettxoutsetinfo()
903903
}
904904
}
905905

906-
if (GetUTXOStats(coins_view, *blockman, stats, hash_type, node.rpc_interruption_point, pindex)) {
906+
if (GetUTXOStats(coins_view, *blockman, stats, hash_type, node.rpc_interruption_point, pindex, index_requested)) {
907907
ret.pushKV("height", (int64_t)stats.nHeight);
908908
ret.pushKV("bestblock", stats.hashBlock.GetHex());
909909
ret.pushKV("txouts", (int64_t)stats.nTransactionOutputs);
@@ -925,7 +925,7 @@ static RPCHelpMan gettxoutsetinfo()
925925
CCoinsStats prev_stats{};
926926

927927
if (pindex->nHeight > 0) {
928-
GetUTXOStats(coins_view, *blockman, prev_stats, hash_type, node.rpc_interruption_point, pindex->pprev);
928+
GetUTXOStats(coins_view, *blockman, prev_stats, hash_type, node.rpc_interruption_point, pindex->pprev, index_requested);
929929
}
930930

931931
UniValue block_info(UniValue::VOBJ);

0 commit comments

Comments
 (0)