Bitcoin ABC 0.30.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 <optional>
11#include <validation.h>
12
13namespace node {
14
15std::optional<kernel::CCoinsStats>
18 const std::function<void()> &interruption_point,
19 const CBlockIndex *pindex, bool index_requested) {
20 // Use CoinStatsIndex if it is requested and available and a hash_type of
21 // Muhash or None was requested
22 if ((hash_type == kernel::CoinStatsHashType::MUHASH ||
23 hash_type == kernel::CoinStatsHashType::NONE) &&
24 g_coin_stats_index && index_requested) {
25 if (pindex) {
26 return g_coin_stats_index->LookUpStats(pindex);
27 } else {
28 CBlockIndex *block_index = WITH_LOCK(
30 return blockman.LookupBlockIndex(view->GetBestBlock()));
31 return g_coin_stats_index->LookUpStats(block_index);
32 }
33 }
34
35 // If the coinstats index isn't requested or is otherwise not usable, the
36 // pindex should either be null or equal to the view's best block. This is
37 // because without the coinstats index we can only get coinstats about the
38 // best block.
39 assert(!pindex || pindex->GetBlockHash() == view->GetBestBlock());
40
41 return kernel::ComputeUTXOStats(hash_type, view, blockman,
42 interruption_point);
43}
44} // 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:146
Abstract view on the open txout dataset.
Definition: coins.h:163
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:74
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:92
CoinStatsHashType
Definition: coinstats.h:23
Definition: init.h:28
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:16
#define WITH_LOCK(cs, code)
Run code while locking a mutex.
Definition: sync.h:357
assert(!tx.IsCoinBase())