aboutsummaryrefslogtreecommitdiff
path: root/src/node
diff options
context:
space:
mode:
authorCarl Dong <contact@carldong.me>2022-05-02 13:44:19 -0400
committerCarl Dong <contact@carldong.me>2022-05-23 14:52:25 -0400
commitb7634fe02b6b030f5d62502c73db84ba9a276640 (patch)
tree08147ea1a3c1e452d73ca49032917bad17c2f3b9 /src/node
parent1352e410a5b84070279ff28399083cb3ab278593 (diff)
downloadbitcoin-b7634fe02b6b030f5d62502c73db84ba9a276640.tar.xz
Move logic from LookupUTXOStatsWithIndex to CoinStatsIndex::LookUpStats
The indexing codepath logic in node/coinstats.cpp is simple enough to be moved into CoinStatsIndex::LookUpStats, avoiding an additional layer of function calls. Callers are modified accordingly. Also, add 2 missed BOOST_CHECKs to the coinstatsindex_initial_sync unit test.
Diffstat (limited to 'src/node')
-rw-r--r--src/node/coinstats.cpp24
1 files changed, 3 insertions, 21 deletions
diff --git a/src/node/coinstats.cpp b/src/node/coinstats.cpp
index 26badd6eb2..8851eb2c2d 100644
--- a/src/node/coinstats.cpp
+++ b/src/node/coinstats.cpp
@@ -187,33 +187,15 @@ static void FinalizeHash(MuHash3072& muhash, CCoinsStats& stats)
}
static void FinalizeHash(std::nullptr_t, CCoinsStats& stats) {}
-std::optional<CCoinsStats> LookupUTXOStatsWithIndex(CoinStatsIndex& coin_stats_index, const CBlockIndex* pindex)
-{
- CCoinsStats stats{Assert(pindex)->nHeight, pindex->GetBlockHash()};
-
- stats.index_used = true;
- if (!coin_stats_index.LookUpStats(pindex, stats)) {
- return std::nullopt;
- }
-
- return stats;
-}
-
-std::optional<CCoinsStats> LookupUTXOStatsWithIndex(CoinStatsIndex& coin_stats_index, CCoinsView* view, BlockManager& blockman)
-{
- CBlockIndex* pindex = WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view->GetBestBlock()));
-
- return LookupUTXOStatsWithIndex(coin_stats_index, pindex);
-}
-
std::optional<CCoinsStats> GetUTXOStats(CCoinsView* view, BlockManager& blockman, 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 == CoinStatsHashType::MUHASH || hash_type == CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) {
if (pindex) {
- return LookupUTXOStatsWithIndex(*g_coin_stats_index, pindex);
+ return g_coin_stats_index->LookUpStats(pindex);
} else {
- return LookupUTXOStatsWithIndex(*g_coin_stats_index, view, blockman);
+ CBlockIndex* block_index = WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view->GetBestBlock()));
+ return g_coin_stats_index->LookUpStats(block_index);
}
}