aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-02-13 19:34:17 -0500
committerCarl Dong <contact@carldong.me>2022-05-20 16:33:24 -0400
commit46eb9fc56a296a2acea10ec7e5bf7b1827f73c45 (patch)
tree6c91d56d1a5f19a71c118b757cab0040bfdcdd5e /src/node
parenta789f3f2b878e1236f8e043a8bb1ffb1afc1b673 (diff)
downloadbitcoin-46eb9fc56a296a2acea10ec7e5bf7b1827f73c45.tar.xz
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.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/coinstats.cpp12
-rw-r--r--src/node/coinstats.h14
2 files changed, 16 insertions, 10 deletions
diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp
index 8d94e1bd36..13f1041a51 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<u
//! Calculate statistics about the unspent transaction output set
template <typename T>
-static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, T hash_obj, const std::function<void()>& interruption_point, const CBlockIndex* pindex, CoinStatsHashType& hash_type)
+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)
{
std::unique_ptr<CCoinsViewCursor> 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<void()>& interruption_point, const CBlockIndex* pindex)
+bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats& stats, CoinStatsHashType hash_type, const std::function<void()>& 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 ee3f3b0030..adc67eb0a6 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<void()>& 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<void()>& interruption_point = {},
+ const CBlockIndex* pindex = nullptr,
+ bool index_requested = true);
uint64_t GetBogoSize(const CScript& script_pub_key);