mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-05-23 18:32:45 +02:00
indexes, refactor: Remove CBlockIndex* uses in coinstatsindex LookUpOne function
This commit does not change behavior in any way.
This commit is contained in:
parent
33b4d48cfc
commit
addb4f2af1
@ -299,23 +299,23 @@ bool CoinStatsIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* n
|
|||||||
return BaseIndex::Rewind(current_tip, new_tip);
|
return BaseIndex::Rewind(current_tip, new_tip);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool LookUpOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result)
|
static bool LookUpOne(const CDBWrapper& db, const interfaces::BlockKey& block, DBVal& result)
|
||||||
{
|
{
|
||||||
// First check if the result is stored under the height index and the value
|
// First check if the result is stored under the height index and the value
|
||||||
// there matches the block hash. This should be the case if the block is on
|
// there matches the block hash. This should be the case if the block is on
|
||||||
// the active chain.
|
// the active chain.
|
||||||
std::pair<uint256, DBVal> read_out;
|
std::pair<uint256, DBVal> read_out;
|
||||||
if (!db.Read(DBHeightKey(block_index->nHeight), read_out)) {
|
if (!db.Read(DBHeightKey(block.height), read_out)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (read_out.first == block_index->GetBlockHash()) {
|
if (read_out.first == block.hash) {
|
||||||
result = std::move(read_out.second);
|
result = std::move(read_out.second);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If value at the height index corresponds to an different block, the
|
// If value at the height index corresponds to an different block, the
|
||||||
// result will be stored in the hash index.
|
// result will be stored in the hash index.
|
||||||
return db.Read(DBHashKey(block_index->GetBlockHash()), result);
|
return db.Read(DBHashKey(block.hash), result);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex* block_index) const
|
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex* block_index) const
|
||||||
@ -324,7 +324,7 @@ std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex* block_
|
|||||||
stats.index_used = true;
|
stats.index_used = true;
|
||||||
|
|
||||||
DBVal entry;
|
DBVal entry;
|
||||||
if (!LookUpOne(*m_db, block_index, entry)) {
|
if (!LookUpOne(*m_db, {block_index->GetBlockHash(), block_index->nHeight}, entry)) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +363,7 @@ bool CoinStatsIndex::Init()
|
|||||||
|
|
||||||
if (pindex) {
|
if (pindex) {
|
||||||
DBVal entry;
|
DBVal entry;
|
||||||
if (!LookUpOne(*m_db, pindex, entry)) {
|
if (!LookUpOne(*m_db, {pindex->GetBlockHash(), pindex->nHeight}, entry)) {
|
||||||
return error("%s: Cannot read current %s state; index may be corrupted",
|
return error("%s: Cannot read current %s state; index may be corrupted",
|
||||||
__func__, GetName());
|
__func__, GetName());
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,12 @@ namespace interfaces {
|
|||||||
class Handler;
|
class Handler;
|
||||||
class Wallet;
|
class Wallet;
|
||||||
|
|
||||||
|
//! Hash/height pair to help track and identify blocks.
|
||||||
|
struct BlockKey {
|
||||||
|
uint256 hash;
|
||||||
|
int height = -1;
|
||||||
|
};
|
||||||
|
|
||||||
//! Helper for findBlock to selectively return pieces of block data. If block is
|
//! Helper for findBlock to selectively return pieces of block data. If block is
|
||||||
//! found, data will be returned by setting specified output variables. If block
|
//! found, data will be returned by setting specified output variables. If block
|
||||||
//! is not found, output variables will keep their previous values.
|
//! is not found, output variables will keep their previous values.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user