mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-06 11:13:02 +02:00
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.
This commit is contained in:
@@ -316,28 +316,31 @@ static bool LookUpOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVa
|
||||
return db.Read(DBHashKey(block_index->GetBlockHash()), result);
|
||||
}
|
||||
|
||||
bool CoinStatsIndex::LookUpStats(const CBlockIndex* block_index, CCoinsStats& coins_stats) const
|
||||
std::optional<CCoinsStats> CoinStatsIndex::LookUpStats(const CBlockIndex* block_index) const
|
||||
{
|
||||
CCoinsStats stats{Assert(block_index)->nHeight, block_index->GetBlockHash()};
|
||||
stats.index_used = true;
|
||||
|
||||
DBVal entry;
|
||||
if (!LookUpOne(*m_db, block_index, entry)) {
|
||||
return false;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
coins_stats.hashSerialized = entry.muhash;
|
||||
coins_stats.nTransactionOutputs = entry.transaction_output_count;
|
||||
coins_stats.nBogoSize = entry.bogo_size;
|
||||
coins_stats.total_amount = entry.total_amount;
|
||||
coins_stats.total_subsidy = entry.total_subsidy;
|
||||
coins_stats.total_unspendable_amount = entry.total_unspendable_amount;
|
||||
coins_stats.total_prevout_spent_amount = entry.total_prevout_spent_amount;
|
||||
coins_stats.total_new_outputs_ex_coinbase_amount = entry.total_new_outputs_ex_coinbase_amount;
|
||||
coins_stats.total_coinbase_amount = entry.total_coinbase_amount;
|
||||
coins_stats.total_unspendables_genesis_block = entry.total_unspendables_genesis_block;
|
||||
coins_stats.total_unspendables_bip30 = entry.total_unspendables_bip30;
|
||||
coins_stats.total_unspendables_scripts = entry.total_unspendables_scripts;
|
||||
coins_stats.total_unspendables_unclaimed_rewards = entry.total_unspendables_unclaimed_rewards;
|
||||
stats.hashSerialized = entry.muhash;
|
||||
stats.nTransactionOutputs = entry.transaction_output_count;
|
||||
stats.nBogoSize = entry.bogo_size;
|
||||
stats.total_amount = entry.total_amount;
|
||||
stats.total_subsidy = entry.total_subsidy;
|
||||
stats.total_unspendable_amount = entry.total_unspendable_amount;
|
||||
stats.total_prevout_spent_amount = entry.total_prevout_spent_amount;
|
||||
stats.total_new_outputs_ex_coinbase_amount = entry.total_new_outputs_ex_coinbase_amount;
|
||||
stats.total_coinbase_amount = entry.total_coinbase_amount;
|
||||
stats.total_unspendables_genesis_block = entry.total_unspendables_genesis_block;
|
||||
stats.total_unspendables_bip30 = entry.total_unspendables_bip30;
|
||||
stats.total_unspendables_scripts = entry.total_unspendables_scripts;
|
||||
stats.total_unspendables_unclaimed_rewards = entry.total_unspendables_unclaimed_rewards;
|
||||
|
||||
return true;
|
||||
return stats;
|
||||
}
|
||||
|
||||
bool CoinStatsIndex::Init()
|
||||
|
||||
@@ -56,7 +56,7 @@ public:
|
||||
explicit CoinStatsIndex(size_t n_cache_size, bool f_memory = false, bool f_wipe = false);
|
||||
|
||||
// Look up stats for a specific block using CBlockIndex
|
||||
bool LookUpStats(const CBlockIndex* block_index, node::CCoinsStats& coins_stats) const;
|
||||
std::optional<node::CCoinsStats> LookUpStats(const CBlockIndex* block_index) const;
|
||||
};
|
||||
|
||||
/// The global UTXO set hash object.
|
||||
|
||||
Reference in New Issue
Block a user