Bitcoin Core  21.99.0
P2P Digital Currency
txdb.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2020 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 <txdb.h>
7 
8 #include <node/ui_interface.h>
9 #include <pow.h>
10 #include <random.h>
11 #include <shutdown.h>
12 #include <uint256.h>
13 #include <util/system.h>
14 #include <util/translation.h>
15 #include <util/vector.h>
16 
17 #include <stdint.h>
18 
19 static const char DB_COIN = 'C';
20 static const char DB_COINS = 'c';
21 static const char DB_BLOCK_FILES = 'f';
22 static const char DB_BLOCK_INDEX = 'b';
23 
24 static const char DB_BEST_BLOCK = 'B';
25 static const char DB_HEAD_BLOCKS = 'H';
26 static const char DB_FLAG = 'F';
27 static const char DB_REINDEX_FLAG = 'R';
28 static const char DB_LAST_BLOCK = 'l';
29 
30 namespace {
31 
32 struct CoinEntry {
33  COutPoint* outpoint;
34  char key;
35  explicit CoinEntry(const COutPoint* ptr) : outpoint(const_cast<COutPoint*>(ptr)), key(DB_COIN) {}
36 
37  SERIALIZE_METHODS(CoinEntry, obj) { READWRITE(obj.key, obj.outpoint->hash, VARINT(obj.outpoint->n)); }
38 };
39 
40 }
41 
42 CCoinsViewDB::CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, bool fWipe) :
43  m_db(std::make_unique<CDBWrapper>(ldb_path, nCacheSize, fMemory, fWipe, true)),
44  m_ldb_path(ldb_path),
45  m_is_memory(fMemory) { }
46 
47 void CCoinsViewDB::ResizeCache(size_t new_cache_size)
48 {
49  // We can't do this operation with an in-memory DB since we'll lose all the coins upon
50  // reset.
51  if (!m_is_memory) {
52  // Have to do a reset first to get the original `m_db` state to release its
53  // filesystem lock.
54  m_db.reset();
55  m_db = std::make_unique<CDBWrapper>(
56  m_ldb_path, new_cache_size, m_is_memory, /*fWipe*/ false, /*obfuscate*/ true);
57  }
58 }
59 
60 bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const {
61  return m_db->Read(CoinEntry(&outpoint), coin);
62 }
63 
64 bool CCoinsViewDB::HaveCoin(const COutPoint &outpoint) const {
65  return m_db->Exists(CoinEntry(&outpoint));
66 }
67 
69  uint256 hashBestChain;
70  if (!m_db->Read(DB_BEST_BLOCK, hashBestChain))
71  return uint256();
72  return hashBestChain;
73 }
74 
75 std::vector<uint256> CCoinsViewDB::GetHeadBlocks() const {
76  std::vector<uint256> vhashHeadBlocks;
77  if (!m_db->Read(DB_HEAD_BLOCKS, vhashHeadBlocks)) {
78  return std::vector<uint256>();
79  }
80  return vhashHeadBlocks;
81 }
82 
83 bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
84  CDBBatch batch(*m_db);
85  size_t count = 0;
86  size_t changed = 0;
87  size_t batch_size = (size_t)gArgs.GetArg("-dbbatchsize", nDefaultDbBatchSize);
88  int crash_simulate = gArgs.GetArg("-dbcrashratio", 0);
89  assert(!hashBlock.IsNull());
90 
91  uint256 old_tip = GetBestBlock();
92  if (old_tip.IsNull()) {
93  // We may be in the middle of replaying.
94  std::vector<uint256> old_heads = GetHeadBlocks();
95  if (old_heads.size() == 2) {
96  assert(old_heads[0] == hashBlock);
97  old_tip = old_heads[1];
98  }
99  }
100 
101  // In the first batch, mark the database as being in the middle of a
102  // transition from old_tip to hashBlock.
103  // A vector is used for future extensibility, as we may want to support
104  // interrupting after partial writes from multiple independent reorgs.
105  batch.Erase(DB_BEST_BLOCK);
106  batch.Write(DB_HEAD_BLOCKS, Vector(hashBlock, old_tip));
107 
108  for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
109  if (it->second.flags & CCoinsCacheEntry::DIRTY) {
110  CoinEntry entry(&it->first);
111  if (it->second.coin.IsSpent())
112  batch.Erase(entry);
113  else
114  batch.Write(entry, it->second.coin);
115  changed++;
116  }
117  count++;
118  CCoinsMap::iterator itOld = it++;
119  mapCoins.erase(itOld);
120  if (batch.SizeEstimate() > batch_size) {
121  LogPrint(BCLog::COINDB, "Writing partial batch of %.2f MiB\n", batch.SizeEstimate() * (1.0 / 1048576.0));
122  m_db->WriteBatch(batch);
123  batch.Clear();
124  if (crash_simulate) {
125  static FastRandomContext rng;
126  if (rng.randrange(crash_simulate) == 0) {
127  LogPrintf("Simulating a crash. Goodbye.\n");
128  _Exit(0);
129  }
130  }
131  }
132  }
133 
134  // In the last batch, mark the database as consistent with hashBlock again.
135  batch.Erase(DB_HEAD_BLOCKS);
136  batch.Write(DB_BEST_BLOCK, hashBlock);
137 
138  LogPrint(BCLog::COINDB, "Writing final batch of %.2f MiB\n", batch.SizeEstimate() * (1.0 / 1048576.0));
139  bool ret = m_db->WriteBatch(batch);
140  LogPrint(BCLog::COINDB, "Committed %u changed transaction outputs (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
141  return ret;
142 }
143 
145 {
146  return m_db->EstimateSize(DB_COIN, (char)(DB_COIN+1));
147 }
148 
149 CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
150 }
151 
153  return Read(std::make_pair(DB_BLOCK_FILES, nFile), info);
154 }
155 
156 bool CBlockTreeDB::WriteReindexing(bool fReindexing) {
157  if (fReindexing)
158  return Write(DB_REINDEX_FLAG, '1');
159  else
160  return Erase(DB_REINDEX_FLAG);
161 }
162 
163 void CBlockTreeDB::ReadReindexing(bool &fReindexing) {
164  fReindexing = Exists(DB_REINDEX_FLAG);
165 }
166 
168  return Read(DB_LAST_BLOCK, nFile);
169 }
170 
172 {
173  CCoinsViewDBCursor *i = new CCoinsViewDBCursor(const_cast<CDBWrapper&>(*m_db).NewIterator(), GetBestBlock());
174  /* It seems that there are no "const iterators" for LevelDB. Since we
175  only need read operations on it, use a const-cast to get around
176  that restriction. */
177  i->pcursor->Seek(DB_COIN);
178  // Cache key of first record
179  if (i->pcursor->Valid()) {
180  CoinEntry entry(&i->keyTmp.second);
181  i->pcursor->GetKey(entry);
182  i->keyTmp.first = entry.key;
183  } else {
184  i->keyTmp.first = 0; // Make sure Valid() and GetKey() return false
185  }
186  return i;
187 }
188 
190 {
191  // Return cached key
192  if (keyTmp.first == DB_COIN) {
193  key = keyTmp.second;
194  return true;
195  }
196  return false;
197 }
198 
200 {
201  return pcursor->GetValue(coin);
202 }
203 
205 {
206  return pcursor->GetValueSize();
207 }
208 
210 {
211  return keyTmp.first == DB_COIN;
212 }
213 
215 {
216  pcursor->Next();
217  CoinEntry entry(&keyTmp.second);
218  if (!pcursor->Valid() || !pcursor->GetKey(entry)) {
219  keyTmp.first = 0; // Invalidate cached key after last record so that Valid() and GetKey() return false
220  } else {
221  keyTmp.first = entry.key;
222  }
223 }
224 
225 bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo) {
226  CDBBatch batch(*this);
227  for (std::vector<std::pair<int, const CBlockFileInfo*> >::const_iterator it=fileInfo.begin(); it != fileInfo.end(); it++) {
228  batch.Write(std::make_pair(DB_BLOCK_FILES, it->first), *it->second);
229  }
230  batch.Write(DB_LAST_BLOCK, nLastFile);
231  for (std::vector<const CBlockIndex*>::const_iterator it=blockinfo.begin(); it != blockinfo.end(); it++) {
232  batch.Write(std::make_pair(DB_BLOCK_INDEX, (*it)->GetBlockHash()), CDiskBlockIndex(*it));
233  }
234  return WriteBatch(batch, true);
235 }
236 
237 bool CBlockTreeDB::WriteFlag(const std::string &name, bool fValue) {
238  return Write(std::make_pair(DB_FLAG, name), fValue ? '1' : '0');
239 }
240 
241 bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
242  char ch;
243  if (!Read(std::make_pair(DB_FLAG, name), ch))
244  return false;
245  fValue = ch == '1';
246  return true;
247 }
248 
249 bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
250 {
251  std::unique_ptr<CDBIterator> pcursor(NewIterator());
252 
253  pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256()));
254 
255  // Load m_block_index
256  while (pcursor->Valid()) {
257  if (ShutdownRequested()) return false;
258  std::pair<char, uint256> key;
259  if (pcursor->GetKey(key) && key.first == DB_BLOCK_INDEX) {
260  CDiskBlockIndex diskindex;
261  if (pcursor->GetValue(diskindex)) {
262  // Construct block index object
263  CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
264  pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
265  pindexNew->nHeight = diskindex.nHeight;
266  pindexNew->nFile = diskindex.nFile;
267  pindexNew->nDataPos = diskindex.nDataPos;
268  pindexNew->nUndoPos = diskindex.nUndoPos;
269  pindexNew->nVersion = diskindex.nVersion;
270  pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
271  pindexNew->nTime = diskindex.nTime;
272  pindexNew->nBits = diskindex.nBits;
273  pindexNew->nNonce = diskindex.nNonce;
274  pindexNew->nStatus = diskindex.nStatus;
275  pindexNew->nTx = diskindex.nTx;
276 
277  if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, consensusParams))
278  return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
279 
280  pcursor->Next();
281  } else {
282  return error("%s: failed to read value", __func__);
283  }
284  } else {
285  break;
286  }
287  }
288 
289  return true;
290 }
291 
292 namespace {
293 
295 class CCoins
296 {
297 public:
299  bool fCoinBase;
300 
302  std::vector<CTxOut> vout;
303 
305  int nHeight;
306 
308  CCoins() : fCoinBase(false), vout(0), nHeight(0) { }
309 
310  template<typename Stream>
311  void Unserialize(Stream &s) {
312  unsigned int nCode = 0;
313  // version
314  unsigned int nVersionDummy;
315  ::Unserialize(s, VARINT(nVersionDummy));
316  // header code
317  ::Unserialize(s, VARINT(nCode));
318  fCoinBase = nCode & 1;
319  std::vector<bool> vAvail(2, false);
320  vAvail[0] = (nCode & 2) != 0;
321  vAvail[1] = (nCode & 4) != 0;
322  unsigned int nMaskCode = (nCode / 8) + ((nCode & 6) != 0 ? 0 : 1);
323  // spentness bitmask
324  while (nMaskCode > 0) {
325  unsigned char chAvail = 0;
326  ::Unserialize(s, chAvail);
327  for (unsigned int p = 0; p < 8; p++) {
328  bool f = (chAvail & (1 << p)) != 0;
329  vAvail.push_back(f);
330  }
331  if (chAvail != 0)
332  nMaskCode--;
333  }
334  // txouts themself
335  vout.assign(vAvail.size(), CTxOut());
336  for (unsigned int i = 0; i < vAvail.size(); i++) {
337  if (vAvail[i])
338  ::Unserialize(s, Using<TxOutCompression>(vout[i]));
339  }
340  // coinbase height
342  }
343 };
344 
345 }
346 
352  std::unique_ptr<CDBIterator> pcursor(m_db->NewIterator());
353  pcursor->Seek(std::make_pair(DB_COINS, uint256()));
354  if (!pcursor->Valid()) {
355  return true;
356  }
357 
358  int64_t count = 0;
359  LogPrintf("Upgrading utxo-set database...\n");
360  LogPrintf("[0%%]..."); /* Continued */
361  uiInterface.ShowProgress(_("Upgrading UTXO database").translated, 0, true);
362  size_t batch_size = 1 << 24;
363  CDBBatch batch(*m_db);
364  int reportDone = 0;
365  std::pair<unsigned char, uint256> key;
366  std::pair<unsigned char, uint256> prev_key = {DB_COINS, uint256()};
367  while (pcursor->Valid()) {
368  if (ShutdownRequested()) {
369  break;
370  }
371  if (pcursor->GetKey(key) && key.first == DB_COINS) {
372  if (count++ % 256 == 0) {
373  uint32_t high = 0x100 * *key.second.begin() + *(key.second.begin() + 1);
374  int percentageDone = (int)(high * 100.0 / 65536.0 + 0.5);
375  uiInterface.ShowProgress(_("Upgrading UTXO database").translated, percentageDone, true);
376  if (reportDone < percentageDone/10) {
377  // report max. every 10% step
378  LogPrintf("[%d%%]...", percentageDone); /* Continued */
379  reportDone = percentageDone/10;
380  }
381  }
382  CCoins old_coins;
383  if (!pcursor->GetValue(old_coins)) {
384  return error("%s: cannot parse CCoins record", __func__);
385  }
386  COutPoint outpoint(key.second, 0);
387  for (size_t i = 0; i < old_coins.vout.size(); ++i) {
388  if (!old_coins.vout[i].IsNull() && !old_coins.vout[i].scriptPubKey.IsUnspendable()) {
389  Coin newcoin(std::move(old_coins.vout[i]), old_coins.nHeight, old_coins.fCoinBase);
390  outpoint.n = i;
391  CoinEntry entry(&outpoint);
392  batch.Write(entry, newcoin);
393  }
394  }
395  batch.Erase(key);
396  if (batch.SizeEstimate() > batch_size) {
397  m_db->WriteBatch(batch);
398  batch.Clear();
399  m_db->CompactRange(prev_key, key);
400  prev_key = key;
401  }
402  pcursor->Next();
403  } else {
404  break;
405  }
406  }
407  m_db->WriteBatch(batch);
408  m_db->CompactRange({DB_COINS, uint256()}, key);
409  uiInterface.ShowProgress("", 100, false);
410  LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE");
411  return !ShutdownRequested();
412 }
CCoinsViewDB::Cursor
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
Definition: txdb.cpp:171
ShutdownRequested
bool ShutdownRequested()
Returns true if a shutdown is requested, false otherwise.
Definition: shutdown.cpp:87
CCoinsViewDB::Upgrade
bool Upgrade()
Attempt to update from an older database format. Returns whether an error occurred.
Definition: txdb.cpp:351
DB_COIN
static const char DB_COIN
Definition: txdb.cpp:19
_
bilingual_str _(const char *psz)
Translation function.
Definition: translation.h:57
GetDataDir
const fs::path & GetDataDir(bool fNetSpecific)
Definition: system.cpp:770
CBlockIndex::nFile
int nFile
Which # file this block is stored in (blk?????.dat)
Definition: chain.h:153
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:211
count
static int count
Definition: tests.c:35
pow.h
DB_COINS
static const char DB_COINS
Definition: txdb.cpp:20
CBlockIndex::nTime
uint32_t nTime
Definition: chain.h:192
nHeight
unsigned int nHeight
Definition: mempool_eviction.cpp:14
CDBBatch
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:47
CBlockIndex::nTx
unsigned int nTx
Number of transactions in this block.
Definition: chain.h:169
uiInterface
CClientUIInterface uiInterface
Definition: ui_interface.cpp:12
VARINT_MODE
#define VARINT_MODE(obj, mode)
Definition: serialize.h:478
CBlockIndex::nBits
uint32_t nBits
Definition: chain.h:193
uint256.h
CBlockIndex::pprev
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:144
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:150
DB_BEST_BLOCK
static const char DB_BEST_BLOCK
Definition: txdb.cpp:24
CBlockIndex::ToString
std::string ToString() const
Definition: chain.h:286
CCoinsViewDBCursor::GetKey
bool GetKey(COutPoint &key) const override
Definition: txdb.cpp:189
CCoinsViewDB::CCoinsViewDB
CCoinsViewDB(fs::path ldb_path, size_t nCacheSize, bool fMemory, bool fWipe)
Definition: txdb.cpp:42
CheckProofOfWork
bool CheckProofOfWork(uint256 hash, unsigned int nBits, const Consensus::Params &params)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
Definition: pow.cpp:74
VarIntMode::NONNEGATIVE_SIGNED
@ NONNEGATIVE_SIGNED
DB_BLOCK_FILES
static const char DB_BLOCK_FILES
Definition: txdb.cpp:21
CBlockTreeDB::ReadReindexing
void ReadReindexing(bool &fReindexing)
Definition: txdb.cpp:163
CCoinsViewDBCursor
Specialization of CCoinsViewCursor to iterate over a CCoinsViewDB.
Definition: txdb.h:74
CDBWrapper::Read
bool Read(const K &key, V &value) const
Definition: dbwrapper.h:231
CBlockIndex::nDataPos
unsigned int nDataPos
Byte offset within blk?????.dat where this block's data is stored.
Definition: chain.h:156
CDiskBlockIndex
Used to marshal pointers into hashes for db storage.
Definition: chain.h:333
nDefaultDbBatchSize
static const int64_t nDefaultDbBatchSize
-dbbatchsize default (bytes)
Definition: txdb.h:26
shutdown.h
CDBBatch::Write
void Write(const K &key, const V &value)
Definition: dbwrapper.h:73
CCoinsViewCursor
Cursor for iterating over CoinsView state.
Definition: coins.h:139
Consensus::Params
Parameters that influence chain consensus.
Definition: params.h:56
CCoinsViewDB::ResizeCache
void ResizeCache(size_t new_cache_size) EXCLUSIVE_LOCKS_REQUIRED(cs_main)
Dynamically alter the underlying leveldb cache size.
Definition: txdb.cpp:47
random.h
CDBWrapper::NewIterator
CDBIterator * NewIterator()
Definition: dbwrapper.h:296
Unserialize
void Unserialize(Stream &s, char &a)
Definition: serialize.h:245
CBlockIndex::nStatus
uint32_t nStatus
Verification status of this block.
Definition: chain.h:187
CTxOut
An output of a transaction.
Definition: transaction.h:128
CCoinsViewDBCursor::GetValueSize
unsigned int GetValueSize() const override
Definition: txdb.cpp:204
Coin
A UTXO entry.
Definition: coins.h:32
CBlockTreeDB::WriteBatchSync
bool WriteBatchSync(const std::vector< std::pair< int, const CBlockFileInfo * > > &fileInfo, int nLastFile, const std::vector< const CBlockIndex * > &blockinfo)
Definition: txdb.cpp:225
CCoinsViewDB::EstimateSize
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
Definition: txdb.cpp:144
VARINT
#define VARINT(obj)
Definition: serialize.h:479
CCoinsViewDB::HaveCoin
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: txdb.cpp:64
CBlockIndex::nVersion
int32_t nVersion
block header
Definition: chain.h:190
CDBBatch::Clear
void Clear()
Definition: dbwrapper.h:66
CBlockIndex::hashMerkleRoot
uint256 hashMerkleRoot
Definition: chain.h:191
CBlockTreeDB::ReadBlockFileInfo
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &info)
Definition: txdb.cpp:152
CBlockTreeDB::WriteReindexing
bool WriteReindexing(bool fReindexing)
Definition: txdb.cpp:156
CCoinsViewDBCursor::Valid
bool Valid() const override
Definition: txdb.cpp:209
ArgsManager::GetArg
std::string GetArg(const std::string &strArg, const std::string &strDefault) const
Return string argument or default value.
Definition: system.cpp:503
LogPrintf
#define LogPrintf(...)
Definition: logging.h:183
DB_FLAG
static const char DB_FLAG
Definition: txdb.cpp:26
bilingual_str::translated
std::string translated
Definition: translation.h:18
uint256
256-bit opaque blob.
Definition: uint256.h:124
CCoinsViewDBCursor::GetValue
bool GetValue(Coin &coin) const override
Definition: txdb.cpp:199
READWRITE
#define READWRITE(...)
Definition: serialize.h:175
CBlockTreeDB::ReadFlag
bool ReadFlag(const std::string &name, bool &fValue)
Definition: txdb.cpp:241
CDBWrapper::Erase
bool Erase(const K &key, bool fSync=false)
Definition: dbwrapper.h:284
LogPrint
#define LogPrint(category,...)
Definition: logging.h:187
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:246
name
const char * name
Definition: rest.cpp:43
ui_interface.h
CDBWrapper
Definition: dbwrapper.h:176
system.h
CBlockTreeDB::WriteFlag
bool WriteFlag(const std::string &name, bool fValue)
Definition: txdb.cpp:237
CBlockTreeDB::LoadBlockIndexGuts
bool LoadBlockIndexGuts(const Consensus::Params &consensusParams, std::function< CBlockIndex *(const uint256 &)> insertBlockIndex)
Definition: txdb.cpp:249
BCLog::COINDB
@ COINDB
Definition: logging.h:56
CCoinsViewDB::BatchWrite
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: txdb.cpp:83
CCoinsViewDBCursor::keyTmp
std::pair< char, COutPoint > keyTmp
Definition: txdb.h:90
base_blob::IsNull
bool IsNull() const
Definition: uint256.h:31
translation.h
CCoinsViewDB::GetBestBlock
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: txdb.cpp:68
COutPoint::n
uint32_t n
Definition: transaction.h:30
DB_REINDEX_FLAG
static const char DB_REINDEX_FLAG
Definition: txdb.cpp:27
Vector
std::vector< typename std::common_type< Args... >::type > Vector(Args &&... args)
Construct a vector with the specified elements.
Definition: vector.h:20
vector.h
CBlockIndex::nUndoPos
unsigned int nUndoPos
Byte offset within rev?????.dat where this block's undo data is stored.
Definition: chain.h:159
gArgs
ArgsManager gArgs
Definition: system.cpp:79
CBlockFileInfo
Definition: chain.h:40
CCoinsViewDBCursor::Next
void Next() override
Definition: txdb.cpp:214
CDBBatch::Erase
void Erase(const K &key)
Definition: dbwrapper.h:98
CCoinsViewDB::m_is_memory
bool m_is_memory
Definition: txdb.h:51
CBlockIndex::nNonce
uint32_t nNonce
Definition: chain.h:194
CCoinsMap
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
Definition: coins.h:136
CBlockTreeDB::CBlockTreeDB
CBlockTreeDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Definition: txdb.cpp:149
FastRandomContext::randrange
uint64_t randrange(uint64_t range) noexcept
Generate a random integer in the range [0..range).
Definition: random.h:190
CDiskBlockIndex::hashPrev
uint256 hashPrev
Definition: chain.h:336
CDiskBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:367
DB_LAST_BLOCK
static const char DB_LAST_BLOCK
Definition: txdb.cpp:28
CDBWrapper::Write
bool Write(const K &key, const V &value, bool fSync=false)
Definition: dbwrapper.h:257
CDBWrapper::Exists
bool Exists(const K &key) const
Definition: dbwrapper.h:265
DB_BLOCK_INDEX
static const char DB_BLOCK_INDEX
Definition: txdb.cpp:22
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:26
CCoinsViewDB::GetCoin
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: txdb.cpp:60
error
bool error(const char *fmt, const Args &... args)
Definition: system.h:50
CCoinsCacheEntry::DIRTY
@ DIRTY
DIRTY means the CCoinsCacheEntry is potentially different from the version in the parent cache.
Definition: coins.h:118
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:137
CCoinsViewDBCursor::pcursor
std::unique_ptr< CDBIterator > pcursor
Definition: txdb.h:89
CCoinsViewDB::m_ldb_path
fs::path m_ldb_path
Definition: txdb.h:50
CCoinsViewDB::m_db
std::unique_ptr< CDBWrapper > m_db
Definition: txdb.h:49
assert
assert(std::addressof(::ChainstateActive().CoinsTip())==std::addressof(coins_cache))
CDBWrapper::WriteBatch
bool WriteBatch(CDBBatch &batch, bool fSync=false)
Definition: dbwrapper.cpp:183
txdb.h
base_blob::begin
unsigned char * begin()
Definition: uint256.h:58
FastRandomContext
Fast randomness source.
Definition: random.h:119
it
auto it
Definition: validation.cpp:399
DB_HEAD_BLOCKS
static const char DB_HEAD_BLOCKS
Definition: txdb.cpp:25
CDBBatch::SizeEstimate
size_t SizeEstimate() const
Definition: dbwrapper.h:114
CCoinsViewDB::GetHeadBlocks
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
Definition: txdb.cpp:75
CBlockTreeDB::ReadLastBlockFile
bool ReadLastBlockFile(int &nFile)
Definition: txdb.cpp:167