index: Coinstats index can be activated with command line flag

This commit is contained in:
Fabian Jahr
2020-01-24 18:58:47 +01:00
parent dd58a4de21
commit 3c914d58ff
5 changed files with 38 additions and 5 deletions

View File

@@ -8,6 +8,7 @@
#include <coins.h>
#include <crypto/muhash.h>
#include <hash.h>
#include <index/coinstatsindex.h>
#include <serialize.h>
#include <uint256.h>
#include <util/system.h>
@@ -92,13 +93,19 @@ static bool GetUTXOStats(CCoinsView* view, BlockManager& blockman, CCoinsStats&
{
std::unique_ptr<CCoinsViewCursor> pcursor(view->Cursor());
assert(pcursor);
stats.hashBlock = pcursor->GetBestBlock();
const CBlockIndex* pindex;
{
LOCK(cs_main);
assert(std::addressof(g_chainman.m_blockman) == std::addressof(blockman));
const CBlockIndex* block = blockman.LookupBlockIndex(stats.hashBlock);
stats.nHeight = Assert(block)->nHeight;
pindex = blockman.LookupBlockIndex(stats.hashBlock);
stats.nHeight = Assert(pindex)->nHeight;
}
// Use CoinStatsIndex if it is available and a hash_type of Muhash or None was requested
if ((stats.m_hash_type == CoinStatsHashType::MUHASH || stats.m_hash_type == CoinStatsHashType::NONE) && g_coin_stats_index) {
return g_coin_stats_index->LookUpStats(pindex, stats);
}
PrepareHash(hash_obj, stats);