Fabcoin Core  0.16.2
P2P Digital Currency
txdb.cpp
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2017 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 <chainparams.h>
9 #include <hash.h>
10 #include <random.h>
11 #include <pow.h>
12 #include <uint256.h>
13 #include <util.h>
14 #include <ui_interface.h>
15 #include <init.h>
16 #include <validation.h>
17 
18 #include <stdint.h>
19 
20 #include <boost/thread.hpp>
21 
22 static const char DB_COIN = 'C';
23 static const char DB_COINS = 'c';
24 static const char DB_BLOCK_FILES = 'f';
25 static const char DB_TXINDEX = 't';
26 static const char DB_BLOCK_INDEX = 'b';
28 static const char DB_HEIGHTINDEX = 'h';
30 
31 static const char DB_BEST_BLOCK = 'B';
32 static const char DB_HEAD_BLOCKS = 'H';
33 static const char DB_FLAG = 'F';
34 static const char DB_REINDEX_FLAG = 'R';
35 static const char DB_LAST_BLOCK = 'l';
36 
37 namespace {
38 
39 struct CoinEntry {
40  COutPoint* outpoint;
41  char key;
42  CoinEntry(const COutPoint* ptr) : outpoint(const_cast<COutPoint*>(ptr)), key(DB_COIN) {}
43 
44  template<typename Stream>
45  void Serialize(Stream &s) const {
46  s << key;
47  s << outpoint->hash;
48  s << VARINT(outpoint->n);
49  }
50 
51  template<typename Stream>
52  void Unserialize(Stream& s) {
53  s >> key;
54  s >> outpoint->hash;
55  s >> VARINT(outpoint->n);
56  }
57 };
58 
59 }
60 
61 CCoinsViewDB::CCoinsViewDB(size_t nCacheSize, bool fMemory, bool fWipe) : db(GetDataDir() / "chainstate", nCacheSize, fMemory, fWipe, true)
62 {
63 }
64 
65 bool CCoinsViewDB::GetCoin(const COutPoint &outpoint, Coin &coin) const {
66  return db.Read(CoinEntry(&outpoint), coin);
67 }
68 
69 bool CCoinsViewDB::HaveCoin(const COutPoint &outpoint) const {
70  return db.Exists(CoinEntry(&outpoint));
71 }
72 
74  uint256 hashBestChain;
75  if (!db.Read(DB_BEST_BLOCK, hashBestChain))
76  return uint256();
77  return hashBestChain;
78 }
79 
80 std::vector<uint256> CCoinsViewDB::GetHeadBlocks() const {
81  std::vector<uint256> vhashHeadBlocks;
82  if (!db.Read(DB_HEAD_BLOCKS, vhashHeadBlocks)) {
83  return std::vector<uint256>();
84  }
85  return vhashHeadBlocks;
86 }
87 
88 bool CCoinsViewDB::BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) {
89  CDBBatch batch(db);
90  size_t count = 0;
91  size_t changed = 0;
92  size_t batch_size = (size_t)gArgs.GetArg("-dbbatchsize", nDefaultDbBatchSize);
93  int crash_simulate = gArgs.GetArg("-dbcrashratio", 0);
94  assert(!hashBlock.IsNull());
95 
96  uint256 old_tip = GetBestBlock();
97  if (old_tip.IsNull()) {
98  // We may be in the middle of replaying.
99  std::vector<uint256> old_heads = GetHeadBlocks();
100  if (old_heads.size() == 2) {
101  assert(old_heads[0] == hashBlock);
102  old_tip = old_heads[1];
103  }
104  }
105 
106  // In the first batch, mark the database as being in the middle of a
107  // transition from old_tip to hashBlock.
108  // A vector is used for future extensibility, as we may want to support
109  // interrupting after partial writes from multiple independent reorgs.
110  batch.Erase(DB_BEST_BLOCK);
111  batch.Write(DB_HEAD_BLOCKS, std::vector<uint256>{hashBlock, old_tip});
112 
113  for (CCoinsMap::iterator it = mapCoins.begin(); it != mapCoins.end();) {
114  if (it->second.flags & CCoinsCacheEntry::DIRTY) {
115  CoinEntry entry(&it->first);
116  if (it->second.coin.IsSpent())
117  batch.Erase(entry);
118  else
119  batch.Write(entry, it->second.coin);
120  changed++;
121  }
122  count++;
123  CCoinsMap::iterator itOld = it++;
124  mapCoins.erase(itOld);
125  if (batch.SizeEstimate() > batch_size) {
126  LogPrint(BCLog::COINDB, "Writing partial batch of %.2f MiB\n", batch.SizeEstimate() * (1.0 / 1048576.0));
127  db.WriteBatch(batch);
128  batch.Clear();
129  if (crash_simulate) {
130  static FastRandomContext rng;
131  if (rng.randrange(crash_simulate) == 0) {
132  LogPrintf("Simulating a crash. Goodbye.\n");
133  _Exit(0);
134  }
135  }
136  }
137  }
138 
139  // In the last batch, mark the database as consistent with hashBlock again.
140  batch.Erase(DB_HEAD_BLOCKS);
141  batch.Write(DB_BEST_BLOCK, hashBlock);
142 
143  LogPrint(BCLog::COINDB, "Writing final batch of %.2f MiB\n", batch.SizeEstimate() * (1.0 / 1048576.0));
144  bool ret = db.WriteBatch(batch);
145  LogPrint(BCLog::COINDB, "Committed %u changed transaction outputs (out of %u) to coin database...\n", (unsigned int)changed, (unsigned int)count);
146  return ret;
147 }
148 
150 {
151  return db.EstimateSize(DB_COIN, (char)(DB_COIN+1));
152 }
153 
154 CBlockTreeDB::CBlockTreeDB(size_t nCacheSize, bool fMemory, bool fWipe) : CDBWrapper(GetDataDir() / "blocks" / "index", nCacheSize, fMemory, fWipe) {
155 }
156 
158  return Read(std::make_pair(DB_BLOCK_FILES, nFile), info);
159 }
160 
161 bool CBlockTreeDB::WriteReindexing(bool fReindexing) {
162  if (fReindexing)
163  return Write(DB_REINDEX_FLAG, '1');
164  else
165  return Erase(DB_REINDEX_FLAG);
166 }
167 
168 bool CBlockTreeDB::ReadReindexing(bool &fReindexing) {
169  fReindexing = Exists(DB_REINDEX_FLAG);
170  return true;
171 }
172 
174  return Read(DB_LAST_BLOCK, nFile);
175 }
176 
178 {
179  CCoinsViewDBCursor *i = new CCoinsViewDBCursor(const_cast<CDBWrapper&>(db).NewIterator(), GetBestBlock());
180  /* It seems that there are no "const iterators" for LevelDB. Since we
181  only need read operations on it, use a const-cast to get around
182  that restriction. */
183  i->pcursor->Seek(DB_COIN);
184  // Cache key of first record
185  if (i->pcursor->Valid()) {
186  CoinEntry entry(&i->keyTmp.second);
187  i->pcursor->GetKey(entry);
188  i->keyTmp.first = entry.key;
189  } else {
190  i->keyTmp.first = 0; // Make sure Valid() and GetKey() return false
191  }
192  return i;
193 }
194 
196 {
197  // Return cached key
198  if (keyTmp.first == DB_COIN) {
199  key = keyTmp.second;
200  return true;
201  }
202  return false;
203 }
204 
206 {
207  return pcursor->GetValue(coin);
208 }
209 
211 {
212  return pcursor->GetValueSize();
213 }
214 
216 {
217  return keyTmp.first == DB_COIN;
218 }
219 
221 {
222  pcursor->Next();
223  CoinEntry entry(&keyTmp.second);
224  if (!pcursor->Valid() || !pcursor->GetKey(entry)) {
225  keyTmp.first = 0; // Invalidate cached key after last record so that Valid() and GetKey() return false
226  } else {
227  keyTmp.first = entry.key;
228  }
229 }
230 
231 bool CBlockTreeDB::WriteBatchSync(const std::vector<std::pair<int, const CBlockFileInfo*> >& fileInfo, int nLastFile, const std::vector<const CBlockIndex*>& blockinfo) {
232  CDBBatch batch(*this);
233  for (std::vector<std::pair<int, const CBlockFileInfo*> >::const_iterator it=fileInfo.begin(); it != fileInfo.end(); it++) {
234  batch.Write(std::make_pair(DB_BLOCK_FILES, it->first), *it->second);
235  }
236  batch.Write(DB_LAST_BLOCK, nLastFile);
237  for (std::vector<const CBlockIndex*>::const_iterator it=blockinfo.begin(); it != blockinfo.end(); it++) {
238  batch.Write(std::make_pair(DB_BLOCK_INDEX, (*it)->GetBlockHash()), CDiskBlockIndex(*it));
239  }
240  return WriteBatch(batch, true);
241 }
242 
244  return Read(std::make_pair(DB_TXINDEX, txid), pos);
245 }
246 
247 bool CBlockTreeDB::WriteTxIndex(const std::vector<std::pair<uint256, CDiskTxPos> >&vect) {
248  CDBBatch batch(*this);
249  for (std::vector<std::pair<uint256,CDiskTxPos> >::const_iterator it=vect.begin(); it!=vect.end(); it++)
250  batch.Write(std::make_pair(DB_TXINDEX, it->first), it->second);
251  return WriteBatch(batch);
252 }
253 
254 bool CBlockTreeDB::WriteFlag(const std::string &name, bool fValue) {
255  return Write(std::make_pair(DB_FLAG, name), fValue ? '1' : '0');
256 }
257 
258 bool CBlockTreeDB::ReadFlag(const std::string &name, bool &fValue) {
259  char ch;
260  if (!Read(std::make_pair(DB_FLAG, name), ch))
261  return false;
262  fValue = ch == '1';
263  return true;
264 }
265 
267 bool CBlockTreeDB::WriteHeightIndex(const CHeightTxIndexKey &heightIndex, const std::vector<uint256>& hash) {
268  CDBBatch batch(*this);
269  batch.Write(std::make_pair(DB_HEIGHTINDEX, heightIndex), hash);
270  return WriteBatch(batch);
271 }
272 
273 int CBlockTreeDB::ReadHeightIndex(int low, int high, int minconf,
274  std::vector<std::vector<uint256>> &blocksOfHashes,
275  std::set<dev::h160> const &addresses) {
276 
277  if ((high < low && high > -1) || (high == 0 && low == 0) || (high < -1 || low < 0)) {
278  return -1;
279  }
280 
281  std::unique_ptr<CDBIterator> pcursor(NewIterator());
282 
283  pcursor->Seek(std::make_pair(DB_HEIGHTINDEX, CHeightTxIndexIteratorKey(low)));
284 
285  int curheight = 0;
286 
287  for (size_t count = 0; pcursor->Valid(); pcursor->Next()) {
288 
289  std::pair<char, CHeightTxIndexKey> key;
290  if (!pcursor->GetKey(key) || key.first != DB_HEIGHTINDEX) {
291  break;
292  }
293 
294  int nextHeight = key.second.height;
295 
296  if (high > -1 && nextHeight > high) {
297  break;
298  }
299 
300  if (minconf > 0) {
301  int conf = chainActive.Height() - nextHeight;
302  if (conf < minconf) {
303  break;
304  }
305  }
306 
307  curheight = nextHeight;
308 
309  auto address = key.second.address;
310  if (!addresses.empty() && addresses.find(address) == addresses.end()) {
311  continue;
312  }
313 
314  std::vector<uint256> hashesTx;
315 
316  if (!pcursor->GetValue(hashesTx)) {
317  break;
318  }
319 
320  count += hashesTx.size();
321 
322  blocksOfHashes.push_back(hashesTx);
323  }
324 
325  return curheight;
326 }
327 
328 bool CBlockTreeDB::EraseHeightIndex(const unsigned int &height) {
329 
330  boost::scoped_ptr<CDBIterator> pcursor(NewIterator());
331  CDBBatch batch(*this);
332 
333  pcursor->Seek(std::make_pair(DB_HEIGHTINDEX, CHeightTxIndexIteratorKey(height)));
334 
335  while (pcursor->Valid()) {
336  boost::this_thread::interruption_point();
337  std::pair<char, CHeightTxIndexKey> key;
338  if (pcursor->GetKey(key) && key.first == DB_HEIGHTINDEX && key.second.height == height) {
339  batch.Erase(key);
340  pcursor->Next();
341  } else {
342  break;
343  }
344  }
345 
346  return WriteBatch(batch);
347 }
348 
350 
351  boost::scoped_ptr<CDBIterator> pcursor(NewIterator());
352  CDBBatch batch(*this);
353 
354  pcursor->Seek(DB_HEIGHTINDEX);
355 
356  while (pcursor->Valid()) {
357  boost::this_thread::interruption_point();
358  std::pair<char, CHeightTxIndexKey> key;
359  if (pcursor->GetKey(key) && key.first == DB_HEIGHTINDEX) {
360  batch.Erase(key);
361  pcursor->Next();
362  } else {
363  break;
364  }
365  }
366 
367  return WriteBatch(batch);
368 }
370 bool CBlockTreeDB::LoadBlockIndexGuts(const Consensus::Params& consensusParams, std::function<CBlockIndex*(const uint256&)> insertBlockIndex)
371 {
372  std::unique_ptr<CDBIterator> pcursor(NewIterator());
373 
374  pcursor->Seek(std::make_pair(DB_BLOCK_INDEX, uint256()));
375 
376  // Load mapBlockIndex
377  while (pcursor->Valid()) {
378  boost::this_thread::interruption_point();
379  std::pair<char, uint256> key;
380  if (pcursor->GetKey(key) && key.first == DB_BLOCK_INDEX) {
381  CDiskBlockIndex diskindex;
382  if (pcursor->GetValue(diskindex)) {
383  // Construct block index object
384  CBlockIndex* pindexNew = insertBlockIndex(diskindex.GetBlockHash());
385  pindexNew->pprev = insertBlockIndex(diskindex.hashPrev);
386  pindexNew->nHeight = diskindex.nHeight;
387  pindexNew->nFile = diskindex.nFile;
388  pindexNew->nDataPos = diskindex.nDataPos;
389  pindexNew->nUndoPos = diskindex.nUndoPos;
390  pindexNew->nVersion = diskindex.nVersion;
391  pindexNew->hashMerkleRoot = diskindex.hashMerkleRoot;
392  memcpy(pindexNew->nReserved, diskindex.nReserved, sizeof(pindexNew->nReserved));
393  pindexNew->nTime = diskindex.nTime;
394  pindexNew->nBits = diskindex.nBits;
395  pindexNew->nNonce = diskindex.nNonce;
396  pindexNew->nSolution = diskindex.nSolution;
397  pindexNew->nStatus = diskindex.nStatus;
398  pindexNew->nTx = diskindex.nTx;
399  pindexNew->hashStateRoot = diskindex.hashStateRoot;
400  pindexNew->hashUTXORoot = diskindex.hashUTXORoot;
401 
402  // TODO(h4x3rotab): Check Equihash solution? Not sure why Zcash doesn't do it here.
403  bool postfork = (uint32_t)pindexNew->nHeight >= (uint32_t)consensusParams.FABHeight;
404  if (!CheckProofOfWork(pindexNew->GetBlockHash(), pindexNew->nBits, postfork, consensusParams))
405  return error("%s: CheckProofOfWork failed: %s", __func__, pindexNew->ToString());
406 
407  pcursor->Next();
408  } else {
409  return error("%s: failed to read value", __func__);
410  }
411  } else {
412  break;
413  }
414  }
415 
416  return true;
417 }
418 
419 namespace {
420 
422 class CCoins
423 {
424 public:
426  bool fCoinBase;
427 
429  std::vector<CTxOut> vout;
430 
432  int nHeight;
433 
435  CCoins() : fCoinBase(false), vout(0), nHeight(0) { }
436 
437  template<typename Stream>
438  void Unserialize(Stream &s) {
439  unsigned int nCode = 0;
440  // version
441  int nVersionDummy;
442  ::Unserialize(s, VARINT(nVersionDummy));
443  // header code
444  ::Unserialize(s, VARINT(nCode));
445  fCoinBase = nCode & 1;
446  std::vector<bool> vAvail(2, false);
447  vAvail[0] = (nCode & 2) != 0;
448  vAvail[1] = (nCode & 4) != 0;
449  unsigned int nMaskCode = (nCode / 8) + ((nCode & 6) != 0 ? 0 : 1);
450  // spentness bitmask
451  while (nMaskCode > 0) {
452  unsigned char chAvail = 0;
453  ::Unserialize(s, chAvail);
454  for (unsigned int p = 0; p < 8; p++) {
455  bool f = (chAvail & (1 << p)) != 0;
456  vAvail.push_back(f);
457  }
458  if (chAvail != 0)
459  nMaskCode--;
460  }
461  // txouts themself
462  vout.assign(vAvail.size(), CTxOut());
463  for (unsigned int i = 0; i < vAvail.size(); i++) {
464  if (vAvail[i])
465  ::Unserialize(s, REF(CTxOutCompressor(vout[i])));
466  }
467  // coinbase height
468  ::Unserialize(s, VARINT(nHeight));
469  }
470 };
471 
472 }
473 
479  std::unique_ptr<CDBIterator> pcursor(db.NewIterator());
480  pcursor->Seek(std::make_pair(DB_COINS, uint256()));
481  if (!pcursor->Valid()) {
482  return true;
483  }
484 
485  int64_t count = 0;
486  LogPrintf("Upgrading utxo-set database...\n");
487  LogPrintf("[0%%]...");
488  size_t batch_size = 1 << 24;
489  CDBBatch batch(db);
491  int reportDone = 0;
492  std::pair<unsigned char, uint256> key;
493  std::pair<unsigned char, uint256> prev_key = {DB_COINS, uint256()};
494  while (pcursor->Valid()) {
495  boost::this_thread::interruption_point();
496  if (ShutdownRequested()) {
497  break;
498  }
499  if (pcursor->GetKey(key) && key.first == DB_COINS) {
500  if (count++ % 256 == 0) {
501  uint32_t high = 0x100 * *key.second.begin() + *(key.second.begin() + 1);
502  int percentageDone = (int)(high * 100.0 / 65536.0 + 0.5);
503  uiInterface.ShowProgress(_("Upgrading UTXO database") + "\n"+ _("(press q to shutdown and continue later)") + "\n", percentageDone);
504  if (reportDone < percentageDone/10) {
505  // report max. every 10% step
506  LogPrintf("[%d%%]...", percentageDone);
507  reportDone = percentageDone/10;
508  }
509  }
510  CCoins old_coins;
511  if (!pcursor->GetValue(old_coins)) {
512  return error("%s: cannot parse CCoins record", __func__);
513  }
514  COutPoint outpoint(key.second, 0);
515  for (size_t i = 0; i < old_coins.vout.size(); ++i) {
516  if (!old_coins.vout[i].IsNull() && !old_coins.vout[i].scriptPubKey.IsUnspendable()) {
517  Coin newcoin(std::move(old_coins.vout[i]), old_coins.nHeight, old_coins.fCoinBase);
518  outpoint.n = i;
519  CoinEntry entry(&outpoint);
520  batch.Write(entry, newcoin);
521  }
522  }
523  batch.Erase(key);
524  if (batch.SizeEstimate() > batch_size) {
525  db.WriteBatch(batch);
526  batch.Clear();
527  db.CompactRange(prev_key, key);
528  prev_key = key;
529  }
530  pcursor->Next();
531  } else {
532  break;
533  }
534  }
535  db.WriteBatch(batch);
536  db.CompactRange({DB_COINS, uint256()}, key);
538  LogPrintf("[%s].\n", ShutdownRequested() ? "CANCELLED" : "DONE");
539  return !ShutdownRequested();
540 }
bool GetValue(Coin &coin) const override
Definition: txdb.cpp:205
bool GetCoin(const COutPoint &outpoint, Coin &coin) const override
Retrieve the Coin (unspent transaction output) for a given outpoint.
Definition: txdb.cpp:65
#define VARINT(obj)
Definition: serialize.h:389
bool error(const char *fmt, const Args &...args)
Definition: util.h:178
void Clear()
Definition: dbwrapper.h:66
#define function(a, b, c, d, k, s)
bool Upgrade()
Attempt to update from an older database format. Returns whether an error occurred.
Definition: txdb.cpp:478
Specialization of CCoinsViewCursor to iterate over a CCoinsViewDB.
Definition: txdb.h:94
bool EraseHeightIndex(const unsigned int &height)
Definition: txdb.cpp:328
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:184
Batch of changes queued to be written to a CDBWrapper.
Definition: dbwrapper.h:47
A UTXO entry.
Definition: coins.h:29
bool ShutdownRequested()
Definition: init.cpp:126
bool ReadReindexing(bool &fReindex)
Definition: txdb.cpp:168
bool ReadLastBlockFile(int &nFile)
Definition: txdb.cpp:173
wrapper for CTxOut that provides a more compact serialization
Definition: compressor.h:93
size_t count
Definition: ExecStats.cpp:37
void Erase(const K &key)
Definition: dbwrapper.h:98
void StartShutdown()
Definition: init.cpp:122
size_t SizeEstimate() const
Definition: dbwrapper.h:114
std::unique_ptr< CDBIterator > pcursor
Definition: txdb.h:109
uint64_t randrange(uint64_t range)
Generate a random integer in the range [0..range).
Definition: random.h:103
std::string ToString() const
Definition: chain.h:370
assert(len-trim+(2 *lenIndices)<=WIDTH)
int nFile
Which # file this block is stored in (blk?????.dat)
Definition: chain.h:196
bool GetKey(COutPoint &key) const override
Definition: txdb.cpp:195
bool WipeHeightIndex()
Definition: txdb.cpp:349
uint32_t FABHeight
Block height at which Fabcoin Equihash hard fork becomes active.
Definition: params.h:52
CDBIterator * NewIterator()
Definition: dbwrapper.h:299
Definition: coins.h:109
void Serialize(Stream &s, char a)
Definition: serialize.h:198
int Height() const
Return the maximal height in the chain.
Definition: chain.h:543
unsigned int nTime
Definition: chain.h:223
#define LogPrintf(...)
Definition: util.h:153
bool CheckProofOfWork(uint256 hash, unsigned int nBits, bool postfork, const Consensus::Params &params)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
Definition: pow.cpp:290
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
Definition: chain.h:217
bool Erase(const K &key, bool fSync=false)
Definition: dbwrapper.h:278
unsigned int nDataPos
Byte offset within blk?????.dat where this block&#39;s data is stored.
Definition: chain.h:199
bool IsNull() const
Definition: uint256.h:38
const char * name
Definition: rest.cpp:36
uint256 GetBlockHash() const
Definition: chain.h:470
bool WriteBatchSync(const std::vector< std::pair< int, const CBlockFileInfo * > > &fileInfo, int nLastFile, const std::vector< const CBlockIndex * > &blockinfo)
Definition: txdb.cpp:231
Fast randomness source.
Definition: random.h:44
size_t EstimateSize(const K &key_begin, const K &key_end) const
Definition: dbwrapper.h:310
uint32_t n
Definition: transaction.h:22
CDBWrapper db
Definition: txdb.h:77
std::unordered_map< COutPoint, CCoinsCacheEntry, SaltedOutpointHasher > CCoinsMap
Definition: coins.h:122
boost::signals2::signal< void(const std::string &title, int nProgress)> ShowProgress
Show progress e.g.
Definition: ui_interface.h:98
unsigned int nBits
Definition: chain.h:224
uint256 hashMerkleRoot
Definition: chain.h:221
void Write(const K &key, const V &value)
Definition: dbwrapper.h:73
An output of a transaction.
Definition: transaction.h:131
Used to marshal pointers into hashes for db storage.
Definition: chain.h:418
CChain chainActive
The currently-connected chain of blocks (protected by cs_main).
Definition: validation.cpp:80
size_t EstimateSize() const override
Estimate database size (0 if not implemented)
Definition: txdb.cpp:149
Parameters that influence chain consensus.
Definition: params.h:39
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:18
std::pair< char, COutPoint > keyTmp
Definition: txdb.h:110
bool HaveCoin(const COutPoint &outpoint) const override
Just check whether a given outpoint is unspent.
Definition: txdb.cpp:69
bool ReadFlag(const std::string &name, bool &fValue)
Definition: txdb.cpp:258
CBlockTreeDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Definition: txdb.cpp:154
bool ReadBlockFileInfo(int nFile, CBlockFileInfo &fileinfo)
Definition: txdb.cpp:157
bool ReadTxIndex(const uint256 &txid, CDiskTxPos &pos)
Definition: txdb.cpp:243
int nVersion
block header
Definition: chain.h:220
CCoinsViewDB(size_t nCacheSize, bool fMemory=false, bool fWipe=false)
Definition: txdb.cpp:61
unsigned int nUndoPos
Byte offset within rev?????.dat where this block&#39;s undo data is stored.
Definition: chain.h:202
uint256 GetBestBlock() const override
Retrieve the block hash whose state this CCoinsView currently represents.
Definition: txdb.cpp:73
#define LogPrint(category,...)
Definition: util.h:164
#define f(x)
Definition: gost.cpp:57
256-bit opaque blob.
Definition: uint256.h:132
uint256 hashPrev
Definition: chain.h:421
bool Write(const K &key, const V &value, bool fSync=false)
Definition: dbwrapper.h:251
ArgsManager gArgs
Definition: util.cpp:94
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: chain.h:177
std::string GetArg(const std::string &strArg, const std::string &strDefault)
Return string argument or default value.
Definition: util.cpp:504
void * memcpy(void *a, const void *b, size_t c)
boost::signals2::signal< void(std::function< void(void)> action)> SetProgressBreakAction
Set progress break action (possible "cancel button" triggers that action)
Definition: ui_interface.h:101
bool WriteTxIndex(const std::vector< std::pair< uint256, CDiskTxPos > > &list)
Definition: txdb.cpp:247
uint256 hashUTXORoot
Definition: chain.h:227
void Unserialize(Stream &s, char &a)
Definition: serialize.h:210
bool WriteReindexing(bool fReindex)
Definition: txdb.cpp:161
bool LoadBlockIndexGuts(const Consensus::Params &consensusParams, std::function< CBlockIndex *(const uint256 &)> insertBlockIndex)
Definition: txdb.cpp:370
bool WriteFlag(const std::string &name, bool fValue)
Definition: txdb.cpp:254
bool Exists(const K &key) const
Definition: dbwrapper.h:259
uint32_t nReserved[7]
Definition: chain.h:222
bool Read(const K &key, V &value) const
Definition: dbwrapper.h:225
bool BatchWrite(CCoinsMap &mapCoins, const uint256 &hashBlock) override
Do a bulk modification (multiple Coin changes + BestBlock change).
Definition: txdb.cpp:88
void Next() override
Definition: txdb.cpp:220
const fs::path & GetDataDir(bool fNetSpecific)
Definition: util.cpp:623
CCoinsViewCursor * Cursor() const override
Get a cursor to iterate over the whole state.
Definition: txdb.cpp:177
bool WriteBatch(CDBBatch &batch, bool fSync=false)
Definition: dbwrapper.cpp:158
struct evm_uint160be address(struct evm_env *env)
Definition: capi.c:13
bool Valid() const override
Definition: txdb.cpp:215
CClientUIInterface uiInterface
Definition: ui_interface.cpp:8
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:193
bool WriteHeightIndex(const CHeightTxIndexKey &heightIndex, const std::vector< uint256 > &hash)
Definition: txdb.cpp:267
uint256 hashStateRoot
Definition: chain.h:226
uint32_t ch(uint32_t x, uint32_t y, uint32_t z)
Definition: picosha2.h:73
unsigned int GetValueSize() const override
Definition: txdb.cpp:210
T & REF(const T &val)
Used to bypass the rule against non-const reference to temporary where it makes sense with wrappers s...
Definition: serialize.h:49
uint256 nNonce
Definition: chain.h:225
std::vector< uint256 > GetHeadBlocks() const override
Retrieve the range of blocks that may have been only partially written.
Definition: txdb.cpp:80
int ReadHeightIndex(int low, int high, int minconf, std::vector< std::vector< uint256 >> &blocksOfHashes, std::set< dev::h160 > const &addresses)
Iterates through blocks by height, starting from low.
Definition: txdb.cpp:273
unsigned int nTx
Number of transactions in this block.
Definition: chain.h:209
std::vector< unsigned char > nSolution
Definition: chain.h:229
std::string _(const char *psz)
Translation function: Call Translate signal on UI interface, which returns a boost::optional result...
Definition: util.h:71
uint256 GetBlockHash() const
Definition: chain.h:324
uint256 hash
Definition: transaction.h:21
Cursor for iterating over CoinsView state.
Definition: coins.h:125