Skip to content

Commit addb4f2

Browse files
committed
indexes, refactor: Remove CBlockIndex* uses in coinstatsindex LookUpOne function
This commit does not change behavior in any way.
1 parent 33b4d48 commit addb4f2

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/index/coinstatsindex.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -299,23 +299,23 @@ bool CoinStatsIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* n
299299
return BaseIndex::Rewind(current_tip, new_tip);
300300
}
301301

302-
static bool LookUpOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result)
302+
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockKey& block, DBVal& result)
303303
{
304304
// First check if the result is stored under the height index and the value
305305
// there matches the block hash. This should be the case if the block is on
306306
// the active chain.
307307
std::pair<uint256, DBVal> read_out;
308-
if (!db.Read(DBHeightKey(block_index->nHeight), read_out)) {
308+
if (!db.Read(DBHeightKey(block.height), read_out)) {
309309
return false;
310310
}
311-
if (read_out.first == block_index->GetBlockHash()) {
311+
if (read_out.first == block.hash) {
312312
result = std::move(read_out.second);
313313
return true;
314314
}
315315

316316
// If value at the height index corresponds to an different block, the
317317
// result will be stored in the hash index.
318-
return db.Read(DBHashKey(block_index->GetBlockHash()), result);
318+
return db.Read(DBHashKey(block.hash), result);
319319
}
320320

321321
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex* block_index) const
@@ -324,7 +324,7 @@ std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex* block_
324324
stats.index_used = true;
325325

326326
DBVal entry;
327-
if (!LookUpOne(*m_db, block_index, entry)) {
327+
if (!LookUpOne(*m_db, {block_index->GetBlockHash(), block_index->nHeight}, entry)) {
328328
return std::nullopt;
329329
}
330330

@@ -363,7 +363,7 @@ bool CoinStatsIndex::Init()
363363

364364
if (pindex) {
365365
DBVal entry;
366-
if (!LookUpOne(*m_db, pindex, entry)) {
366+
if (!LookUpOne(*m_db, {pindex->GetBlockHash(), pindex->nHeight}, entry)) {
367367
return error("%s: Cannot read current %s state; index may be corrupted",
368368
__func__, GetName());
369369
}

src/interfaces/chain.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ namespace interfaces {
3838
class Handler;
3939
class Wallet;
4040

41+
//! Hash/height pair to help track and identify blocks.
42+
struct BlockKey {
43+
uint256 hash;
44+
int height = -1;
45+
};
46+
4147
//! Helper for findBlock to selectively return pieces of block data. If block is
4248
//! found, data will be returned by setting specified output variables. If block
4349
//! is not found, output variables will keep their previous values.

0 commit comments

Comments
 (0)