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