Changeset View
Changeset View
Standalone View
Standalone View
src/node/coinstats.cpp
Show First 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | for (auto it = outputs.begin(); it != outputs.end(); ++it) { | ||||
stats.nBogoSize += GetBogoSize(it->second.GetTxOut().scriptPubKey); | stats.nBogoSize += GetBogoSize(it->second.GetTxOut().scriptPubKey); | ||||
} | } | ||||
} | } | ||||
//! Calculate statistics about the unspent transaction output set | //! Calculate statistics about the unspent transaction output set | ||||
template <typename T> | template <typename T> | ||||
static bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, | static bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, | ||||
CCoinsStats &stats, T hash_obj, | CCoinsStats &stats, T hash_obj, | ||||
const std::function<void()> &interruption_point) { | const std::function<void()> &interruption_point, | ||||
const CBlockIndex *pindex) { | |||||
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); | std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor()); | ||||
assert(pcursor); | assert(pcursor); | ||||
stats.hashBlock = pcursor->GetBestBlock(); | |||||
const CBlockIndex *pindex; | if (!pindex) { | ||||
{ | |||||
LOCK(cs_main); | LOCK(cs_main); | ||||
assert(std::addressof(g_chainman.m_blockman) == | assert(std::addressof(g_chainman.m_blockman) == | ||||
std::addressof(blockman)); | std::addressof(blockman)); | ||||
pindex = blockman.LookupBlockIndex(view->GetBestBlock()); | |||||
pindex = blockman.LookupBlockIndex(stats.hashBlock); | |||||
stats.nHeight = Assert(pindex)->nHeight; | |||||
} | } | ||||
stats.nHeight = Assert(pindex)->nHeight; | |||||
stats.hashBlock = pindex->GetBlockHash(); | |||||
// Use CoinStatsIndex if it is available and a hash_type of Muhash or None | // Use CoinStatsIndex if it is available and a hash_type of Muhash or None | ||||
// was requested | // was requested | ||||
if ((stats.m_hash_type == CoinStatsHashType::MUHASH || | if ((stats.m_hash_type == CoinStatsHashType::MUHASH || | ||||
stats.m_hash_type == CoinStatsHashType::NONE) && | stats.m_hash_type == CoinStatsHashType::NONE) && | ||||
g_coin_stats_index) { | g_coin_stats_index) { | ||||
stats.from_index = true; | |||||
return g_coin_stats_index->LookUpStats(pindex, stats); | return g_coin_stats_index->LookUpStats(pindex, stats); | ||||
} | } | ||||
PrepareHash(hash_obj, stats); | PrepareHash(hash_obj, stats); | ||||
TxId prevkey; | TxId prevkey; | ||||
std::map<uint32_t, Coin> outputs; | std::map<uint32_t, Coin> outputs; | ||||
while (pcursor->Valid()) { | while (pcursor->Valid()) { | ||||
Show All 21 Lines | static bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, | ||||
FinalizeHash(hash_obj, stats); | FinalizeHash(hash_obj, stats); | ||||
stats.nDiskSize = view->EstimateSize(); | stats.nDiskSize = view->EstimateSize(); | ||||
return true; | return true; | ||||
} | } | ||||
bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, CCoinsStats &stats, | bool GetUTXOStats(CCoinsView *view, BlockManager &blockman, CCoinsStats &stats, | ||||
const std::function<void()> &interruption_point) { | const std::function<void()> &interruption_point, | ||||
const CBlockIndex *pindex) { | |||||
switch (stats.m_hash_type) { | switch (stats.m_hash_type) { | ||||
case (CoinStatsHashType::HASH_SERIALIZED): { | case (CoinStatsHashType::HASH_SERIALIZED): { | ||||
CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); | CHashWriter ss(SER_GETHASH, PROTOCOL_VERSION); | ||||
return GetUTXOStats(view, blockman, stats, ss, interruption_point); | return GetUTXOStats(view, blockman, stats, ss, interruption_point, | ||||
pindex); | |||||
} | } | ||||
case (CoinStatsHashType::MUHASH): { | case (CoinStatsHashType::MUHASH): { | ||||
MuHash3072 muhash; | MuHash3072 muhash; | ||||
return GetUTXOStats(view, blockman, stats, muhash, | return GetUTXOStats(view, blockman, stats, muhash, | ||||
interruption_point); | interruption_point, pindex); | ||||
} | } | ||||
case (CoinStatsHashType::NONE): { | case (CoinStatsHashType::NONE): { | ||||
return GetUTXOStats(view, blockman, stats, nullptr, | return GetUTXOStats(view, blockman, stats, nullptr, | ||||
interruption_point); | interruption_point, pindex); | ||||
} | } | ||||
} // no default case, so the compiler can warn about missing cases | } // no default case, so the compiler can warn about missing cases | ||||
assert(false); | assert(false); | ||||
} | } | ||||
// The legacy hash serializes the hashBlock | // The legacy hash serializes the hashBlock | ||||
static void PrepareHash(CHashWriter &ss, const CCoinsStats &stats) { | static void PrepareHash(CHashWriter &ss, const CCoinsStats &stats) { | ||||
ss << stats.hashBlock; | ss << stats.hashBlock; | ||||
Show All 14 Lines |