Bitcoin Core  22.99.0
P2P Digital Currency
coinstatsindex.cpp
Go to the documentation of this file.
1 // Copyright (c) 2020-2021 The Bitcoin Core developers
2 // Distributed under the MIT software license, see the accompanying
3 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
4 
5 #include <chainparams.h>
6 #include <coins.h>
7 #include <crypto/muhash.h>
8 #include <index/coinstatsindex.h>
9 #include <node/blockstorage.h>
10 #include <serialize.h>
11 #include <txdb.h>
12 #include <undo.h>
13 #include <validation.h>
14 
15 using node::CCoinsStats;
16 using node::GetBogoSize;
18 using node::TxOutSer;
20 
21 static constexpr uint8_t DB_BLOCK_HASH{'s'};
22 static constexpr uint8_t DB_BLOCK_HEIGHT{'t'};
23 static constexpr uint8_t DB_MUHASH{'M'};
24 
25 namespace {
26 
27 struct DBVal {
28  uint256 muhash;
29  uint64_t transaction_output_count;
30  uint64_t bogo_size;
31  CAmount total_amount;
32  CAmount total_subsidy;
33  CAmount total_unspendable_amount;
34  CAmount total_prevout_spent_amount;
35  CAmount total_new_outputs_ex_coinbase_amount;
36  CAmount total_coinbase_amount;
37  CAmount total_unspendables_genesis_block;
38  CAmount total_unspendables_bip30;
39  CAmount total_unspendables_scripts;
40  CAmount total_unspendables_unclaimed_rewards;
41 
42  SERIALIZE_METHODS(DBVal, obj)
43  {
44  READWRITE(obj.muhash);
45  READWRITE(obj.transaction_output_count);
46  READWRITE(obj.bogo_size);
47  READWRITE(obj.total_amount);
48  READWRITE(obj.total_subsidy);
49  READWRITE(obj.total_unspendable_amount);
50  READWRITE(obj.total_prevout_spent_amount);
51  READWRITE(obj.total_new_outputs_ex_coinbase_amount);
52  READWRITE(obj.total_coinbase_amount);
53  READWRITE(obj.total_unspendables_genesis_block);
54  READWRITE(obj.total_unspendables_bip30);
55  READWRITE(obj.total_unspendables_scripts);
56  READWRITE(obj.total_unspendables_unclaimed_rewards);
57  }
58 };
59 
60 struct DBHeightKey {
61  int height;
62 
63  explicit DBHeightKey(int height_in) : height(height_in) {}
64 
65  template <typename Stream>
66  void Serialize(Stream& s) const
67  {
69  ser_writedata32be(s, height);
70  }
71 
72  template <typename Stream>
73  void Unserialize(Stream& s)
74  {
75  const uint8_t prefix{ser_readdata8(s)};
76  if (prefix != DB_BLOCK_HEIGHT) {
77  throw std::ios_base::failure("Invalid format for coinstatsindex DB height key");
78  }
79  height = ser_readdata32be(s);
80  }
81 };
82 
83 struct DBHashKey {
84  uint256 block_hash;
85 
86  explicit DBHashKey(const uint256& hash_in) : block_hash(hash_in) {}
87 
88  SERIALIZE_METHODS(DBHashKey, obj)
89  {
90  uint8_t prefix{DB_BLOCK_HASH};
92  if (prefix != DB_BLOCK_HASH) {
93  throw std::ios_base::failure("Invalid format for coinstatsindex DB hash key");
94  }
95 
96  READWRITE(obj.block_hash);
97  }
98 };
99 
100 }; // namespace
101 
102 std::unique_ptr<CoinStatsIndex> g_coin_stats_index;
103 
104 CoinStatsIndex::CoinStatsIndex(size_t n_cache_size, bool f_memory, bool f_wipe)
105 {
106  fs::path path{gArgs.GetDataDirNet() / "indexes" / "coinstats"};
108 
109  m_db = std::make_unique<CoinStatsIndex::DB>(path / "db", n_cache_size, f_memory, f_wipe);
110 }
111 
112 bool CoinStatsIndex::WriteBlock(const CBlock& block, const CBlockIndex* pindex)
113 {
114  CBlockUndo block_undo;
115  const CAmount block_subsidy{GetBlockSubsidy(pindex->nHeight, Params().GetConsensus())};
116  m_total_subsidy += block_subsidy;
117 
118  // Ignore genesis block
119  if (pindex->nHeight > 0) {
120  if (!UndoReadFromDisk(block_undo, pindex)) {
121  return false;
122  }
123 
124  std::pair<uint256, DBVal> read_out;
125  if (!m_db->Read(DBHeightKey(pindex->nHeight - 1), read_out)) {
126  return false;
127  }
128 
129  uint256 expected_block_hash{pindex->pprev->GetBlockHash()};
130  if (read_out.first != expected_block_hash) {
131  LogPrintf("WARNING: previous block header belongs to unexpected block %s; expected %s\n",
132  read_out.first.ToString(), expected_block_hash.ToString());
133 
134  if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) {
135  return error("%s: previous block header not found; expected %s",
136  __func__, expected_block_hash.ToString());
137  }
138  }
139 
140  // TODO: Deduplicate BIP30 related code
141  bool is_bip30_block{(pindex->nHeight == 91722 && pindex->GetBlockHash() == uint256S("0x00000000000271a2dc26e7667f8419f2e15416dc6955e5a6c6cdf3f2574dd08e")) ||
142  (pindex->nHeight == 91812 && pindex->GetBlockHash() == uint256S("0x00000000000af0aed4792b1acee3d966af36cf5def14935db8de83d6f9306f2f"))};
143 
144  // Add the new utxos created from the block
145  for (size_t i = 0; i < block.vtx.size(); ++i) {
146  const auto& tx{block.vtx.at(i)};
147 
148  // Skip duplicate txid coinbase transactions (BIP30).
149  if (is_bip30_block && tx->IsCoinBase()) {
150  m_total_unspendable_amount += block_subsidy;
151  m_total_unspendables_bip30 += block_subsidy;
152  continue;
153  }
154 
155  for (uint32_t j = 0; j < tx->vout.size(); ++j) {
156  const CTxOut& out{tx->vout[j]};
157  Coin coin{out, pindex->nHeight, tx->IsCoinBase()};
158  COutPoint outpoint{tx->GetHash(), j};
159 
160  // Skip unspendable coins
161  if (coin.out.scriptPubKey.IsUnspendable()) {
162  m_total_unspendable_amount += coin.out.nValue;
163  m_total_unspendables_scripts += coin.out.nValue;
164  continue;
165  }
166 
167  m_muhash.Insert(MakeUCharSpan(TxOutSer(outpoint, coin)));
168 
169  if (tx->IsCoinBase()) {
170  m_total_coinbase_amount += coin.out.nValue;
171  } else {
172  m_total_new_outputs_ex_coinbase_amount += coin.out.nValue;
173  }
174 
176  m_total_amount += coin.out.nValue;
177  m_bogo_size += GetBogoSize(coin.out.scriptPubKey);
178  }
179 
180  // The coinbase tx has no undo data since no former output is spent
181  if (!tx->IsCoinBase()) {
182  const auto& tx_undo{block_undo.vtxundo.at(i - 1)};
183 
184  for (size_t j = 0; j < tx_undo.vprevout.size(); ++j) {
185  Coin coin{tx_undo.vprevout[j]};
186  COutPoint outpoint{tx->vin[j].prevout.hash, tx->vin[j].prevout.n};
187 
188  m_muhash.Remove(MakeUCharSpan(TxOutSer(outpoint, coin)));
189 
190  m_total_prevout_spent_amount += coin.out.nValue;
191 
193  m_total_amount -= coin.out.nValue;
194  m_bogo_size -= GetBogoSize(coin.out.scriptPubKey);
195  }
196  }
197  }
198  } else {
199  // genesis block
200  m_total_unspendable_amount += block_subsidy;
201  m_total_unspendables_genesis_block += block_subsidy;
202  }
203 
204  // If spent prevouts + block subsidy are still a higher amount than
205  // new outputs + coinbase + current unspendable amount this means
206  // the miner did not claim the full block reward. Unclaimed block
207  // rewards are also unspendable.
209  m_total_unspendable_amount += unclaimed_rewards;
210  m_total_unspendables_unclaimed_rewards += unclaimed_rewards;
211 
212  std::pair<uint256, DBVal> value;
213  value.first = pindex->GetBlockHash();
214  value.second.transaction_output_count = m_transaction_output_count;
215  value.second.bogo_size = m_bogo_size;
216  value.second.total_amount = m_total_amount;
217  value.second.total_subsidy = m_total_subsidy;
218  value.second.total_unspendable_amount = m_total_unspendable_amount;
219  value.second.total_prevout_spent_amount = m_total_prevout_spent_amount;
220  value.second.total_new_outputs_ex_coinbase_amount = m_total_new_outputs_ex_coinbase_amount;
221  value.second.total_coinbase_amount = m_total_coinbase_amount;
222  value.second.total_unspendables_genesis_block = m_total_unspendables_genesis_block;
223  value.second.total_unspendables_bip30 = m_total_unspendables_bip30;
224  value.second.total_unspendables_scripts = m_total_unspendables_scripts;
225  value.second.total_unspendables_unclaimed_rewards = m_total_unspendables_unclaimed_rewards;
226 
227  uint256 out;
228  m_muhash.Finalize(out);
229  value.second.muhash = out;
230 
231  CDBBatch batch(*m_db);
232  batch.Write(DBHeightKey(pindex->nHeight), value);
233  batch.Write(DB_MUHASH, m_muhash);
234  return m_db->WriteBatch(batch);
235 }
236 
238  const std::string& index_name,
239  int start_height, int stop_height)
240 {
241  DBHeightKey key{start_height};
242  db_it.Seek(key);
243 
244  for (int height = start_height; height <= stop_height; ++height) {
245  if (!db_it.GetKey(key) || key.height != height) {
246  return error("%s: unexpected key in %s: expected (%c, %d)",
247  __func__, index_name, DB_BLOCK_HEIGHT, height);
248  }
249 
250  std::pair<uint256, DBVal> value;
251  if (!db_it.GetValue(value)) {
252  return error("%s: unable to read value in %s at key (%c, %d)",
253  __func__, index_name, DB_BLOCK_HEIGHT, height);
254  }
255 
256  batch.Write(DBHashKey(value.first), std::move(value.second));
257 
258  db_it.Next();
259  }
260  return true;
261 }
262 
263 bool CoinStatsIndex::Rewind(const CBlockIndex* current_tip, const CBlockIndex* new_tip)
264 {
265  assert(current_tip->GetAncestor(new_tip->nHeight) == new_tip);
266 
267  CDBBatch batch(*m_db);
268  std::unique_ptr<CDBIterator> db_it(m_db->NewIterator());
269 
270  // During a reorg, we need to copy all hash digests for blocks that are
271  // getting disconnected from the height index to the hash index so we can
272  // still find them when the height index entries are overwritten.
273  if (!CopyHeightIndexToHashIndex(*db_it, batch, m_name, new_tip->nHeight, current_tip->nHeight)) {
274  return false;
275  }
276 
277  if (!m_db->WriteBatch(batch)) return false;
278 
279  {
280  LOCK(cs_main);
282  const auto& consensus_params{Params().GetConsensus()};
283 
284  do {
285  CBlock block;
286 
287  if (!ReadBlockFromDisk(block, iter_tip, consensus_params)) {
288  return error("%s: Failed to read block %s from disk",
289  __func__, iter_tip->GetBlockHash().ToString());
290  }
291 
292  ReverseBlock(block, iter_tip);
293 
294  iter_tip = iter_tip->GetAncestor(iter_tip->nHeight - 1);
295  } while (new_tip != iter_tip);
296  }
297 
298  return BaseIndex::Rewind(current_tip, new_tip);
299 }
300 
301 static bool LookUpOne(const CDBWrapper& db, const CBlockIndex* block_index, DBVal& result)
302 {
303  // First check if the result is stored under the height index and the value
304  // there matches the block hash. This should be the case if the block is on
305  // the active chain.
306  std::pair<uint256, DBVal> read_out;
307  if (!db.Read(DBHeightKey(block_index->nHeight), read_out)) {
308  return false;
309  }
310  if (read_out.first == block_index->GetBlockHash()) {
311  result = std::move(read_out.second);
312  return true;
313  }
314 
315  // If value at the height index corresponds to an different block, the
316  // result will be stored in the hash index.
317  return db.Read(DBHashKey(block_index->GetBlockHash()), result);
318 }
319 
320 bool CoinStatsIndex::LookUpStats(const CBlockIndex* block_index, CCoinsStats& coins_stats) const
321 {
322  DBVal entry;
323  if (!LookUpOne(*m_db, block_index, entry)) {
324  return false;
325  }
326 
327  coins_stats.hashSerialized = entry.muhash;
328  coins_stats.nTransactionOutputs = entry.transaction_output_count;
329  coins_stats.nBogoSize = entry.bogo_size;
330  coins_stats.total_amount = entry.total_amount;
331  coins_stats.total_subsidy = entry.total_subsidy;
332  coins_stats.total_unspendable_amount = entry.total_unspendable_amount;
333  coins_stats.total_prevout_spent_amount = entry.total_prevout_spent_amount;
334  coins_stats.total_new_outputs_ex_coinbase_amount = entry.total_new_outputs_ex_coinbase_amount;
335  coins_stats.total_coinbase_amount = entry.total_coinbase_amount;
336  coins_stats.total_unspendables_genesis_block = entry.total_unspendables_genesis_block;
337  coins_stats.total_unspendables_bip30 = entry.total_unspendables_bip30;
338  coins_stats.total_unspendables_scripts = entry.total_unspendables_scripts;
339  coins_stats.total_unspendables_unclaimed_rewards = entry.total_unspendables_unclaimed_rewards;
340 
341  return true;
342 }
343 
345 {
346  if (!m_db->Read(DB_MUHASH, m_muhash)) {
347  // Check that the cause of the read failure is that the key does not
348  // exist. Any other errors indicate database corruption or a disk
349  // failure, and starting the index would cause further corruption.
350  if (m_db->Exists(DB_MUHASH)) {
351  return error("%s: Cannot read current %s state; index may be corrupted",
352  __func__, GetName());
353  }
354  }
355 
356  if (!BaseIndex::Init()) return false;
357 
358  const CBlockIndex* pindex{CurrentIndex()};
359 
360  if (pindex) {
361  DBVal entry;
362  if (!LookUpOne(*m_db, pindex, entry)) {
363  return error("%s: Cannot read current %s state; index may be corrupted",
364  __func__, GetName());
365  }
366  m_transaction_output_count = entry.transaction_output_count;
367  m_bogo_size = entry.bogo_size;
368  m_total_amount = entry.total_amount;
369  m_total_subsidy = entry.total_subsidy;
370  m_total_unspendable_amount = entry.total_unspendable_amount;
371  m_total_prevout_spent_amount = entry.total_prevout_spent_amount;
372  m_total_new_outputs_ex_coinbase_amount = entry.total_new_outputs_ex_coinbase_amount;
373  m_total_coinbase_amount = entry.total_coinbase_amount;
374  m_total_unspendables_genesis_block = entry.total_unspendables_genesis_block;
375  m_total_unspendables_bip30 = entry.total_unspendables_bip30;
376  m_total_unspendables_scripts = entry.total_unspendables_scripts;
377  m_total_unspendables_unclaimed_rewards = entry.total_unspendables_unclaimed_rewards;
378  }
379 
380  return true;
381 }
382 
383 // Reverse a single block as part of a reorg
384 bool CoinStatsIndex::ReverseBlock(const CBlock& block, const CBlockIndex* pindex)
385 {
386  CBlockUndo block_undo;
387  std::pair<uint256, DBVal> read_out;
388 
389  const CAmount block_subsidy{GetBlockSubsidy(pindex->nHeight, Params().GetConsensus())};
390  m_total_subsidy -= block_subsidy;
391 
392  // Ignore genesis block
393  if (pindex->nHeight > 0) {
394  if (!UndoReadFromDisk(block_undo, pindex)) {
395  return false;
396  }
397 
398  if (!m_db->Read(DBHeightKey(pindex->nHeight - 1), read_out)) {
399  return false;
400  }
401 
402  uint256 expected_block_hash{pindex->pprev->GetBlockHash()};
403  if (read_out.first != expected_block_hash) {
404  LogPrintf("WARNING: previous block header belongs to unexpected block %s; expected %s\n",
405  read_out.first.ToString(), expected_block_hash.ToString());
406 
407  if (!m_db->Read(DBHashKey(expected_block_hash), read_out)) {
408  return error("%s: previous block header not found; expected %s",
409  __func__, expected_block_hash.ToString());
410  }
411  }
412  }
413 
414  // Remove the new UTXOs that were created from the block
415  for (size_t i = 0; i < block.vtx.size(); ++i) {
416  const auto& tx{block.vtx.at(i)};
417 
418  for (uint32_t j = 0; j < tx->vout.size(); ++j) {
419  const CTxOut& out{tx->vout[j]};
420  COutPoint outpoint{tx->GetHash(), j};
421  Coin coin{out, pindex->nHeight, tx->IsCoinBase()};
422 
423  // Skip unspendable coins
424  if (coin.out.scriptPubKey.IsUnspendable()) {
425  m_total_unspendable_amount -= coin.out.nValue;
426  m_total_unspendables_scripts -= coin.out.nValue;
427  continue;
428  }
429 
430  m_muhash.Remove(MakeUCharSpan(TxOutSer(outpoint, coin)));
431 
432  if (tx->IsCoinBase()) {
433  m_total_coinbase_amount -= coin.out.nValue;
434  } else {
435  m_total_new_outputs_ex_coinbase_amount -= coin.out.nValue;
436  }
437 
439  m_total_amount -= coin.out.nValue;
440  m_bogo_size -= GetBogoSize(coin.out.scriptPubKey);
441  }
442 
443  // The coinbase tx has no undo data since no former output is spent
444  if (!tx->IsCoinBase()) {
445  const auto& tx_undo{block_undo.vtxundo.at(i - 1)};
446 
447  for (size_t j = 0; j < tx_undo.vprevout.size(); ++j) {
448  Coin coin{tx_undo.vprevout[j]};
449  COutPoint outpoint{tx->vin[j].prevout.hash, tx->vin[j].prevout.n};
450 
451  m_muhash.Insert(MakeUCharSpan(TxOutSer(outpoint, coin)));
452 
453  m_total_prevout_spent_amount -= coin.out.nValue;
454 
456  m_total_amount += coin.out.nValue;
457  m_bogo_size += GetBogoSize(coin.out.scriptPubKey);
458  }
459  }
460  }
461 
463  m_total_unspendable_amount -= unclaimed_rewards;
464  m_total_unspendables_unclaimed_rewards -= unclaimed_rewards;
465 
466  // Check that the rolled back internal values are consistent with the DB read out
467  uint256 out;
468  m_muhash.Finalize(out);
469  Assert(read_out.second.muhash == out);
470 
471  Assert(m_transaction_output_count == read_out.second.transaction_output_count);
472  Assert(m_total_amount == read_out.second.total_amount);
473  Assert(m_bogo_size == read_out.second.bogo_size);
474  Assert(m_total_subsidy == read_out.second.total_subsidy);
475  Assert(m_total_unspendable_amount == read_out.second.total_unspendable_amount);
476  Assert(m_total_prevout_spent_amount == read_out.second.total_prevout_spent_amount);
477  Assert(m_total_new_outputs_ex_coinbase_amount == read_out.second.total_new_outputs_ex_coinbase_amount);
478  Assert(m_total_coinbase_amount == read_out.second.total_coinbase_amount);
479  Assert(m_total_unspendables_genesis_block == read_out.second.total_unspendables_genesis_block);
480  Assert(m_total_unspendables_bip30 == read_out.second.total_unspendables_bip30);
481  Assert(m_total_unspendables_scripts == read_out.second.total_unspendables_scripts);
482  Assert(m_total_unspendables_unclaimed_rewards == read_out.second.total_unspendables_unclaimed_rewards);
483 
484  return m_db->Write(DB_MUHASH, m_muhash);
485 }
DB_BLOCK_HEIGHT
static constexpr uint8_t DB_BLOCK_HEIGHT
Definition: coinstatsindex.cpp:22
GetBlockSubsidy
CAmount GetBlockSubsidy(int nHeight, const Consensus::Params &consensusParams)
Definition: validation.cpp:1414
CoinStatsIndex::m_total_unspendable_amount
CAmount m_total_unspendable_amount
Definition: coinstatsindex.h:28
MakeUCharSpan
constexpr auto MakeUCharSpan(V &&v) -> decltype(UCharSpanCast(Span
Like the Span constructor, but for (const) unsigned char member types only.
Definition: span.h:285
SERIALIZE_METHODS
#define SERIALIZE_METHODS(cls, obj)
Implement the Serialize and Unserialize methods by delegating to a single templated static method tha...
Definition: serialize.h:176
CoinStatsIndex::m_muhash
MuHash3072 m_muhash
Definition: coinstatsindex.h:23
CBlockIndex::GetAncestor
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: chain.cpp:114
assert
assert(!tx.IsCoinBase())
CoinStatsIndex::m_total_unspendables_bip30
CAmount m_total_unspendables_bip30
Definition: coinstatsindex.h:33
CoinStatsIndex::GetName
const char * GetName() const override
Get the name of the index for display in logs.
Definition: coinstatsindex.h:48
node::BlockManager::LookupBlockIndex
CBlockIndex * LookupBlockIndex(const uint256 &hash) const EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Definition: blockstorage.cpp:35
CoinStatsIndex::WriteBlock
bool WriteBlock(const CBlock &block, const CBlockIndex *pindex) override
Write update index entries for a newly connected block.
Definition: coinstatsindex.cpp:112
LookUpOne
static bool LookUpOne(const CDBWrapper &db, const CBlockIndex *block_index, DBVal &result)
Definition: coinstatsindex.cpp:301
node::CCoinsStats
Definition: coinstats.h:30
CDBBatch
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:47
ArgsManager::GetDataDirNet
const fs::path & GetDataDirNet() const
Get data directory path with appended network identifier.
Definition: system.h:304
node::CCoinsStats::hashSerialized
uint256 hashSerialized
Definition: coinstats.h:39
BaseIndex::Init
virtual bool Init()
Initialize internal state from the database and block index.
Definition: base.cpp:58
node::CCoinsStats::nTransactionOutputs
uint64_t nTransactionOutputs
Definition: coinstats.h:37
COutPoint::hash
uint256 hash
Definition: transaction.h:29
CBlockIndex::pprev
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:158
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:164
BaseIndex::m_chainstate
CChainState * m_chainstate
Definition: base.h:79
node::CCoinsStats::total_prevout_spent_amount
CAmount total_prevout_spent_amount
Total cumulative amount of prevouts spent up to and including this block.
Definition: coinstats.h:59
MuHash3072::Insert
MuHash3072 & Insert(Span< const unsigned char > in) noexcept
Definition: muhash.cpp:338
node::CCoinsStats::total_amount
std::optional< CAmount > total_amount
The total amount, or nullopt if an overflow occurred calculating it.
Definition: coinstats.h:42
node::CCoinsStats::total_unspendables_unclaimed_rewards
CAmount total_unspendables_unclaimed_rewards
Total cumulative amount of coins lost due to unclaimed miner rewards up to and including this block.
Definition: coinstats.h:71
CChainParams::GetConsensus
const Consensus::Params & GetConsensus() const
Definition: chainparams.h:82
CDBWrapper::Read
bool Read(const K &key, V &value) const
Definition: dbwrapper.h:231
node::CCoinsStats::nBogoSize
uint64_t nBogoSize
Definition: coinstats.h:38
CoinStatsIndex::m_total_unspendables_genesis_block
CAmount m_total_unspendables_genesis_block
Definition: coinstatsindex.h:32
coinstatsindex.h
chainparams.h
CoinStatsIndex::m_bogo_size
uint64_t m_bogo_size
Definition: coinstatsindex.h:25
node::ReadBlockFromDisk
bool ReadBlockFromDisk(CBlock &block, const FlatFilePos &pos, const Consensus::Params &consensusParams)
Functions for disk access for blocks.
Definition: blockstorage.cpp:745
Unserialize
void Unserialize(Stream &, char)=delete
CBlockUndo::vtxundo
std::vector< CTxUndo > vtxundo
Definition: undo.h:66
Serialize
void Serialize(Stream &, char)=delete
Assert
#define Assert(val)
Identity function.
Definition: check.h:57
DB_MUHASH
static constexpr uint8_t DB_MUHASH
Definition: coinstatsindex.cpp:23
CoinStatsIndex::m_db
std::unique_ptr< BaseIndex::DB > m_db
Definition: coinstatsindex.h:21
g_coin_stats_index
std::unique_ptr< CoinStatsIndex > g_coin_stats_index
The global UTXO set hash object.
Definition: coinstatsindex.cpp:100
node::TxOutSer
CDataStream TxOutSer(const COutPoint &outpoint, const Coin &coin)
Definition: coinstats.cpp:32
CoinStatsIndex::m_total_amount
CAmount m_total_amount
Definition: coinstatsindex.h:26
BaseIndex::CurrentIndex
const CBlockIndex * CurrentIndex()
Definition: base.h:85
CDBIterator::Next
void Next()
Definition: dbwrapper.cpp:244
prefix
const char * prefix
Definition: rest.cpp:926
CDBBatch::Write
void Write(const K &key, const V &value)
Definition: dbwrapper.h:73
MuHash3072::Remove
MuHash3072 & Remove(Span< const unsigned char > in) noexcept
Definition: muhash.cpp:343
muhash.h
node::UndoReadFromDisk
bool UndoReadFromDisk(CBlockUndo &blockundo, const CBlockIndex *pindex)
Definition: blockstorage.cpp:515
ser_readdata32be
uint32_t ser_readdata32be(Stream &s)
Definition: serialize.h:106
CoinStatsIndex::m_total_new_outputs_ex_coinbase_amount
CAmount m_total_new_outputs_ex_coinbase_amount
Definition: coinstatsindex.h:30
node::CCoinsStats::total_unspendables_scripts
CAmount total_unspendables_scripts
Total cumulative amount of outputs sent to unspendable scripts (OP_RETURN for example) up to and incl...
Definition: coinstats.h:69
CoinStatsIndex::LookUpStats
bool LookUpStats(const CBlockIndex *block_index, node::CCoinsStats &coins_stats) const
Definition: coinstatsindex.cpp:320
CDBIterator::GetValue
bool GetValue(V &value)
Definition: dbwrapper.h:158
CoinStatsIndex::Rewind
bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip) override
Rewind index to an earlier chain tip during a chain reorg.
Definition: coinstatsindex.cpp:263
CChainState::m_blockman
node::BlockManager & m_blockman
Reference to a BlockManager instance which itself is shared across all CChainState instances.
Definition: validation.h:498
CoinStatsIndex::m_total_subsidy
CAmount m_total_subsidy
Definition: coinstatsindex.h:27
CopyHeightIndexToHashIndex
static bool CopyHeightIndexToHashIndex(CDBIterator &db_it, CDBBatch &batch, const std::string &index_name, int start_height, int stop_height)
Definition: coinstatsindex.cpp:237
CTxOut
An output of a transaction.
Definition: transaction.h:148
Coin
A UTXO entry.
Definition: coins.h:30
BaseIndex::Rewind
virtual bool Rewind(const CBlockIndex *current_tip, const CBlockIndex *new_tip)
Rewind index to an earlier chain tip during a chain reorg.
Definition: base.cpp:223
fs::path
Path class wrapper to block calls to the fs::path(std::string) implicit constructor and the fs::path:...
Definition: fs.h:29
CoinStatsIndex::m_name
std::string m_name
Definition: coinstatsindex.h:20
undo.h
node::CCoinsStats::total_unspendable_amount
CAmount total_unspendable_amount
Total cumulative amount of unspendable coins up to and including this block.
Definition: coinstats.h:57
CoinStatsIndex::Init
bool Init() override
Initialize internal state from the database and block index.
Definition: coinstatsindex.cpp:344
LogPrintf
#define LogPrintf(...)
Definition: logging.h:188
CAmount
int64_t CAmount
Amount in satoshis (Can be negative)
Definition: amount.h:12
ser_readdata8
uint8_t ser_readdata8(Stream &s)
Definition: serialize.h:82
node::CCoinsStats::total_coinbase_amount
CAmount total_coinbase_amount
Total cumulative amount of coinbase outputs up to and including this block.
Definition: coinstats.h:63
uint256
256-bit opaque blob.
Definition: uint256.h:126
uint256S
uint256 uint256S(const char *str)
Definition: uint256.h:139
READWRITE
#define READWRITE(...)
Definition: serialize.h:140
node::CCoinsStats::total_unspendables_genesis_block
CAmount total_unspendables_genesis_block
The unspendable coinbase amount from the genesis block.
Definition: coinstats.h:65
MuHash3072::Finalize
void Finalize(uint256 &out) noexcept
Definition: muhash.cpp:313
ser_writedata8
void ser_writedata8(Stream &s, uint8_t obj)
Definition: serialize.h:53
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:264
coins.h
gArgs
ArgsManager gArgs
Definition: system.cpp:87
CDBIterator::Seek
void Seek(const K &key)
Definition: dbwrapper.h:137
CoinStatsIndex::CoinStatsIndex
CoinStatsIndex(size_t n_cache_size, bool f_memory=false, bool f_wipe=false)
Definition: coinstatsindex.cpp:104
CDBWrapper
Definition: dbwrapper.h:176
node::CCoinsStats::total_subsidy
CAmount total_subsidy
Total cumulative amount of block subsidies up to and including this block.
Definition: coinstats.h:55
CBlock
Definition: block.h:62
CBlock::vtx
std::vector< CTransactionRef > vtx
Definition: block.h:66
LOCK
#define LOCK(cs)
Definition: sync.h:226
node::CCoinsStats::total_unspendables_bip30
CAmount total_unspendables_bip30
The two unspendable coinbase outputs total amount caused by BIP30.
Definition: coinstats.h:67
blockstorage.h
ser_writedata32be
void ser_writedata32be(Stream &s, uint32_t obj)
Definition: serialize.h:72
fs::create_directories
static bool create_directories(const std::filesystem::path &p)
Create directory (and if necessary its parents), unless the leaf directory already exists or is a sym...
Definition: fs.h:150
CDBIterator::GetKey
bool GetKey(K &key)
Definition: dbwrapper.h:147
CoinStatsIndex::m_total_unspendables_unclaimed_rewards
CAmount m_total_unspendables_unclaimed_rewards
Definition: coinstatsindex.h:35
Params
const CChainParams & Params()
Return the currently selected parameters.
Definition: chainparams.cpp:561
node::CCoinsStats::total_new_outputs_ex_coinbase_amount
CAmount total_new_outputs_ex_coinbase_amount
Total cumulative amount of outputs created up to and including this block.
Definition: coinstats.h:61
node::GetBogoSize
uint64_t GetBogoSize(const CScript &script_pub_key)
Definition: coinstats.cpp:22
CoinStatsIndex::m_total_unspendables_scripts
CAmount m_total_unspendables_scripts
Definition: coinstatsindex.h:34
serialize.h
CoinStatsIndex::m_total_coinbase_amount
CAmount m_total_coinbase_amount
Definition: coinstatsindex.h:31
CoinStatsIndex::ReverseBlock
bool ReverseBlock(const CBlock &block, const CBlockIndex *pindex)
Definition: coinstatsindex.cpp:384
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
CoinStatsIndex::m_transaction_output_count
uint64_t m_transaction_output_count
Definition: coinstatsindex.h:24
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:49
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition: validation.cpp:138
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:151
CoinStatsIndex::m_total_prevout_spent_amount
CAmount m_total_prevout_spent_amount
Definition: coinstatsindex.h:29
DB_BLOCK_HASH
static constexpr uint8_t DB_BLOCK_HASH
Definition: coinstatsindex.cpp:21
txdb.h
CBlockUndo
Undo information for a CBlock.
Definition: undo.h:63
CDBIterator
Definition: dbwrapper.h:117