Bitcoin ABC 0.32.5
P2P Digital Currency
coinstats.cpp
Go to the documentation of this file.
1// Copyright (c) 2010 Satoshi Nakamoto
2// Copyright (c) 2009-2019 The Bitcoin Core developers
3// Distributed under the MIT software license, see the accompanying
4// file COPYING or http://www.opensource.org/licenses/mit-license.php.
5
6#include <node/coinstats.h>
7
8#include <coins.h>
10#include <validation.h>
11
12#include <optional>
13
14namespace node {
15
16std::optional<kernel::CCoinsStats>
19 const std::function<void()> &interruption_point,
20 const CBlockIndex *pindex, bool index_requested) {
21 // Use CoinStatsIndex if it is requested and available and a hash_type of
22 // Muhash or None was requested
23 if ((hash_type == kernel::CoinStatsHashType::MUHASH ||
24 hash_type == kernel::CoinStatsHashType::NONE) &&
25 g_coin_stats_index && index_requested) {
26 if (pindex) {
27 return g_coin_stats_index->LookUpStats(pindex);
28 } else {
29 CBlockIndex *block_index = WITH_LOCK(
31 return blockman.LookupBlockIndex(view->GetBestBlock()));
32 return g_coin_stats_index->LookUpStats(block_index);
33 }
34 }
35
36 // If the coinstats index isn't requested or is otherwise not usable, the
37 // pindex should either be null or equal to the view's best block. This is
38 // because without the coinstats index we can only get coinstats about the
39 // best block.
40 assert(!pindex || pindex->GetBlockHash() == view->GetBestBlock());
41
42 return kernel::ComputeUTXOStats(hash_type, view, blockman,
43 interruption_point);
44}
45} // namespace node
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:25
BlockHash GetBlockHash() const
Definition: blockindex.h:130
Abstract view on the open txout dataset.
Definition: coins.h:305
virtual BlockHash GetBestBlock() const
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: coins.cpp:16
Maintains a tree of blocks (stored in m_block_index) which is consulted to determine where the most-w...
Definition: blockstorage.h:107
CBlockIndex * LookupBlockIndex(const BlockHash &hash) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: cs_main.cpp:7
static bool ComputeUTXOStats(CCoinsView *view, CCoinsStats &stats, T hash_obj, const std::function< void()> &interruption_point)
Calculate statistics about the unspent transaction output set.
Definition: coinstats.cpp:95
CoinStatsHashType
Definition: coinstats.h:24
Definition: init.h:31
std::optional< kernel::CCoinsStats > GetUTXOStats(CCoinsView *view, BlockManager &blockman, kernel::CoinStatsHashType hash_type, const std::function< void()> &interruption_point, const CBlockIndex *pindex, bool index_requested)
Calculate statistics about the unspent transaction output set.
Definition: coinstats.cpp:17
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:357
assert(!tx.IsCoinBase())