Skip to content

Commit 3c85e8a

Browse files
committed
merge bitcoin#25222: Pass reference to LookUpStats
1 parent c521a98 commit 3c85e8a

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

src/index/coinstatsindex.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <coins.h>
77
#include <crypto/muhash.h>
88
#include <index/coinstatsindex.h>
9+
#include <kernel/coinstats.h>
910
#include <node/blockstorage.h>
1011
#include <serialize.h>
1112
#include <txdb.h>
@@ -321,13 +322,13 @@ static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockKey& block, D
321322
return db.Read(DBHashKey(block.hash), result);
322323
}
323324

324-
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex* block_index) const
325+
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex& block_index) const
325326
{
326-
CCoinsStats stats{Assert(block_index)->nHeight, block_index->GetBlockHash()};
327+
CCoinsStats stats{block_index.nHeight, block_index.GetBlockHash()};
327328
stats.index_used = true;
328329

329330
DBVal entry;
330-
if (!LookUpOne(*m_db, {block_index->GetBlockHash(), block_index->nHeight}, entry)) {
331+
if (!LookUpOne(*m_db, {block_index.GetBlockHash(), block_index.nHeight}, entry)) {
331332
return std::nullopt;
332333
}
333334

src/index/coinstatsindex.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
#ifndef BITCOIN_INDEX_COINSTATSINDEX_H
66
#define BITCOIN_INDEX_COINSTATSINDEX_H
77

8-
#include <chain.h>
98
#include <crypto/muhash.h>
10-
#include <flatfile.h>
119
#include <index/base.h>
12-
#include <kernel/coinstats.h>
10+
11+
class CBlockIndex;
12+
class CDBBatch;
13+
namespace kernel {
14+
struct CCoinsStats;
15+
}
1316

1417
static constexpr bool DEFAULT_COINSTATSINDEX{false};
1518

@@ -58,7 +61,7 @@ class CoinStatsIndex final : public BaseIndex
5861
explicit CoinStatsIndex(std::unique_ptr<interfaces::Chain> chain, size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
5962

6063
// Look up stats for a specific block using CBlockIndex
61-
std::optional<kernel::CCoinsStats> LookUpStats(const CBlockIndex* block_index) const;
64+
std::optional<kernel::CCoinsStats> LookUpStats(const CBlockIndex& block_index) const;
6265
};
6366

6467
/// The global UTXO set hash object.

src/rpc/blockchain.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1121,9 +1121,9 @@ std::optional<kernel::CCoinsStats> GetUTXOStats(CCoinsView* view, node::BlockMan
11211121
// Use CoinStatsIndex if it is requested and available and a hash_type of Muhash or None was requested
11221122
if ((hash_type == kernel::CoinStatsHashType::MUHASH || hash_type == kernel::CoinStatsHashType::NONE) && g_coin_stats_index && index_requested) {
11231123
if (pindex) {
1124-
return g_coin_stats_index->LookUpStats(pindex);
1124+
return g_coin_stats_index->LookUpStats(*pindex);
11251125
} else {
1126-
CBlockIndex* block_index = WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view->GetBestBlock()));
1126+
CBlockIndex& block_index = *CHECK_NONFATAL(WITH_LOCK(::cs_main, return blockman.LookupBlockIndex(view->GetBestBlock())));
11271127
return g_coin_stats_index->LookUpStats(block_index);
11281128
}
11291129
}

src/test/coinstatsindex_tests.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <chainparams.h>
66
#include <index/coinstatsindex.h>
77
#include <interfaces/chain.h>
8+
#include <kernel/coinstats.h>
89
#include <test/util/index.h>
910
#include <test/util/setup_common.h>
1011
#include <test/util/validation.h>
@@ -26,7 +27,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
2627
}
2728

2829
// CoinStatsIndex should not be found before it is started.
29-
BOOST_CHECK(!coin_stats_index.LookUpStats(block_index));
30+
BOOST_CHECK(!coin_stats_index.LookUpStats(*block_index));
3031

3132
// BlockUntilSyncedToCurrentChain should return false before CoinStatsIndex
3233
// is started.
@@ -42,10 +43,10 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
4243
LOCK(cs_main);
4344
genesis_block_index = m_node.chainman->ActiveChain().Genesis();
4445
}
45-
BOOST_CHECK(coin_stats_index.LookUpStats(genesis_block_index));
46+
BOOST_CHECK(coin_stats_index.LookUpStats(*genesis_block_index));
4647

4748
// Check that CoinStatsIndex updates with new blocks.
48-
BOOST_CHECK(coin_stats_index.LookUpStats(block_index));
49+
BOOST_CHECK(coin_stats_index.LookUpStats(*block_index));
4950

5051
const CScript script_pub_key{CScript() << ToByteVector(coinbaseKey.GetPubKey()) << OP_CHECKSIG};
5152
std::vector<CMutableTransaction> noTxns;
@@ -59,7 +60,7 @@ BOOST_FIXTURE_TEST_CASE(coinstatsindex_initial_sync, TestChain100Setup)
5960
LOCK(cs_main);
6061
new_block_index = m_node.chainman->ActiveChain().Tip();
6162
}
62-
BOOST_CHECK(coin_stats_index.LookUpStats(new_block_index));
63+
BOOST_CHECK(coin_stats_index.LookUpStats(*new_block_index));
6364

6465
BOOST_CHECK(block_index != new_block_index);
6566

0 commit comments

Comments
 (0)