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