Feathercoin  0.5.0
P2P Digital Currency
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
main.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2012 The Bitcoin developers
3 // Distributed under the MIT/X11 software license, see the accompanying
4 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 #ifndef BITCOIN_MAIN_H
6 #define BITCOIN_MAIN_H
7 
8 #include "bignum.h"
9 #include "sync.h"
10 #include "net.h"
11 #include "script.h"
12 #include "scrypt.h"
13 
14 #include <list>
15 
16 class CWallet;
17 class CBlock;
18 class CBlockIndex;
19 class CKeyItem;
20 class CReserveKey;
21 
22 class CAddress;
23 class CInv;
24 class CNode;
25 
27 
29 static const unsigned int MAX_BLOCK_SIZE = 1000000; // 1000KB block hard limit
31 static const unsigned int MAX_BLOCK_SIZE_GEN = MAX_BLOCK_SIZE/4; // 250KB block soft limit
33 static const unsigned int DEFAULT_BLOCK_MAX_SIZE = 250000;
35 static const unsigned int DEFAULT_BLOCK_PRIORITY_SIZE = 17000;
37 static const unsigned int MAX_STANDARD_TX_SIZE = 100000;
39 static const unsigned int MAX_BLOCK_SIGOPS = MAX_BLOCK_SIZE/50;
41 static const unsigned int MAX_ORPHAN_TRANSACTIONS = MAX_BLOCK_SIZE/100;
43 static const unsigned int MAX_INV_SZ = 50000;
45 static const unsigned int MAX_BLOCKFILE_SIZE = 0x8000000; // 128 MiB
47 static const unsigned int BLOCKFILE_CHUNK_SIZE = 0x1000000; // 16 MiB
49 static const unsigned int UNDOFILE_CHUNK_SIZE = 0x100000; // 1 MiB
51 static const unsigned int MEMPOOL_HEIGHT = 0x7FFFFFFF;
53 static const int64 DUST_SOFT_LIMIT = 100000; // 0.001 FTC
55 static const int64 DUST_HARD_LIMIT = 1000; // 0.00001 FTC mininput
57 static const int64 MAX_MONEY = 336000000 * COIN;
58 inline bool MoneyRange(int64 nValue) { return (nValue >= 0 && nValue <= MAX_MONEY); }
60 static const int COINBASE_MATURITY = 100;
62 static const unsigned int LOCKTIME_THRESHOLD = 500000000; // Tue Nov 5 00:53:20 1985 UTC
64 static const int MAX_SCRIPTCHECK_THREADS = 16;
65 #ifdef USE_UPNP
66 static const int fHaveUPnP = true;
67 #else
68 static const int fHaveUPnP = false;
69 #endif
70 
71 
72 extern CScript COINBASE_FLAGS;
73 
74 
75 
76 
77 
78 
80 extern std::map<uint256, CBlockIndex*> mapBlockIndex;
81 extern std::set<CBlockIndex*, CBlockIndexWorkComparator> setBlockIndexValid;
84 extern int nBestHeight;
85 extern uint256 nBestChainWork;
87 extern uint256 hashBestChain;
88 extern CBlockIndex* pindexBest;
89 extern unsigned int nTransactionsUpdated;
90 extern uint64 nLastBlockTx;
91 extern uint64 nLastBlockSize;
92 extern const std::string strMessageMagic;
93 extern double dHashesPerSec;
94 extern int64 nHPSTimerStart;
97 extern std::set<CWallet*> setpwalletRegistered;
98 extern std::map<uint256, CBlock*> mapOrphanBlocks;
99 extern unsigned char pchMessageStart[4];
100 extern bool fImporting;
101 extern bool fReindex;
102 extern bool fBenchmark;
103 extern int nScriptCheckThreads;
104 extern bool fTxIndex;
105 extern unsigned int nCoinCacheSize;
106 
107 // Settings
108 extern int64 nTransactionFee;
110 
111 // Minimum disk space required - used in CheckDiskSpace()
112 static const uint64 nMinDiskSpace = 52428800;
113 
114 
115 class CReserveKey;
116 class CCoinsDB;
117 class CBlockTreeDB;
118 struct CDiskBlockPos;
119 class CCoins;
120 class CTxUndo;
121 class CCoinsView;
122 class CCoinsViewCache;
123 class CScriptCheck;
124 class CValidationState;
125 
126 struct CBlockTemplate;
127 
129 void RegisterWallet(CWallet* pwalletIn);
131 void UnregisterWallet(CWallet* pwalletIn);
133 void SyncWithWallets(const uint256 &hash, const CTransaction& tx, const CBlock* pblock = NULL, bool fUpdate = false);
135 bool ProcessBlock(CValidationState &state, CNode* pfrom, CBlock* pblock, CDiskBlockPos *dbp = NULL);
137 bool CheckDiskSpace(uint64 nAdditionalBytes = 0);
139 FILE* OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly = false);
141 FILE* OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly = false);
143 bool LoadExternalBlockFile(FILE* fileIn, CDiskBlockPos *dbp = NULL);
145 bool InitBlockIndex();
147 bool LoadBlockIndex();
149 void UnloadBlockIndex();
151 bool VerifyDB(int nCheckLevel, int nCheckDepth);
153 void PrintBlockTree();
155 CBlockIndex* FindBlockByHeight(int nHeight);
157 bool ProcessMessages(CNode* pfrom);
159 bool SendMessages(CNode* pto, bool fSendTrickle);
161 void ThreadScriptCheck();
163 void GenerateBitcoins(bool fGenerate, CWallet* pwallet);
165 CBlockTemplate* CreateNewBlock(const CScript& scriptPubKeyIn);
168 void IncrementExtraNonce(CBlock* pblock, CBlockIndex* pindexPrev, unsigned int& nExtraNonce);
170 void FormatHashBuffers(CBlock* pblock, char* pmidstate, char* pdata, char* phash1);
172 bool CheckWork(CBlock* pblock, CWallet& wallet, CReserveKey& reservekey);
174 bool CheckProofOfWork(uint256 hash, unsigned int nBits);
176 unsigned int ComputeMinWork(unsigned int nBase, int64 nTime);
178 int GetNumBlocksOfPeers();
182 std::string GetWarnings(std::string strFor);
184 bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow = false);
192 bool VerifySignature(const CCoins& txFrom, const CTransaction& txTo, unsigned int nIn, unsigned int flags, int nHashType);
194 bool AbortNode(const std::string &msg);
195 
196 
197 
198 
199 
200 
201 
202 
203 
204 
205 
206 bool GetWalletFile(CWallet* pwallet, std::string &strWalletFileOut);
207 
209 {
210  int nFile;
211  unsigned int nPos;
212 
214  READWRITE(VARINT(nFile));
215  READWRITE(VARINT(nPos));
216  )
217 
218  CDiskBlockPos() {
219  SetNull();
220  }
221 
222  CDiskBlockPos(int nFileIn, unsigned int nPosIn) {
223  nFile = nFileIn;
224  nPos = nPosIn;
225  }
226 
227  friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b) {
228  return (a.nFile == b.nFile && a.nPos == b.nPos);
229  }
230 
231  friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b) {
232  return !(a == b);
233  }
234 
235  void SetNull() { nFile = -1; nPos = 0; }
236  bool IsNull() const { return (nFile == -1); }
237 };
238 
239 struct CDiskTxPos : public CDiskBlockPos
240 {
241  unsigned int nTxOffset; // after header
242 
244  READWRITE(*(CDiskBlockPos*)this);
245  READWRITE(VARINT(nTxOffset));
246  )
247 
248  CDiskTxPos(const CDiskBlockPos &blockIn, unsigned int nTxOffsetIn) : CDiskBlockPos(blockIn.nFile, blockIn.nPos), nTxOffset(nTxOffsetIn) {
249  }
250 
252  SetNull();
253  }
254 
255  void SetNull() {
257  nTxOffset = 0;
258  }
259 };
260 
261 
263 class CInPoint
264 {
265 public:
267  unsigned int n;
268 
269  CInPoint() { SetNull(); }
270  CInPoint(CTransaction* ptxIn, unsigned int nIn) { ptx = ptxIn; n = nIn; }
271  void SetNull() { ptx = NULL; n = (unsigned int) -1; }
272  bool IsNull() const { return (ptx == NULL && n == (unsigned int) -1); }
273 };
274 
275 
276 
279 {
280 public:
282  unsigned int n;
283 
284  COutPoint() { SetNull(); }
285  COutPoint(uint256 hashIn, unsigned int nIn) { hash = hashIn; n = nIn; }
287  void SetNull() { hash = 0; n = (unsigned int) -1; }
288  bool IsNull() const { return (hash == 0 && n == (unsigned int) -1); }
289 
290  friend bool operator<(const COutPoint& a, const COutPoint& b)
291  {
292  return (a.hash < b.hash || (a.hash == b.hash && a.n < b.n));
293  }
294 
295  friend bool operator==(const COutPoint& a, const COutPoint& b)
296  {
297  return (a.hash == b.hash && a.n == b.n);
298  }
299 
300  friend bool operator!=(const COutPoint& a, const COutPoint& b)
301  {
302  return !(a == b);
303  }
304 
305  std::string ToString() const
306  {
307  return strprintf("COutPoint(%s, %u)", hash.ToString().c_str(), n);
308  }
309 
310  void print() const
311  {
312  printf("%s\n", ToString().c_str());
313  }
314 };
315 
316 
317 
318 
323 class CTxIn
324 {
325 public:
328  unsigned int nSequence;
329 
331  {
332  nSequence = std::numeric_limits<unsigned int>::max();
333  }
334 
335  explicit CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max())
336  {
337  prevout = prevoutIn;
338  scriptSig = scriptSigIn;
339  nSequence = nSequenceIn;
340  }
341 
342  CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits<unsigned int>::max())
343  {
344  prevout = COutPoint(hashPrevTx, nOut);
345  scriptSig = scriptSigIn;
346  nSequence = nSequenceIn;
347  }
348 
350  (
351  READWRITE(prevout);
352  READWRITE(scriptSig);
353  READWRITE(nSequence);
354  )
355 
356  bool IsFinal() const
357  {
358  return (nSequence == std::numeric_limits<unsigned int>::max());
359  }
360 
361  friend bool operator==(const CTxIn& a, const CTxIn& b)
362  {
363  return (a.prevout == b.prevout &&
364  a.scriptSig == b.scriptSig &&
365  a.nSequence == b.nSequence);
366  }
367 
368  friend bool operator!=(const CTxIn& a, const CTxIn& b)
369  {
370  return !(a == b);
371  }
372 
373  std::string ToString() const
374  {
375  std::string str;
376  str += "CTxIn(";
377  str += prevout.ToString();
378  if (prevout.IsNull())
379  str += strprintf(", coinbase %s", HexStr(scriptSig).c_str());
380  else
381  str += strprintf(", scriptSig=%s", scriptSig.ToString().substr(0,24).c_str());
382  if (nSequence != std::numeric_limits<unsigned int>::max())
383  str += strprintf(", nSequence=%u", nSequence);
384  str += ")";
385  return str;
386  }
387 
388  void print() const
389  {
390  printf("%s\n", ToString().c_str());
391  }
392 };
393 
394 
395 
396 
400 class CTxOut
401 {
402 public:
405 
407  {
408  SetNull();
409  }
410 
411  CTxOut(int64 nValueIn, CScript scriptPubKeyIn)
412  {
413  nValue = nValueIn;
414  scriptPubKey = scriptPubKeyIn;
415  }
416 
418  (
419  READWRITE(nValue);
420  READWRITE(scriptPubKey);
421  )
422 
423  void SetNull()
424  {
425  nValue = -1;
426  scriptPubKey.clear();
427  }
428 
429  bool IsNull() const
430  {
431  return (nValue == -1);
432  }
433 
434  uint256 GetHash() const
435  {
436  return SerializeHash(*this);
437  }
438 
439  friend bool operator==(const CTxOut& a, const CTxOut& b)
440  {
441  return (a.nValue == b.nValue &&
442  a.scriptPubKey == b.scriptPubKey);
443  }
444 
445  friend bool operator!=(const CTxOut& a, const CTxOut& b)
446  {
447  return !(a == b);
448  }
449 
450  bool IsDust() const;
451 
452  std::string ToString() const
453  {
454  if (scriptPubKey.size() < 6)
455  return "CTxOut(error)";
456  return strprintf("CTxOut(nValue=%"PRI64d".%08"PRI64d", scriptPubKey=%s)", nValue / COIN, nValue % COIN, scriptPubKey.ToString().substr(0,30).c_str());
457  }
458 
459  void print() const
460  {
461  printf("%s\n", ToString().c_str());
462  }
463 };
464 
465 
466 
468 {
472 };
473 
478 {
479 public:
480  static int64 nMinTxFee;
482  static const int CURRENT_VERSION=1;
483  int nVersion;
484  std::vector<CTxIn> vin;
485  std::vector<CTxOut> vout;
486  unsigned int nLockTime;
487 
489  {
490  SetNull();
491  }
492 
494  (
495  READWRITE(this->nVersion);
496  nVersion = this->nVersion;
497  READWRITE(vin);
498  READWRITE(vout);
499  READWRITE(nLockTime);
500  )
501 
502  void SetNull()
503  {
505  vin.clear();
506  vout.clear();
507  nLockTime = 0;
508  }
509 
510  bool IsNull() const
511  {
512  return (vin.empty() && vout.empty());
513  }
514 
515  uint256 GetHash() const
516  {
517  return SerializeHash(*this);
518  }
519 
520  bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const
521  {
522  // Time based nLockTime implemented in 0.1.6
523  if (nLockTime == 0)
524  return true;
525  if (nBlockHeight == 0)
526  nBlockHeight = nBestHeight;
527  if (nBlockTime == 0)
528  nBlockTime = GetAdjustedTime();
529  if ((int64)nLockTime < ((int64)nLockTime < LOCKTIME_THRESHOLD ? (int64)nBlockHeight : nBlockTime))
530  return true;
531  BOOST_FOREACH(const CTxIn& txin, vin)
532  if (!txin.IsFinal())
533  return false;
534  return true;
535  }
536 
537  bool IsNewerThan(const CTransaction& old) const
538  {
539  if (vin.size() != old.vin.size())
540  return false;
541  for (unsigned int i = 0; i < vin.size(); i++)
542  if (vin[i].prevout != old.vin[i].prevout)
543  return false;
544 
545  bool fNewer = false;
546  unsigned int nLowest = std::numeric_limits<unsigned int>::max();
547  for (unsigned int i = 0; i < vin.size(); i++)
548  {
549  if (vin[i].nSequence != old.vin[i].nSequence)
550  {
551  if (vin[i].nSequence <= nLowest)
552  {
553  fNewer = false;
554  nLowest = vin[i].nSequence;
555  }
556  if (old.vin[i].nSequence < nLowest)
557  {
558  fNewer = true;
559  nLowest = old.vin[i].nSequence;
560  }
561  }
562  }
563  return fNewer;
564  }
565 
566  bool IsCoinBase() const
567  {
568  return (vin.size() == 1 && vin[0].prevout.IsNull());
569  }
570 
574  bool IsStandard(std::string& strReason) const;
575  bool IsStandard() const
576  {
577  std::string strReason;
578  return IsStandard(strReason);
579  }
580 
585  bool AreInputsStandard(CCoinsViewCache& mapInputs) const;
586 
590  unsigned int GetLegacySigOpCount() const;
591 
597  unsigned int GetP2SHSigOpCount(CCoinsViewCache& mapInputs) const;
598 
603  {
604  int64 nValueOut = 0;
605  BOOST_FOREACH(const CTxOut& txout, vout)
606  {
607  nValueOut += txout.nValue;
608  if (!MoneyRange(txout.nValue) || !MoneyRange(nValueOut))
609  throw std::runtime_error("CTransaction::GetValueOut() : value out of range");
610  }
611  return nValueOut;
612  }
613 
621  int64 GetValueIn(CCoinsViewCache& mapInputs) const;
622 
623  static bool AllowFree(double dPriority)
624  {
625  // Large (in bytes) low-priority (new, small-coin) transactions
626  // need a fee.
627  return dPriority > COIN * 576 / 250;
628  }
629 
630 // Apply the effects of this transaction on the UTXO set represented by view
631 void UpdateCoins(const CTransaction& tx, CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, const uint256 &txhash);
632 
633  int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, enum GetMinFee_mode mode=GMF_BLOCK) const;
634 
635  friend bool operator==(const CTransaction& a, const CTransaction& b)
636  {
637  return (a.nVersion == b.nVersion &&
638  a.vin == b.vin &&
639  a.vout == b.vout &&
640  a.nLockTime == b.nLockTime);
641  }
642 
643  friend bool operator!=(const CTransaction& a, const CTransaction& b)
644  {
645  return !(a == b);
646  }
647 
648 
649  std::string ToString() const
650  {
651  std::string str;
652  str += strprintf("CTransaction(hash=%s, ver=%d, vin.size=%"PRIszu", vout.size=%"PRIszu", nLockTime=%u)\n",
653  GetHash().ToString().c_str(),
654  nVersion,
655  vin.size(),
656  vout.size(),
657  nLockTime);
658  for (unsigned int i = 0; i < vin.size(); i++)
659  str += " " + vin[i].ToString() + "\n";
660  for (unsigned int i = 0; i < vout.size(); i++)
661  str += " " + vout[i].ToString() + "\n";
662  return str;
663  }
664 
665  void print() const
666  {
667  printf("%s", ToString().c_str());
668  }
669 
670 
671  // Check whether all prevouts of this transaction are present in the UTXO set represented by view
672  bool HaveInputs(CCoinsViewCache &view) const;
673 
674  // Check whether all inputs of this transaction are valid (no double spends, scripts & sigs, amounts)
675  // This does not modify the UTXO set. If pvChecks is not NULL, script checks are pushed onto it
676  // instead of being performed inline.
677  bool CheckInputs(CValidationState &state, CCoinsViewCache &view, bool fScriptChecks = true,
678  unsigned int flags = SCRIPT_VERIFY_P2SH | SCRIPT_VERIFY_STRICTENC,
679  std::vector<CScriptCheck> *pvChecks = NULL) const;
680 
681  // Apply the effects of this transaction on the UTXO set represented by view
682  void UpdateCoins(CValidationState &state, CCoinsViewCache &view, CTxUndo &txundo, int nHeight, const uint256 &txhash) const;
683 
684  // Context-independent validity checks
686 
687  // Try to accept this transaction into the memory pool
688  bool AcceptToMemoryPool(CValidationState &state, bool fCheckInputs=true, bool fLimitFree = true, bool* pfMissingInputs=NULL);
689 
690 protected:
691  static const CTxOut &GetOutputFor(const CTxIn& input, CCoinsViewCache& mapInputs);
692 };
693 
696 {
697 private:
699 
700 public:
701  static uint64 CompressAmount(uint64 nAmount);
702  static uint64 DecompressAmount(uint64 nAmount);
703 
704  CTxOutCompressor(CTxOut &txoutIn) : txout(txoutIn) { }
705 
707  if (!fRead) {
708  uint64 nVal = CompressAmount(txout.nValue);
709  READWRITE(VARINT(nVal));
710  } else {
711  uint64 nVal = 0;
712  READWRITE(VARINT(nVal));
713  txout.nValue = DecompressAmount(nVal);
714  }
715  CScriptCompressor cscript(REF(txout.scriptPubKey));
716  READWRITE(cscript);
717  });)
718 };
719 
727 {
728 public:
729  CTxOut txout; // the txout data before being spent
730  bool fCoinBase; // if the outpoint was the last unspent: whether it belonged to a coinbase
731  unsigned int nHeight; // if the outpoint was the last unspent: its height
732  int nVersion; // if the outpoint was the last unspent: its version
733 
734  CTxInUndo() : txout(), fCoinBase(false), nHeight(0), nVersion(0) {}
735  CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn = false, unsigned int nHeightIn = 0, int nVersionIn = 0) : txout(txoutIn), fCoinBase(fCoinBaseIn), nHeight(nHeightIn), nVersion(nVersionIn) { }
736 
737  unsigned int GetSerializeSize(int nType, int nVersion) const {
738  return ::GetSerializeSize(VARINT(nHeight*2+(fCoinBase ? 1 : 0)), nType, nVersion) +
739  (nHeight > 0 ? ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion) : 0) +
740  ::GetSerializeSize(CTxOutCompressor(REF(txout)), nType, nVersion);
741  }
742 
743  template<typename Stream>
744  void Serialize(Stream &s, int nType, int nVersion) const {
745  ::Serialize(s, VARINT(nHeight*2+(fCoinBase ? 1 : 0)), nType, nVersion);
746  if (nHeight > 0)
747  ::Serialize(s, VARINT(this->nVersion), nType, nVersion);
748  ::Serialize(s, CTxOutCompressor(REF(txout)), nType, nVersion);
749  }
750 
751  template<typename Stream>
752  void Unserialize(Stream &s, int nType, int nVersion) {
753  unsigned int nCode = 0;
754  ::Unserialize(s, VARINT(nCode), nType, nVersion);
755  nHeight = nCode / 2;
756  fCoinBase = nCode & 1;
757  if (nHeight > 0)
758  ::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
759  ::Unserialize(s, REF(CTxOutCompressor(REF(txout))), nType, nVersion);
760  }
761 };
762 
764 class CTxUndo
765 {
766 public:
767  // undo information for all txins
768  std::vector<CTxInUndo> vprevout;
769 
771  READWRITE(vprevout);
772  )
773 };
774 
777 {
778 public:
779  std::vector<CTxUndo> vtxundo; // for all but the coinbase
780 
782  READWRITE(vtxundo);
783  )
784 
785  bool WriteToDisk(CDiskBlockPos &pos, const uint256 &hashBlock)
786  {
787  // Open history file to append
788  CAutoFile fileout = CAutoFile(OpenUndoFile(pos), SER_DISK, CLIENT_VERSION);
789  if (!fileout)
790  return error("CBlockUndo::WriteToDisk() : OpenUndoFile failed");
791 
792  // Write index header
793  unsigned int nSize = fileout.GetSerializeSize(*this);
794  fileout << FLATDATA(pchMessageStart) << nSize;
795 
796  // Write undo data
797  long fileOutPos = ftell(fileout);
798  if (fileOutPos < 0)
799  return error("CBlockUndo::WriteToDisk() : ftell failed");
800  pos.nPos = (unsigned int)fileOutPos;
801  fileout << *this;
802 
803  // calculate & write checksum
804  CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
805  hasher << hashBlock;
806  hasher << *this;
807  fileout << hasher.GetHash();
808 
809  // Flush stdio buffers and commit to disk before returning
810  fflush(fileout);
811  if (!IsInitialBlockDownload())
812  FileCommit(fileout);
813 
814  return true;
815  }
816 
817  bool ReadFromDisk(const CDiskBlockPos &pos, const uint256 &hashBlock)
818  {
819  // Open history file to read
820  CAutoFile filein = CAutoFile(OpenUndoFile(pos, true), SER_DISK, CLIENT_VERSION);
821  if (!filein)
822  return error("CBlockUndo::ReadFromDisk() : OpenBlockFile failed");
823 
824  // Read block
825  uint256 hashChecksum;
826  try {
827  filein >> *this;
828  filein >> hashChecksum;
829  }
830  catch (std::exception &e) {
831  return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
832  }
833 
834  // Verify checksum
835  CHashWriter hasher(SER_GETHASH, PROTOCOL_VERSION);
836  hasher << hashBlock;
837  hasher << *this;
838  if (hashChecksum != hasher.GetHash())
839  return error("CBlockUndo::ReadFromDisk() : checksum mismatch");
840 
841  return true;
842  }
843 };
844 
896 class CCoins
897 {
898 public:
899  // whether transaction is a coinbase
900  bool fCoinBase;
901 
902  // unspent transaction outputs; spent outputs are .IsNull(); spent outputs at the end of the array are dropped
903  std::vector<CTxOut> vout;
904 
905  // at which height this transaction was included in the active block chain
906  int nHeight;
907 
908  // version of the CTransaction; accesses to this value should probably check for nHeight as well,
909  // as new tx version will probably only be introduced at certain heights
910  int nVersion;
911 
912  // construct a CCoins from a CTransaction, at a given height
913  CCoins(const CTransaction &tx, int nHeightIn) : fCoinBase(tx.IsCoinBase()), vout(tx.vout), nHeight(nHeightIn), nVersion(tx.nVersion) { }
914 
915  // empty constructor
916  CCoins() : fCoinBase(false), vout(0), nHeight(0), nVersion(0) { }
917 
918  // remove spent outputs at the end of vout
919  void Cleanup() {
920  while (vout.size() > 0 && vout.back().IsNull())
921  vout.pop_back();
922  if (vout.empty())
923  std::vector<CTxOut>().swap(vout);
924  }
925 
926  void swap(CCoins &to) {
927  std::swap(to.fCoinBase, fCoinBase);
928  to.vout.swap(vout);
929  std::swap(to.nHeight, nHeight);
930  std::swap(to.nVersion, nVersion);
931  }
932 
933  // equality test
934  friend bool operator==(const CCoins &a, const CCoins &b) {
935  return a.fCoinBase == b.fCoinBase &&
936  a.nHeight == b.nHeight &&
937  a.nVersion == b.nVersion &&
938  a.vout == b.vout;
939  }
940  friend bool operator!=(const CCoins &a, const CCoins &b) {
941  return !(a == b);
942  }
943 
944  // calculate number of bytes for the bitmask, and its number of non-zero bytes
945  // each bit in the bitmask represents the availability of one output, but the
946  // availabilities of the first two outputs are encoded separately
947  void CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) const {
948  unsigned int nLastUsedByte = 0;
949  for (unsigned int b = 0; 2+b*8 < vout.size(); b++) {
950  bool fZero = true;
951  for (unsigned int i = 0; i < 8 && 2+b*8+i < vout.size(); i++) {
952  if (!vout[2+b*8+i].IsNull()) {
953  fZero = false;
954  continue;
955  }
956  }
957  if (!fZero) {
958  nLastUsedByte = b + 1;
959  nNonzeroBytes++;
960  }
961  }
962  nBytes += nLastUsedByte;
963  }
964 
965  bool IsCoinBase() const {
966  return fCoinBase;
967  }
968 
969  unsigned int GetSerializeSize(int nType, int nVersion) const {
970  unsigned int nSize = 0;
971  unsigned int nMaskSize = 0, nMaskCode = 0;
972  CalcMaskSize(nMaskSize, nMaskCode);
973  bool fFirst = vout.size() > 0 && !vout[0].IsNull();
974  bool fSecond = vout.size() > 1 && !vout[1].IsNull();
975  assert(fFirst || fSecond || nMaskCode);
976  unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
977  // version
978  nSize += ::GetSerializeSize(VARINT(this->nVersion), nType, nVersion);
979  // size of header code
980  nSize += ::GetSerializeSize(VARINT(nCode), nType, nVersion);
981  // spentness bitmask
982  nSize += nMaskSize;
983  // txouts themself
984  for (unsigned int i = 0; i < vout.size(); i++)
985  if (!vout[i].IsNull())
986  nSize += ::GetSerializeSize(CTxOutCompressor(REF(vout[i])), nType, nVersion);
987  // height
988  nSize += ::GetSerializeSize(VARINT(nHeight), nType, nVersion);
989  return nSize;
990  }
991 
992  template<typename Stream>
993  void Serialize(Stream &s, int nType, int nVersion) const {
994  unsigned int nMaskSize = 0, nMaskCode = 0;
995  CalcMaskSize(nMaskSize, nMaskCode);
996  bool fFirst = vout.size() > 0 && !vout[0].IsNull();
997  bool fSecond = vout.size() > 1 && !vout[1].IsNull();
998  assert(fFirst || fSecond || nMaskCode);
999  unsigned int nCode = 8*(nMaskCode - (fFirst || fSecond ? 0 : 1)) + (fCoinBase ? 1 : 0) + (fFirst ? 2 : 0) + (fSecond ? 4 : 0);
1000  // version
1001  ::Serialize(s, VARINT(this->nVersion), nType, nVersion);
1002  // header code
1003  ::Serialize(s, VARINT(nCode), nType, nVersion);
1004  // spentness bitmask
1005  for (unsigned int b = 0; b<nMaskSize; b++) {
1006  unsigned char chAvail = 0;
1007  for (unsigned int i = 0; i < 8 && 2+b*8+i < vout.size(); i++)
1008  if (!vout[2+b*8+i].IsNull())
1009  chAvail |= (1 << i);
1010  ::Serialize(s, chAvail, nType, nVersion);
1011  }
1012  // txouts themself
1013  for (unsigned int i = 0; i < vout.size(); i++) {
1014  if (!vout[i].IsNull())
1015  ::Serialize(s, CTxOutCompressor(REF(vout[i])), nType, nVersion);
1016  }
1017  // coinbase height
1018  ::Serialize(s, VARINT(nHeight), nType, nVersion);
1019  }
1020 
1021  template<typename Stream>
1022  void Unserialize(Stream &s, int nType, int nVersion) {
1023  unsigned int nCode = 0;
1024  // version
1025  ::Unserialize(s, VARINT(this->nVersion), nType, nVersion);
1026  // header code
1027  ::Unserialize(s, VARINT(nCode), nType, nVersion);
1028  fCoinBase = nCode & 1;
1029  std::vector<bool> vAvail(2, false);
1030  vAvail[0] = nCode & 2;
1031  vAvail[1] = nCode & 4;
1032  unsigned int nMaskCode = (nCode / 8) + ((nCode & 6) != 0 ? 0 : 1);
1033  // spentness bitmask
1034  while (nMaskCode > 0) {
1035  unsigned char chAvail = 0;
1036  ::Unserialize(s, chAvail, nType, nVersion);
1037  for (unsigned int p = 0; p < 8; p++) {
1038  bool f = (chAvail & (1 << p)) != 0;
1039  vAvail.push_back(f);
1040  }
1041  if (chAvail != 0)
1042  nMaskCode--;
1043  }
1044  // txouts themself
1045  vout.assign(vAvail.size(), CTxOut());
1046  for (unsigned int i = 0; i < vAvail.size(); i++) {
1047  if (vAvail[i])
1048  ::Unserialize(s, REF(CTxOutCompressor(vout[i])), nType, nVersion);
1049  }
1050  // coinbase height
1051  ::Unserialize(s, VARINT(nHeight), nType, nVersion);
1052  Cleanup();
1053  }
1054 
1055  // mark an outpoint spent, and construct undo information
1056  bool Spend(const COutPoint &out, CTxInUndo &undo) {
1057  if (out.n >= vout.size())
1058  return false;
1059  if (vout[out.n].IsNull())
1060  return false;
1061  undo = CTxInUndo(vout[out.n]);
1062  vout[out.n].SetNull();
1063  Cleanup();
1064  if (vout.size() == 0) {
1065  undo.nHeight = nHeight;
1066  undo.fCoinBase = fCoinBase;
1067  undo.nVersion = this->nVersion;
1068  }
1069  return true;
1070  }
1071 
1072  // mark a vout spent
1073  bool Spend(int nPos) {
1074  CTxInUndo undo;
1075  COutPoint out(0, nPos);
1076  return Spend(out, undo);
1077  }
1078 
1079  // check whether a particular output is still available
1080  bool IsAvailable(unsigned int nPos) const {
1081  return (nPos < vout.size() && !vout[nPos].IsNull());
1082  }
1083 
1084  // check whether the entire CCoins is spent
1085  // note that only !IsPruned() CCoins can be serialized
1086  bool IsPruned() const {
1087  BOOST_FOREACH(const CTxOut &out, vout)
1088  if (!out.IsNull())
1089  return false;
1090  return true;
1091  }
1092 };
1093 
1097 {
1098 private:
1101  unsigned int nIn;
1102  unsigned int nFlags;
1104 
1105 public:
1107  CScriptCheck(const CCoins& txFromIn, const CTransaction& txToIn, unsigned int nInIn, unsigned int nFlagsIn, int nHashTypeIn) :
1108  scriptPubKey(txFromIn.vout[txToIn.vin[nInIn].prevout.n].scriptPubKey),
1109  ptxTo(&txToIn), nIn(nInIn), nFlags(nFlagsIn), nHashType(nHashTypeIn) { }
1110 
1111  bool operator()() const;
1112 
1113  void swap(CScriptCheck &check) {
1114  scriptPubKey.swap(check.scriptPubKey);
1115  std::swap(ptxTo, check.ptxTo);
1116  std::swap(nIn, check.nIn);
1117  std::swap(nFlags, check.nFlags);
1118  std::swap(nHashType, check.nHashType);
1119  }
1120 };
1121 
1123 class CMerkleTx : public CTransaction
1124 {
1125 public:
1127  std::vector<uint256> vMerkleBranch;
1128  int nIndex;
1129 
1130  // memory only
1131  mutable bool fMerkleVerified;
1132 
1133 
1135  {
1136  Init();
1137  }
1138 
1139  CMerkleTx(const CTransaction& txIn) : CTransaction(txIn)
1140  {
1141  Init();
1142  }
1143 
1144  void Init()
1145  {
1146  hashBlock = 0;
1147  nIndex = -1;
1148  fMerkleVerified = false;
1149  }
1150 
1151 
1153  (
1154  nSerSize += SerReadWrite(s, *(CTransaction*)this, nType, nVersion, ser_action);
1155  nVersion = this->nVersion;
1156  READWRITE(hashBlock);
1157  READWRITE(vMerkleBranch);
1158  READWRITE(nIndex);
1159  )
1160 
1161 
1162  int SetMerkleBranch(const CBlock* pblock=NULL);
1163  int GetDepthInMainChain(CBlockIndex* &pindexRet) const;
1164  int GetDepthInMainChain() const { CBlockIndex *pindexRet; return GetDepthInMainChain(pindexRet); }
1165  bool IsInMainChain() const { return GetDepthInMainChain() > 0; }
1166  int GetBlocksToMaturity() const;
1167  bool AcceptToMemoryPool(bool fCheckInputs=true, bool fLimitFree=true);
1168 };
1169 
1170 
1171 
1172 
1173 
1209 {
1210 protected:
1211  // the total number of transactions in the block
1212  unsigned int nTransactions;
1213 
1214  // node-is-parent-of-matched-txid bits
1215  std::vector<bool> vBits;
1216 
1217  // txids and internal hashes
1218  std::vector<uint256> vHash;
1219 
1220  // flag set when encountering invalid data
1221  bool fBad;
1222 
1223  // helper function to efficiently calculate the number of nodes at given height in the merkle tree
1224  unsigned int CalcTreeWidth(int height) {
1225  return (nTransactions+(1 << height)-1) >> height;
1226  }
1227 
1228  // calculate the hash of a node in the merkle tree (at leaf level: the txid's themself)
1229  uint256 CalcHash(int height, unsigned int pos, const std::vector<uint256> &vTxid);
1230 
1231  // recursive function that traverses tree nodes, storing the data as bits and hashes
1232  void TraverseAndBuild(int height, unsigned int pos, const std::vector<uint256> &vTxid, const std::vector<bool> &vMatch);
1233 
1234  // recursive function that traverses tree nodes, consuming the bits and hashes produced by TraverseAndBuild.
1235  // it returns the hash of the respective node.
1236  uint256 TraverseAndExtract(int height, unsigned int pos, unsigned int &nBitsUsed, unsigned int &nHashUsed, std::vector<uint256> &vMatch);
1237 
1238 public:
1239 
1240  // serialization implementation
1242  READWRITE(nTransactions);
1243  READWRITE(vHash);
1244  std::vector<unsigned char> vBytes;
1245  if (fRead) {
1246  READWRITE(vBytes);
1247  CPartialMerkleTree &us = *(const_cast<CPartialMerkleTree*>(this));
1248  us.vBits.resize(vBytes.size() * 8);
1249  for (unsigned int p = 0; p < us.vBits.size(); p++)
1250  us.vBits[p] = (vBytes[p / 8] & (1 << (p % 8))) != 0;
1251  us.fBad = false;
1252  } else {
1253  vBytes.resize((vBits.size()+7)/8);
1254  for (unsigned int p = 0; p < vBits.size(); p++)
1255  vBytes[p / 8] |= vBits[p] << (p % 8);
1256  READWRITE(vBytes);
1257  }
1258  )
1259 
1260  // Construct a partial merkle tree from a list of transaction id's, and a mask that selects a subset of them
1261  CPartialMerkleTree(const std::vector<uint256> &vTxid, const std::vector<bool> &vMatch);
1262 
1264 
1265  // extract the matching txid's represented by this partial merkle tree.
1266  // returns the merkle root, or 0 in case of failure
1267  uint256 ExtractMatches(std::vector<uint256> &vMatch);
1268 };
1269 
1270 
1279 {
1280 public:
1281  // header
1282  static const int CURRENT_VERSION=2;
1286  unsigned int nTime;
1287  unsigned int nBits;
1288  unsigned int nNonce;
1289 
1291  {
1292  SetNull();
1293  }
1294 
1296  (
1297  READWRITE(this->nVersion);
1298  nVersion = this->nVersion;
1299  READWRITE(hashPrevBlock);
1300  READWRITE(hashMerkleRoot);
1301  READWRITE(nTime);
1302  READWRITE(nBits);
1303  READWRITE(nNonce);
1304  )
1305 
1306  void SetNull()
1307  {
1308  nVersion = CBlockHeader::CURRENT_VERSION;
1309  hashPrevBlock = 0;
1310  hashMerkleRoot = 0;
1311  nTime = 0;
1312  nBits = 0;
1313  nNonce = 0;
1314  }
1315 
1316  bool IsNull() const
1317  {
1318  return (nBits == 0);
1319  }
1320 
1322  {
1323  return Hash(BEGIN(nVersion), END(nNonce));
1324  }
1325 
1327  {
1328  return (int64)nTime;
1329  }
1330 
1331  void UpdateTime(const CBlockIndex* pindexPrev);
1332 };
1333 
1334 class CBlock : public CBlockHeader
1335 {
1336 public:
1337  // network and disk
1338  std::vector<CTransaction> vtx;
1339 
1340  // memory only
1341  mutable std::vector<uint256> vMerkleTree;
1342 
1344  {
1345  SetNull();
1346  }
1347 
1348  CBlock(const CBlockHeader &header)
1349  {
1350  SetNull();
1351  *((CBlockHeader*)this) = header;
1352  }
1353 
1355  (
1356  READWRITE(*(CBlockHeader*)this);
1357  READWRITE(vtx);
1358  )
1359 
1360  void SetNull()
1361  {
1362  CBlockHeader::SetNull();
1363  vtx.clear();
1364  vMerkleTree.clear();
1365  }
1366 
1368  {
1369  uint256 thash;
1370  scrypt_1024_1_1_256(BEGIN(nVersion), BEGIN(thash));
1371  return thash;
1372  }
1373 
1375  {
1376  CBlockHeader block;
1377  block.nVersion = nVersion;
1378  block.hashPrevBlock = hashPrevBlock;
1379  block.hashMerkleRoot = hashMerkleRoot;
1380  block.nTime = nTime;
1381  block.nBits = nBits;
1382  block.nNonce = nNonce;
1383  return block;
1384  }
1385 
1387  {
1388  vMerkleTree.clear();
1389  BOOST_FOREACH(const CTransaction& tx, vtx)
1390  vMerkleTree.push_back(tx.GetHash());
1391  int j = 0;
1392  for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
1393  {
1394  for (int i = 0; i < nSize; i += 2)
1395  {
1396  int i2 = std::min(i+1, nSize-1);
1397  vMerkleTree.push_back(Hash(BEGIN(vMerkleTree[j+i]), END(vMerkleTree[j+i]),
1398  BEGIN(vMerkleTree[j+i2]), END(vMerkleTree[j+i2])));
1399  }
1400  j += nSize;
1401  }
1402  return (vMerkleTree.empty() ? 0 : vMerkleTree.back());
1403  }
1404 
1405  const uint256 &GetTxHash(unsigned int nIndex) const {
1406  assert(vMerkleTree.size() > 0); // BuildMerkleTree must have been called first
1407  assert(nIndex < vtx.size());
1408  return vMerkleTree[nIndex];
1409  }
1410 
1411  std::vector<uint256> GetMerkleBranch(int nIndex) const
1412  {
1413  if (vMerkleTree.empty())
1414  BuildMerkleTree();
1415  std::vector<uint256> vMerkleBranch;
1416  int j = 0;
1417  for (int nSize = vtx.size(); nSize > 1; nSize = (nSize + 1) / 2)
1418  {
1419  int i = std::min(nIndex^1, nSize-1);
1420  vMerkleBranch.push_back(vMerkleTree[j+i]);
1421  nIndex >>= 1;
1422  j += nSize;
1423  }
1424  return vMerkleBranch;
1425  }
1426 
1427  static uint256 CheckMerkleBranch(uint256 hash, const std::vector<uint256>& vMerkleBranch, int nIndex)
1428  {
1429  if (nIndex == -1)
1430  return 0;
1431  BOOST_FOREACH(const uint256& otherside, vMerkleBranch)
1432  {
1433  if (nIndex & 1)
1434  hash = Hash(BEGIN(otherside), END(otherside), BEGIN(hash), END(hash));
1435  else
1436  hash = Hash(BEGIN(hash), END(hash), BEGIN(otherside), END(otherside));
1437  nIndex >>= 1;
1438  }
1439  return hash;
1440  }
1441 
1443  {
1444  // Open history file to append
1445  CAutoFile fileout = CAutoFile(OpenBlockFile(pos), SER_DISK, CLIENT_VERSION);
1446  if (!fileout)
1447  return error("CBlock::WriteToDisk() : OpenBlockFile failed");
1448 
1449  // Write index header
1450  unsigned int nSize = fileout.GetSerializeSize(*this);
1451  fileout << FLATDATA(pchMessageStart) << nSize;
1452 
1453  // Write block
1454  long fileOutPos = ftell(fileout);
1455  if (fileOutPos < 0)
1456  return error("CBlock::WriteToDisk() : ftell failed");
1457  pos.nPos = (unsigned int)fileOutPos;
1458  fileout << *this;
1459 
1460  // Flush stdio buffers and commit to disk before returning
1461  fflush(fileout);
1462  if (!IsInitialBlockDownload())
1463  FileCommit(fileout);
1464 
1465  return true;
1466  }
1467 
1468  bool ReadFromDisk(const CDiskBlockPos &pos)
1469  {
1470  SetNull();
1471 
1472  // Open history file to read
1473  CAutoFile filein = CAutoFile(OpenBlockFile(pos, true), SER_DISK, CLIENT_VERSION);
1474  if (!filein)
1475  return error("CBlock::ReadFromDisk() : OpenBlockFile failed");
1476 
1477  // Read block
1478  try {
1479  filein >> *this;
1480  }
1481  catch (std::exception &e) {
1482  return error("%s() : deserialize or I/O error", __PRETTY_FUNCTION__);
1483  }
1484 
1485  // Check the header
1486  if (!CheckProofOfWork(GetPoWHash(), nBits))
1487  return error("CBlock::ReadFromDisk() : errors in block header");
1488 
1489  return true;
1490  }
1491 
1492 
1493 
1494  void print() const
1495  {
1496  printf("CBlock(hash=%s, input=%s, PoW=%s, ver=%d, hashPrevBlock=%s, hashMerkleRoot=%s, nTime=%u, nBits=%08x, nNonce=%u, vtx=%"PRIszu")\n",
1497  GetHash().ToString().c_str(),
1498  HexStr(BEGIN(nVersion),BEGIN(nVersion)+80,false).c_str(),
1499  GetPoWHash().ToString().c_str(),
1500  nVersion,
1501  hashPrevBlock.ToString().c_str(),
1502  hashMerkleRoot.ToString().c_str(),
1503  nTime, nBits, nNonce,
1504  vtx.size());
1505  for (unsigned int i = 0; i < vtx.size(); i++)
1506  {
1507  printf(" ");
1508  vtx[i].print();
1509  }
1510  printf(" vMerkleTree: ");
1511  for (unsigned int i = 0; i < vMerkleTree.size(); i++)
1512  printf("%s ", vMerkleTree[i].ToString().c_str());
1513  printf("\n");
1514  }
1515 
1516 
1521  bool DisconnectBlock(CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &coins, bool *pfClean = NULL);
1522 
1523  // Apply the effects of this block (with given index) on the UTXO set represented by coins
1524  bool ConnectBlock(CValidationState &state, CBlockIndex *pindex, CCoinsViewCache &coins, bool fJustCheck=false);
1525 
1526  // Read a block from disk
1527  bool ReadFromDisk(const CBlockIndex* pindex);
1528 
1529  // Add this block to the block index, and if necessary, switch the active block chain to this
1530  bool AddToBlockIndex(CValidationState &state, const CDiskBlockPos &pos);
1531 
1532  // Context-independent validity checks
1533  bool CheckBlock(CValidationState &state, bool fCheckPOW=true, bool fCheckMerkleRoot=true) const;
1534 
1535  // Store block on disk
1536  // if dbp is provided, the file is known to already reside on disk
1537  bool AcceptBlock(CValidationState &state, CDiskBlockPos *dbp = NULL);
1538 };
1539 
1540 
1541 
1542 
1543 
1545 {
1546 public:
1547  unsigned int nBlocks; // number of blocks stored in file
1548  unsigned int nSize; // number of used bytes of block file
1549  unsigned int nUndoSize; // number of used bytes in the undo file
1550  unsigned int nHeightFirst; // lowest height of block in file
1551  unsigned int nHeightLast; // highest height of block in file
1552  uint64 nTimeFirst; // earliest time of block in file
1553  uint64 nTimeLast; // latest time of block in file
1554 
1556  READWRITE(VARINT(nBlocks));
1557  READWRITE(VARINT(nSize));
1558  READWRITE(VARINT(nUndoSize));
1559  READWRITE(VARINT(nHeightFirst));
1560  READWRITE(VARINT(nHeightLast));
1561  READWRITE(VARINT(nTimeFirst));
1562  READWRITE(VARINT(nTimeLast));
1563  )
1564 
1565  void SetNull() {
1566  nBlocks = 0;
1567  nSize = 0;
1568  nUndoSize = 0;
1569  nHeightFirst = 0;
1570  nHeightLast = 0;
1571  nTimeFirst = 0;
1572  nTimeLast = 0;
1573  }
1574 
1576  SetNull();
1577  }
1578 
1579  std::string ToString() const {
1580  return strprintf("CBlockFileInfo(blocks=%u, size=%u, heights=%u...%u, time=%s...%s)", nBlocks, nSize, nHeightFirst, nHeightLast, DateTimeStrFormat("%Y-%m-%d", nTimeFirst).c_str(), DateTimeStrFormat("%Y-%m-%d", nTimeLast).c_str());
1581  }
1582 
1583  // update statistics (does not update nSize)
1584  void AddBlock(unsigned int nHeightIn, uint64 nTimeIn) {
1585  if (nBlocks==0 || nHeightFirst > nHeightIn)
1586  nHeightFirst = nHeightIn;
1587  if (nBlocks==0 || nTimeFirst > nTimeIn)
1588  nTimeFirst = nTimeIn;
1589  nBlocks++;
1590  if (nHeightIn > nHeightFirst)
1591  nHeightLast = nHeightIn;
1592  if (nTimeIn > nTimeLast)
1593  nTimeLast = nTimeIn;
1594  }
1595 };
1596 
1599 extern int nLastBlockFile;
1600 
1603  BLOCK_VALID_HEADER = 1, // parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, timestamp not in future
1604  BLOCK_VALID_TREE = 2, // parent found, difficulty matches, timestamp >= median previous, checkpoint
1605  BLOCK_VALID_TRANSACTIONS = 3, // only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid, no duplicate txids, sigops, size, merkle root
1606  BLOCK_VALID_CHAIN = 4, // outputs do not overspend inputs, no double spends, coinbase output ok, immature coinbase spends, BIP30
1607  BLOCK_VALID_SCRIPTS = 5, // scripts/signatures ok
1609 
1610  BLOCK_HAVE_DATA = 8, // full block available in blk*.dat
1611  BLOCK_HAVE_UNDO = 16, // undo data available in rev*.dat
1613 
1614  BLOCK_FAILED_VALID = 32, // stage after last reached validness failed
1615  BLOCK_FAILED_CHILD = 64, // descends from failed block
1617 };
1618 
1627 {
1628 public:
1629  // pointer to the hash of the block, if any. memory is owned by this CBlockIndex
1631 
1632  // pointer to the index of the predecessor of this block
1634 
1635  // (memory only) pointer to the index of the *active* successor of this block
1637 
1638  // height of the entry in the chain. The genesis block has height 0
1639  int nHeight;
1640 
1641  // Which # file this block is stored in (blk?????.dat)
1642  int nFile;
1643 
1644  // Byte offset within blk?????.dat where this block's data is stored
1645  unsigned int nDataPos;
1646 
1647  // Byte offset within rev?????.dat where this block's undo data is stored
1648  unsigned int nUndoPos;
1649 
1650  // (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block
1652 
1653  // Number of transactions in this block.
1654  // Note: in a potential headers-first mode, this number cannot be relied upon
1655  unsigned int nTx;
1656 
1657  // (memory only) Number of transactions in the chain up to and including this block
1658  unsigned int nChainTx; // change to 64-bit type when necessary; won't happen before 2030
1659 
1660  // Verification status of this block. See enum BlockStatus
1661  unsigned int nStatus;
1662 
1663  // block header
1666  unsigned int nTime;
1667  unsigned int nBits;
1668  unsigned int nNonce;
1669 
1670 
1672  {
1673  phashBlock = NULL;
1674  pprev = NULL;
1675  pnext = NULL;
1676  nHeight = 0;
1677  nFile = 0;
1678  nDataPos = 0;
1679  nUndoPos = 0;
1680  nChainWork = 0;
1681  nTx = 0;
1682  nChainTx = 0;
1683  nStatus = 0;
1684 
1685  nVersion = 0;
1686  hashMerkleRoot = 0;
1687  nTime = 0;
1688  nBits = 0;
1689  nNonce = 0;
1690  }
1691 
1693  {
1694  phashBlock = NULL;
1695  pprev = NULL;
1696  pnext = NULL;
1697  nHeight = 0;
1698  nFile = 0;
1699  nDataPos = 0;
1700  nUndoPos = 0;
1701  nChainWork = 0;
1702  nTx = 0;
1703  nChainTx = 0;
1704  nStatus = 0;
1705 
1706  nVersion = block.nVersion;
1707  hashMerkleRoot = block.hashMerkleRoot;
1708  nTime = block.nTime;
1709  nBits = block.nBits;
1710  nNonce = block.nNonce;
1711  }
1712 
1714  CDiskBlockPos ret;
1715  if (nStatus & BLOCK_HAVE_DATA) {
1716  ret.nFile = nFile;
1717  ret.nPos = nDataPos;
1718  }
1719  return ret;
1720  }
1721 
1723  CDiskBlockPos ret;
1724  if (nStatus & BLOCK_HAVE_UNDO) {
1725  ret.nFile = nFile;
1726  ret.nPos = nUndoPos;
1727  }
1728  return ret;
1729  }
1730 
1732  {
1733  CBlockHeader block;
1734  block.nVersion = nVersion;
1735  if (pprev)
1736  block.hashPrevBlock = pprev->GetBlockHash();
1737  block.hashMerkleRoot = hashMerkleRoot;
1738  block.nTime = nTime;
1739  block.nBits = nBits;
1740  block.nNonce = nNonce;
1741  return block;
1742  }
1743 
1745  {
1746  return *phashBlock;
1747  }
1748 
1750  {
1751  return (int64)nTime;
1752  }
1753 
1755  {
1756  CBigNum bnTarget;
1757  bnTarget.SetCompact(nBits);
1758  if (bnTarget <= 0)
1759  return 0;
1760  return (CBigNum(1)<<256) / (bnTarget+1);
1761  }
1762 
1763  bool IsInMainChain() const
1764  {
1765  return (pnext || this == pindexBest);
1766  }
1767 
1768  bool CheckIndex() const
1769  {
1772  return true; // return CheckProofOfWork(GetBlockHash(), nBits);
1773  }
1774 
1775  enum { nMedianTimeSpan=11 };
1776 
1778  {
1779  int64 pmedian[nMedianTimeSpan];
1780  int64* pbegin = &pmedian[nMedianTimeSpan];
1781  int64* pend = &pmedian[nMedianTimeSpan];
1782 
1783  const CBlockIndex* pindex = this;
1784  for (int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->pprev)
1785  *(--pbegin) = pindex->GetBlockTime();
1786 
1787  std::sort(pbegin, pend);
1788  return pbegin[(pend - pbegin)/2];
1789  }
1790 
1792  {
1793  const CBlockIndex* pindex = this;
1794  for (int i = 0; i < nMedianTimeSpan/2; i++)
1795  {
1796  if (!pindex->pnext)
1797  return GetBlockTime();
1798  pindex = pindex->pnext;
1799  }
1800  return pindex->GetMedianTimePast();
1801  }
1802 
1807  static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart,
1808  unsigned int nRequired, unsigned int nToCheck);
1809 
1810  std::string ToString() const
1811  {
1812  return strprintf("CBlockIndex(pprev=%p, pnext=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
1813  pprev, pnext, nHeight,
1814  hashMerkleRoot.ToString().c_str(),
1815  GetBlockHash().ToString().c_str());
1816  }
1817 
1818  void print() const
1819  {
1820  printf("%s\n", ToString().c_str());
1821  }
1822 };
1823 
1825 {
1827  if (pa->nChainWork > pb->nChainWork) return false;
1828  if (pa->nChainWork < pb->nChainWork) return true;
1829 
1830  if (pa->GetBlockHash() < pb->GetBlockHash()) return false;
1831  if (pa->GetBlockHash() > pb->GetBlockHash()) return true;
1832 
1833  return false; // identical blocks
1834  }
1835 };
1836 
1837 
1838 
1841 {
1842 public:
1844 
1846  hashPrev = 0;
1847  }
1848 
1849  explicit CDiskBlockIndex(CBlockIndex* pindex) : CBlockIndex(*pindex) {
1850  hashPrev = (pprev ? pprev->GetBlockHash() : 0);
1851  }
1852 
1854  (
1855  if (!(nType & SER_GETHASH))
1856  READWRITE(VARINT(nVersion));
1857 
1858  READWRITE(VARINT(nHeight));
1859  READWRITE(VARINT(nStatus));
1860  READWRITE(VARINT(nTx));
1861  if (nStatus & (BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO))
1862  READWRITE(VARINT(nFile));
1863  if (nStatus & BLOCK_HAVE_DATA)
1864  READWRITE(VARINT(nDataPos));
1865  if (nStatus & BLOCK_HAVE_UNDO)
1866  READWRITE(VARINT(nUndoPos));
1867 
1868  // block header
1869  READWRITE(this->nVersion);
1870  READWRITE(hashPrev);
1871  READWRITE(hashMerkleRoot);
1872  READWRITE(nTime);
1873  READWRITE(nBits);
1874  READWRITE(nNonce);
1875  )
1876 
1877  uint256 GetBlockHash() const
1878  {
1879  CBlockHeader block;
1880  block.nVersion = nVersion;
1881  block.hashPrevBlock = hashPrev;
1882  block.hashMerkleRoot = hashMerkleRoot;
1883  block.nTime = nTime;
1884  block.nBits = nBits;
1885  block.nNonce = nNonce;
1886  return block.GetHash();
1887  }
1888 
1889 
1890  std::string ToString() const
1891  {
1892  std::string str = "CDiskBlockIndex(";
1893  str += CBlockIndex::ToString();
1894  str += strprintf("\n hashBlock=%s, hashPrev=%s)",
1895  GetBlockHash().ToString().c_str(),
1896  hashPrev.ToString().c_str());
1897  return str;
1898  }
1899 
1900  void print() const
1901  {
1902  printf("%s\n", ToString().c_str());
1903  }
1904 };
1905 
1908 private:
1909  enum mode_state {
1910  MODE_VALID, // everything ok
1911  MODE_INVALID, // network rule violation (DoS value may be set)
1912  MODE_ERROR, // run-time error
1913  } mode;
1914  int nDoS;
1916 public:
1917  CValidationState() : mode(MODE_VALID), nDoS(0), corruptionPossible(false) {}
1918  bool DoS(int level, bool ret = false, bool corruptionIn = false) {
1919  if (mode == MODE_ERROR)
1920  return ret;
1921  nDoS += level;
1922  mode = MODE_INVALID;
1923  corruptionPossible = corruptionIn;
1924  return ret;
1925  }
1926  bool Invalid(bool ret = false) {
1927  return DoS(0, ret);
1928  }
1929  bool Error() {
1930  mode = MODE_ERROR;
1931  return false;
1932  }
1933  bool Abort(const std::string &msg) {
1934  AbortNode(msg);
1935  return Error();
1936  }
1937  bool IsValid() {
1938  return mode == MODE_VALID;
1939  }
1940  bool IsInvalid() {
1941  return mode == MODE_INVALID;
1942  }
1943  bool IsError() {
1944  return mode == MODE_ERROR;
1945  }
1946  bool IsInvalid(int &nDoSOut) {
1947  if (IsInvalid()) {
1948  nDoSOut = nDoS;
1949  return true;
1950  }
1951  return false;
1952  }
1954  return corruptionPossible;
1955  }
1956 };
1957 
1958 
1959 
1960 
1961 
1962 
1963 
1969 {
1970 protected:
1971  std::vector<uint256> vHave;
1972 public:
1973 
1975  {
1976  }
1977 
1978  explicit CBlockLocator(const CBlockIndex* pindex)
1979  {
1980  Set(pindex);
1981  }
1982 
1983  explicit CBlockLocator(uint256 hashBlock)
1984  {
1985  std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hashBlock);
1986  if (mi != mapBlockIndex.end())
1987  Set((*mi).second);
1988  }
1989 
1990  CBlockLocator(const std::vector<uint256>& vHaveIn)
1991  {
1992  vHave = vHaveIn;
1993  }
1994 
1996  (
1997  if (!(nType & SER_GETHASH))
1998  READWRITE(nVersion);
1999  READWRITE(vHave);
2000  )
2001 
2002  void SetNull()
2003  {
2004  vHave.clear();
2005  }
2006 
2007  bool IsNull()
2008  {
2009  return vHave.empty();
2010  }
2011 
2012  void Set(const CBlockIndex* pindex)
2013  {
2014  vHave.clear();
2015  int nStep = 1;
2016  while (pindex)
2017  {
2018  vHave.push_back(pindex->GetBlockHash());
2019 
2020  // Exponentially larger steps back
2021  for (int i = 0; pindex && i < nStep; i++)
2022  pindex = pindex->pprev;
2023  if (vHave.size() > 10)
2024  nStep *= 2;
2025  }
2026  vHave.push_back(hashGenesisBlock);
2027  }
2028 
2030  {
2031  // Retrace how far back it was in the sender's branch
2032  int nDistance = 0;
2033  int nStep = 1;
2034  BOOST_FOREACH(const uint256& hash, vHave)
2035  {
2036  std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
2037  if (mi != mapBlockIndex.end())
2038  {
2039  CBlockIndex* pindex = (*mi).second;
2040  if (pindex->IsInMainChain())
2041  return nDistance;
2042  }
2043  nDistance += nStep;
2044  if (nDistance > 10)
2045  nStep *= 2;
2046  }
2047  return nDistance;
2048  }
2049 
2051  {
2052  // Find the first block the caller has in the main chain
2053  BOOST_FOREACH(const uint256& hash, vHave)
2054  {
2055  std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
2056  if (mi != mapBlockIndex.end())
2057  {
2058  CBlockIndex* pindex = (*mi).second;
2059  if (pindex->IsInMainChain())
2060  return pindex;
2061  }
2062  }
2063  return pindexGenesisBlock;
2064  }
2065 
2067  {
2068  // Find the first block the caller has in the main chain
2069  BOOST_FOREACH(const uint256& hash, vHave)
2070  {
2071  std::map<uint256, CBlockIndex*>::iterator mi = mapBlockIndex.find(hash);
2072  if (mi != mapBlockIndex.end())
2073  {
2074  CBlockIndex* pindex = (*mi).second;
2075  if (pindex->IsInMainChain())
2076  return hash;
2077  }
2078  }
2079  return hashGenesisBlock;
2080  }
2081 
2083  {
2084  CBlockIndex* pindex = GetBlockIndex();
2085  if (!pindex)
2086  return 0;
2087  return pindex->nHeight;
2088  }
2089 };
2090 
2091 
2092 
2093 
2094 
2095 
2096 
2097 
2099 {
2100 public:
2102  std::map<uint256, CTransaction> mapTx;
2103  std::map<COutPoint, CInPoint> mapNextTx;
2104 
2105  bool accept(CValidationState &state, CTransaction &tx, bool fCheckInputs, bool fLimitFree, bool* pfMissingInputs);
2106  bool addUnchecked(const uint256& hash, const CTransaction &tx);
2107  bool remove(const CTransaction &tx, bool fRecursive = false);
2108  bool removeConflicts(const CTransaction &tx);
2109  void clear();
2110  void queryHashes(std::vector<uint256>& vtxid);
2111  void pruneSpent(const uint256& hash, CCoins &coins);
2112 
2113  unsigned long size()
2114  {
2115  LOCK(cs);
2116  return mapTx.size();
2117  }
2118 
2119  bool exists(uint256 hash)
2120  {
2121  return (mapTx.count(hash) != 0);
2122  }
2123 
2125  {
2126  return mapTx[hash];
2127  }
2128 };
2129 
2130 extern CTxMemPool mempool;
2131 
2133 {
2134  int nHeight;
2141 
2142  CCoinsStats() : nHeight(0), hashBlock(0), nTransactions(0), nTransactionOutputs(0), nSerializedSize(0), hashSerialized(0), nTotalAmount(0) {}
2143 };
2144 
2147 {
2148 public:
2149  // Retrieve the CCoins (unspent transaction outputs) for a given txid
2150  virtual bool GetCoins(const uint256 &txid, CCoins &coins);
2151 
2152  // Modify the CCoins for a given txid
2153  virtual bool SetCoins(const uint256 &txid, const CCoins &coins);
2154 
2155  // Just check whether we have data for a given txid.
2156  // This may (but cannot always) return true for fully spent transactions
2157  virtual bool HaveCoins(const uint256 &txid);
2158 
2159  // Retrieve the block index whose state this CCoinsView currently represents
2160  virtual CBlockIndex *GetBestBlock();
2161 
2162  // Modify the currently active block index
2163  virtual bool SetBestBlock(CBlockIndex *pindex);
2164 
2165  // Do a bulk modification (multiple SetCoins + one SetBestBlock)
2166  virtual bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex);
2167 
2168  // Calculate statistics about the unspent transaction output set
2169  virtual bool GetStats(CCoinsStats &stats);
2170 
2171  // As we use CCoinsViews polymorphically, have a virtual destructor
2172  virtual ~CCoinsView() {}
2173 };
2174 
2177 {
2178 protected:
2180 
2181 public:
2182  CCoinsViewBacked(CCoinsView &viewIn);
2183  bool GetCoins(const uint256 &txid, CCoins &coins);
2184  bool SetCoins(const uint256 &txid, const CCoins &coins);
2185  bool HaveCoins(const uint256 &txid);
2186  CBlockIndex *GetBestBlock();
2187  bool SetBestBlock(CBlockIndex *pindex);
2188  void SetBackend(CCoinsView &viewIn);
2189  bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex);
2190  bool GetStats(CCoinsStats &stats);
2191 };
2192 
2195 {
2196 protected:
2198  std::map<uint256,CCoins> cacheCoins;
2199 
2200 public:
2201  CCoinsViewCache(CCoinsView &baseIn, bool fDummy = false);
2202 
2203  // Standard CCoinsView methods
2204  bool GetCoins(const uint256 &txid, CCoins &coins);
2205  bool SetCoins(const uint256 &txid, const CCoins &coins);
2206  bool HaveCoins(const uint256 &txid);
2207  CBlockIndex *GetBestBlock();
2208  bool SetBestBlock(CBlockIndex *pindex);
2209  bool BatchWrite(const std::map<uint256, CCoins> &mapCoins, CBlockIndex *pindex);
2210 
2211  // Return a modifiable reference to a CCoins. Check HaveCoins first.
2212  // Many methods explicitly require a CCoinsViewCache because of this method, to reduce
2213  // copying.
2214  CCoins &GetCoins(const uint256 &txid);
2215 
2216  // Push the modifications applied to this cache to its base.
2217  // Failure to call this method before destruction will cause the changes to be forgotten.
2218  bool Flush();
2219 
2220  // Calculate the size of the cache (in number of transactions)
2221  unsigned int GetCacheSize();
2222 
2223 private:
2224  std::map<uint256,CCoins>::iterator FetchCoins(const uint256 &txid);
2225 };
2226 
2230 {
2231 protected:
2233 
2234 public:
2235  CCoinsViewMemPool(CCoinsView &baseIn, CTxMemPool &mempoolIn);
2236  bool GetCoins(const uint256 &txid, CCoins &coins);
2237  bool HaveCoins(const uint256 &txid);
2238 };
2239 
2241 extern CCoinsViewCache *pcoinsTip;
2242 
2244 extern CBlockTreeDB *pblocktree;
2245 
2247 {
2249  std::vector<int64_t> vTxFees;
2250  std::vector<int64_t> vTxSigOps;
2251 };
2252 
2253 #if defined(_M_IX86) || defined(__i386__) || defined(__i386) || defined(_M_X64) || defined(__x86_64__) || defined(_M_AMD64)
2254 extern unsigned int cpuid_edx;
2255 #endif
2256 
2257 
2258 
2259 
2260 
2265 {
2266 public:
2267  // Public only for unit testing
2270 
2271 public:
2272  // Public only for unit testing and relay testing
2273  // (not relayed)
2274  std::vector<std::pair<unsigned int, uint256> > vMatchedTxn;
2275 
2276  // Create from a CBlock, filtering transactions according to filter
2277  // Note that this will call IsRelevantAndUpdate on the filter for each transaction,
2278  // thus the filter will likely be modified.
2279  CMerkleBlock(const CBlock& block, CBloomFilter& filter);
2280 
2282  (
2283  READWRITE(header);
2284  READWRITE(txn);
2285  )
2286 };
2287 
2288 #endif
bool error(const char *format,...)
Definition: util.cpp:358
std::map< uint256, CBlockIndex * > mapBlockIndex
Definition: main.cpp:37
CBlockLocator()
Definition: main.h:1974
CCoins()
Definition: main.h:916
unsigned int GetSerializeSize(int nType, int nVersion) const
Definition: main.h:969
#define VARINT(obj)
Definition: serialize.h:305
#define PRIszu
Definition: util.h:70
CCriticalSection cs_setpwalletRegistered
Definition: main.cpp:29
bool IsFinal(int nBlockHeight=0, int64 nBlockTime=0) const
Definition: main.h:520
CBlockHeader()
Definition: main.h:1290
bool CheckProofOfWork(uint256 hash, unsigned int nBits)
Check whether a block hash satisfies the proof-of-work requirement specified by nBits.
Definition: main.cpp:1254
CDiskBlockPos GetBlockPos() const
Definition: main.h:1713
unsigned int nTxOffsetIn
Definition: main.h:248
unsigned int n
Definition: main.h:267
bool Spend(int nPos)
Definition: main.h:1073
int nVersion
Definition: main.h:483
COutPoint()
Definition: main.h:284
CBlockHeader header
Definition: main.h:2268
#define strprintf(format,...)
Definition: util.h:169
#define PRI64d
Definition: util.h:51
CBigNum GetBlockWork() const
Definition: main.h:1754
CDiskBlockPos(int nFileIn, unsigned int nPosIn)
Definition: main.h:222
unsigned int nTxOffset
Definition: main.h:241
int nVersion
Definition: main.h:1283
void UpdateCoins(const CTransaction &tx, CValidationState &state, CCoinsViewCache &inputs, CTxUndo &txundo, int nHeight, const uint256 &txhash)
bool IsInitialBlockDownload()
Check whether we are doing an initial block download (synchronizing from disk or network) ...
Definition: main.cpp:1276
unsigned int SerReadWrite(Stream &s, const T &obj, int nType, int nVersion, CSerActionGetSerializeSize ser_action)
Definition: serialize.h:757
bool operator()(CBlockIndex *pa, CBlockIndex *pb)
Definition: main.h:1826
int64 GetMedianTime() const
Definition: main.h:1791
int nLastBlockFile
Definition: main.cpp:2604
friend bool operator!=(const COutPoint &a, const COutPoint &b)
Definition: main.h:300
uint256 hashBlock
Definition: main.h:2135
IMPLEMENT_SERIALIZE(READWRITE(VARINT(nFile));READWRITE(VARINT(nPos));) CDiskBlockPos()
Definition: main.h:213
CCoinsStats()
Definition: main.h:2142
CScript scriptPubKey
Definition: main.h:404
CScript COINBASE_FLAGS
Definition: main.cpp:76
bool CheckInputs(CValidationState &state, CCoinsViewCache &view, bool fScriptChecks=true, unsigned int flags=SCRIPT_VERIFY_P2SH|SCRIPT_VERIFY_STRICTENC, std::vector< CScriptCheck > *pvChecks=NULL) const
Definition: main.cpp:1475
CBlockIndex * FindBlockByHeight(int nHeight)
Find a block by height in the currently-connected chain.
Definition: main.cpp:1041
CBlockIndex * pprev
Definition: main.h:1633
#define READWRITE(obj)
Definition: serialize.h:93
CBlockLocator(const std::vector< uint256 > &vHaveIn)
Definition: main.h:1990
void Serialize(Stream &s, int nType, int nVersion) const
Definition: main.h:993
void print() const
Definition: main.h:388
bool LoadExternalBlockFile(FILE *fileIn, CDiskBlockPos *dbp=NULL)
Import blocks from an external file.
Definition: main.cpp:2986
void FileCommit(FILE *fileout)
Definition: util.cpp:1158
void swap(CScriptCheck &check)
Definition: main.h:1113
std::vector< CTxOut > vout
Definition: main.h:903
unsigned int nTransactions
Definition: main.h:1212
int nHeight
Definition: main.h:2134
Definition: main.h:1334
bool CheckTransaction(CValidationState &state) const
Definition: main.cpp:556
CScriptCheck()
Definition: main.h:1106
CBlock(const CBlockHeader &header)
Definition: main.h:1348
bool IsNull() const
Definition: main.h:429
static uint64 CompressAmount(uint64 nAmount)
Definition: main.cpp:4832
#define END(a)
Definition: util.h:40
bool AcceptToMemoryPool(CValidationState &state, bool fCheckInputs=true, bool fLimitFree=true, bool *pfMissingInputs=NULL)
Definition: main.cpp:822
CTxInUndo()
Definition: main.h:734
CScriptCheck(const CCoins &txFromIn, const CTransaction &txToIn, unsigned int nInIn, unsigned int nFlagsIn, int nHashTypeIn)
Definition: main.h:1107
GetMinFee_mode
Definition: main.h:467
int nBestHeight
Definition: main.cpp:41
unsigned int GetLegacySigOpCount() const
Count ECDSA signature operations the old-fashioned (pre-0.6) way.
Definition: main.cpp:488
unsigned int nFlags
Definition: main.h:1102
std::set< CWallet * > setpwalletRegistered
Definition: main.cpp:30
int nIndex
Definition: main.h:1128
inv message data
Definition: protocol.h:113
CBlockIndex()
Definition: main.h:1671
wrapper for CTxOut that provides a more compact serialization
Definition: main.h:695
unsigned int GetSerializeSize(int nType, int nVersion) const
Definition: main.h:737
int64 GetBlockTime() const
Definition: main.h:1749
uint64 nTimeFirst
Definition: main.h:1552
bool CheckDiskSpace(uint64 nAdditionalBytes=0)
Check whether enough disk space is available for an incoming block.
Definition: main.cpp:2591
std::map< COutPoint, CInPoint > mapNextTx
Definition: main.h:2103
std::set< CBlockIndex *, CBlockIndexWorkComparator > setBlockIndexValid
Definition: main.cpp:46
void Cleanup()
Definition: main.h:919
void Serialize(Stream &s, char a, int, int=0)
Definition: serialize.h:120
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: main.h:1968
uint256 hashBlock
Definition: main.h:1126
CTransaction * ptx
Definition: main.h:266
int nHeight
Definition: main.h:906
BloomFilter is a probabilistic filter which SPV clients provide so that we can filter the transaction...
Definition: bloom.h:41
void PrintBlockTree()
Print the loaded block tree.
Definition: main.cpp:2916
std::string ToString() const
Definition: main.h:1810
void print() const
Definition: main.h:459
friend bool operator==(const CTxOut &a, const CTxOut &b)
Definition: main.h:439
std::vector< int64_t > vTxFees
Definition: main.h:2249
void print() const
Definition: main.h:665
CScript scriptPubKey
Definition: main.h:1099
bool Invalid(bool ret=false)
Definition: main.h:1926
IMPLEMENT_SERIALIZE(READWRITE(*(CDiskBlockPos *) this);READWRITE(VARINT(nTxOffset));) CDiskTxPos(const CDiskBlockPos &blockIn
void Unserialize(Stream &s, int nType, int nVersion)
Definition: main.h:1022
static bool AllowFree(double dPriority)
Definition: main.h:623
IMPLEMENT_SERIALIZE(READWRITE(prevout);READWRITE(scriptSig);READWRITE(nSequence);) bool IsFinal() const
Definition: main.h:350
unsigned int nSize
Definition: main.h:1548
uint256 GetHash() const
Definition: main.h:515
bool AreInputsStandard(CCoinsViewCache &mapInputs) const
Check for standard transaction types.
Definition: main.cpp:434
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b)
Definition: main.h:227
CTxOut(int64 nValueIn, CScript scriptPubKeyIn)
Definition: main.h:411
#define IMPLEMENT_SERIALIZE(statements)
Definition: serialize.h:55
bool ConnectBestBlock(CValidationState &state)
Find the best known block, and make it the tip of the block chain.
Definition: main.cpp:1321
CTxIn(uint256 hashPrevTx, unsigned int nOut, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits< unsigned int >::max())
Definition: main.h:342
bool IsError()
Definition: main.h:1943
bool fMerkleVerified
Definition: main.h:1131
Compact serializer for scripts.
Definition: script.h:606
double dHashesPerSec
Definition: main.cpp:80
Data structure that represents a partial merkle tree.
Definition: main.h:1208
int nFile
Definition: main.h:1642
int64 GetMinFee(unsigned int nBlockSize=1, bool fAllowFree=true, enum GetMinFee_mode mode=GMF_BLOCK) const
Definition: main.cpp:604
uint256 GetPoWHash() const
Definition: main.h:1367
CTxMemPool mempool
Definition: main.cpp:34
uint64 nLastBlockTx
Definition: main.cpp:4292
friend bool operator!=(const CTxOut &a, const CTxOut &b)
Definition: main.h:445
CTxOutCompressor(CTxOut &txoutIn)
Definition: main.h:704
unsigned long long uint64
Definition: serialize.h:26
pruned version of CTransaction: only retains metadata and unspent transaction outputs ...
Definition: main.h:896
bool fReindex
Definition: main.cpp:50
int64 GetMedianTimePast() const
Definition: main.h:1777
const std::string strMessageMagic
Definition: main.cpp:78
unsigned int GetSerializeSize(const T &obj)
Definition: serialize.h:1190
unsigned int nCoinCacheSize
Definition: main.cpp:53
unsigned int n
Definition: main.h:282
bool IsDust() const
Definition: main.cpp:367
uint256 nBestInvalidWork
Definition: main.cpp:43
bool corruptionPossible
Definition: main.h:1915
CBlock()
Definition: main.h:1343
uint256 GetBlockHash()
Definition: main.h:2066
uint256 nChainWork
Definition: main.h:1651
uint256 hashGenesisBlock
CBlockIndex(CBlockHeader &block)
Definition: main.h:1692
CDiskBlockIndex(CBlockIndex *pindex)
Definition: main.h:1849
unsigned int nHeightLast
Definition: main.h:1551
#define FLATDATA(obj)
Definition: serialize.h:304
int GetNumBlocksOfPeers()
Get the number of active peers.
Definition: main.cpp:1271
void IncrementExtraNonce(CBlock *pblock, CBlockIndex *pindexPrev, unsigned int &nExtraNonce)
Modify the extranonce in a block.
Definition: main.cpp:4568
Undo information for a CTxIn.
Definition: main.h:726
std::string ToString() const
Definition: main.h:452
void Init()
Definition: main.h:1144
unsigned int nChainTx
Definition: main.h:1658
bool VerifySignature(const CCoins &txFrom, const CTransaction &txTo, unsigned int nIn, unsigned int flags, int nHashType)
Verify a signature.
Definition: main.cpp:1470
bool IsNewerThan(const CTransaction &old) const
Definition: main.h:537
unsigned int nUndoSize
Definition: main.h:1549
std::string GetWarnings(std::string strFor)
Format a string that describes several potential problems detected by the core.
bool CheckIndex() const
Definition: main.h:1768
friend bool operator==(const COutPoint &a, const COutPoint &b)
Definition: main.h:295
std::string ToString() const
Definition: script.h:561
bool IsAvailable(unsigned int nPos) const
Definition: main.h:1080
int64 nTransactionFee
Definition: main.cpp:84
IMPLEMENT_SERIALIZE(READWRITE(this->nVersion);nVersion=this->nVersion;READWRITE(vin);READWRITE(vout);READWRITE(nLockTime);) void SetNull()
Definition: main.h:494
bool InitBlockIndex()
Initialize a new block tree database + block data on disk.
Definition: main.cpp:2836
CInPoint(CTransaction *ptxIn, unsigned int nIn)
Definition: main.h:270
virtual ~CCoinsView()
Definition: main.h:2172
CCoins(const CTransaction &tx, int nHeightIn)
Definition: main.h:913
static int64 nMinTxFee
Fees smaller than this (in satoshi) are considered zero fee (for transaction creation) ...
Definition: main.h:480
friend bool operator==(const CCoins &a, const CCoins &b)
Definition: main.h:934
uint256 BuildMerkleTree() const
Definition: main.h:1386
int GetDepthInMainChain() const
Definition: main.h:1164
uint256 hashSerialized
Definition: main.h:2139
friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b)
Definition: main.h:231
void Serialize(Stream &s, int nType, int nVersion) const
Definition: main.h:744
unsigned int GetP2SHSigOpCount(CCoinsViewCache &mapInputs) const
Count ECDSA signature operations in pay-to-script-hash inputs.
Definition: main.cpp:1411
int64 nTimeBestReceived
Definition: main.cpp:47
uint256 SerializeHash(const T &obj, int nType=SER_GETHASH, int nVersion=PROTOCOL_VERSION)
Definition: hash.h:101
int nHashType
Definition: main.h:1103
void AddBlock(unsigned int nHeightIn, uint64 nTimeIn)
Definition: main.h:1584
CBigNum & SetCompact(unsigned int nCompact)
Definition: bignum.h:289
std::vector< uint256 > vHash
Definition: main.h:1218
bool IsInMainChain() const
Definition: main.h:1165
Used to relay blocks as header + vector to filtered nodes.
Definition: main.h:2264
unsigned int nTime
Definition: main.h:1666
unsigned int CalcTreeWidth(int height)
Definition: main.h:1224
FILE * OpenBlockFile(const CDiskBlockPos &pos, bool fReadOnly=false)
Open a block file (blk?????.dat)
Definition: main.cpp:2629
CBlockIndex * InsertBlockIndex(uint256 hash)
Create a new block index entry for a given block hash.
Definition: main.cpp:2637
int64 nHPSTimerStart
Definition: main.cpp:81
unsigned int nStatus
Definition: main.h:1661
unsigned int nLockTime
Definition: main.h:486
int GetHeight()
Definition: main.h:2082
Access to the block database (blocks/index/)
Definition: txdb.h:32
CBlockHeader GetBlockHeader() const
Definition: main.h:1731
uint256 nBestChainWork
Definition: main.cpp:42
int nVersion
Definition: main.h:910
unsigned long size()
Definition: main.h:2113
uint256 hashMerkleRoot
Definition: main.h:1285
void print() const
Definition: main.h:1818
unsigned int GetSerializeSize(char a, int, int=0)
Definition: serialize.h:106
Abstract view on the open txout dataset.
Definition: main.h:2146
unsigned int nDataPos
Definition: main.h:1645
#define printf
Definition: rpcdump.cpp:12
CBlockTreeDB * pblocktree
Global variable that points to the active block tree (protected by cs_main)
Definition: main.cpp:290
An input of a transaction.
Definition: main.h:323
void SetNull()
Definition: main.h:271
IMPLEMENT_SERIALIZE(READWRITE(VARINT(nBlocks));READWRITE(VARINT(nSize));READWRITE(VARINT(nUndoSize));READWRITE(VARINT(nHeightFirst));READWRITE(VARINT(nHeightLast));READWRITE(VARINT(nTimeFirst));READWRITE(VARINT(nTimeLast));) void SetNull()
Definition: main.h:1555
bool IsNull() const
Definition: main.h:272
bool ProcessBlock(CValidationState &state, CNode *pfrom, CBlock *pblock, CDiskBlockPos *dbp=NULL)
Process an incoming block.
Definition: main.cpp:2339
bool fCoinBase
Definition: main.h:730
#define LOCK(cs)
Definition: sync.h:108
bool VerifyDB(int nCheckLevel, int nCheckDepth)
Verify consistency of the block and coin databases.
Definition: main.cpp:2730
CCoinsView * base
Definition: main.h:2179
std::vector< CTxOut > vout
Definition: main.h:485
CBlockFileInfo()
Definition: main.h:1575
bool CorruptionPossible()
Definition: main.h:1953
CBlockIndex * GetBlockIndex()
Definition: main.h:2050
void Unserialize(Stream &s, char &a, int, int=0)
Definition: serialize.h:134
CBlockHeader GetBlockHeader() const
Definition: main.h:1374
CBlockIndex * pindexGenesisBlock
Definition: main.cpp:40
void CalcMaskSize(unsigned int &nBytes, unsigned int &nNonzeroBytes) const
Definition: main.h:947
bool IsInMainChain() const
Definition: main.h:1763
std::vector< CTxIn > vin
Definition: main.h:484
bool DoS(int level, bool ret=false, bool corruptionIn=false)
Definition: main.h:1918
CBlockFileInfo infoLastBlockFile
Definition: main.cpp:2603
uint256 hashPrevBlock
Definition: main.h:1284
int64 GetAdjustedTime()
Definition: util.cpp:1317
MTState * state
Definition: db_test.cc:1708
C++ wrapper for BIGNUM (OpenSSL bignum)
Definition: bignum.h:51
CBlockTemplate * CreateNewBlock(const CScript &scriptPubKeyIn)
Generate a new block, without valid proof-of-work.
Definition: main.cpp:4319
int64 GetBlockTime() const
Definition: main.h:1326
std::vector< uint256 > vMerkleBranch
Definition: main.h:1127
A CService with information about it as peer.
Definition: protocol.h:76
unsigned int nBits
Definition: main.h:1667
CDiskBlockIndex()
Definition: main.h:1845
void RegisterWallet(CWallet *pwalletIn)
Register a wallet to receive updates from core.
Definition: main.cpp:96
uint256 hashMerkleRoot
Definition: main.h:1665
std::map< uint256, CTransaction > mapTx
Definition: main.h:2102
int nScriptCheckThreads
Definition: main.cpp:48
CTxOut txout
Definition: main.h:729
unsigned int nNonce
Definition: main.h:1288
void scrypt_1024_1_1_256(const char *input, char *output)
Definition: scrypt.cpp:325
std::vector< uint256 > vMerkleTree
Definition: main.h:1341
bool IsNull()
Definition: main.h:2007
unsigned int nHeightFirst
Definition: main.h:1550
int64 GetValueIn(CCoinsViewCache &mapInputs) const
Amount of bitcoins coming in to this transaction Note that lightweight clients may not know anything ...
Definition: main.cpp:1399
uint256 Hash(const T1 pbegin, const T1 pend)
Definition: hash.h:16
void swap(CCoins &to)
Definition: main.h:926
std::vector< uint256 > vHave
Definition: main.h:1971
An output of a transaction.
Definition: main.h:400
Used to marshal pointers into hashes for db storage.
Definition: main.h:1840
std::string DateTimeStrFormat(const char *pszFormat, int64 nTime)
Definition: util.h:352
int64 GetValueOut() const
Amount of bitcoins spent by this transaction.
Definition: main.h:602
void print() const
Definition: main.h:1900
unsigned int nHeight
Definition: main.h:731
bool CheckBlock(int nHeight, const uint256 &hash)
Definition: checkpoints.cpp:61
CPartialMerkleTree txn
Definition: main.h:2269
bool Error()
Definition: main.h:1929
bool IsNull() const
Definition: main.h:236
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: main.h:278
unsigned int ComputeMinWork(unsigned int nBase, int64 nTime)
Calculate the minimum amount of work a received block needs, without knowing its direct parent...
std::vector< CTxInUndo > vprevout
Definition: main.h:768
bool Abort(const std::string &msg)
Definition: main.h:1933
std::vector< uint256 > GetMerkleBranch(int nIndex) const
Definition: main.h:1411
CTxOut()
Definition: main.h:406
std::string ToString() const
Definition: main.h:1890
void ThreadScriptCheck()
Run an instance of the script checking thread.
Definition: main.cpp:1672
void print() const
Definition: main.h:1494
std::string ToString() const
Definition: main.h:649
bool IsStandard() const
Definition: main.h:575
CCriticalSection cs
Definition: main.h:2101
unsigned int nPos
Definition: main.h:211
CInPoint()
Definition: main.h:269
static const int CURRENT_VERSION
Definition: main.h:1282
CCriticalSection cs_LastBlockFile
Definition: main.cpp:2602
uint256 GetHash() const
Definition: main.h:434
void UnloadBlockIndex()
Unload database information.
Definition: main.cpp:2803
std::string ToString() const
Definition: main.h:373
IMPLEMENT_SERIALIZE(READWRITE(FLATDATA(*this));) void SetNull()
Definition: main.h:286
Closure representing one script verification Note that this stores references to the spending transac...
Definition: main.h:1096
bool GetTransaction(const uint256 &hash, CTransaction &tx, uint256 &hashBlock, bool fAllowSlow=false)
Retrieve a transaction (from memory pool, or from disk, if possible)
Definition: main.cpp:968
CTransaction & lookup(uint256 hash)
Definition: main.h:2124
bool WriteToDisk(CDiskBlockPos &pos)
Definition: main.h:1442
bool HaveInputs(CCoinsViewCache &view) const
Definition: main.cpp:1442
int nVersion
Definition: main.h:1664
std::vector< bool > vBits
Definition: main.h:1215
const uint256 & GetTxHash(unsigned int nIndex) const
Definition: main.h:1405
uint64 nLastBlockSize
Definition: main.cpp:4293
bool LoadBlockIndex()
Load the block tree and coins database from disk.
Definition: main.cpp:2815
CCoinsViewCache * pcoinsTip
Global variable that points to the active CCoinsView (protected by cs_main)
Definition: main.cpp:289
CValidationState()
Definition: main.h:1917
unsigned int nUndoPos
Definition: main.h:1648
COutPoint(uint256 hashIn, unsigned int nIn)
Definition: main.h:285
CScript scriptSig
Definition: main.h:327
unsigned int nSequence
Definition: main.h:328
bool fCoinBase
Definition: main.h:900
std::string ToString() const
Definition: main.h:305
#define BEGIN(a)
Definition: util.h:39
IMPLEMENT_SERIALIZE(READWRITE(nValue);READWRITE(scriptPubKey);) void SetNull()
Definition: main.h:418
CMerkleTx(const CTransaction &txIn)
Definition: main.h:1139
Capture information about block/transaction validation.
Definition: main.h:1907
256-bit unsigned integer
Definition: uint256.h:537
uint256 hashPrev
Definition: main.h:1843
int64 nMinimumInputValue
Definition: main.cpp:85
const CTransaction * ptxTo
Definition: main.h:1100
static uint64 DecompressAmount(uint64 nAmount)
Definition: main.cpp:4851
unsigned int nTime
Definition: main.h:1286
void Unserialize(Stream &s, int nType, int nVersion)
Definition: main.h:752
bool IsValid()
Definition: main.h:1937
uint256 GetHash() const
Definition: main.h:1321
CBlockIndex * pnext
Definition: main.h:1636
unsigned char pchMessageStart[4]
Definition: main.cpp:3178
bool Spend(const COutPoint &out, CTxInUndo &undo)
Definition: main.h:1056
uint256 hashBestChain
Definition: main.cpp:44
CTxOut & txout
Definition: main.h:698
A key allocated from the key pool.
Definition: wallet.h:318
CBlockTemplate * CreateNewBlockWithKey(CReserveKey &reservekey)
Definition: main.cpp:4558
bool IsInvalid(int &nDoSOut)
Definition: main.h:1946
int64 nValue
Definition: main.h:403
std::vector< std::pair< unsigned int, uint256 > > vMatchedTxn
Definition: main.h:2274
The block chain is a tree shaped structure starting with the genesis block at the root...
Definition: main.h:1626
Undo information for a CBlock.
Definition: main.h:776
Serialized script, used inside transaction inputs and outputs.
Definition: script.h:244
CTxIn()
Definition: main.h:330
CBlockLocator(const CBlockIndex *pindex)
Definition: main.h:1978
Undo information for a CTransaction.
Definition: main.h:764
std::string ToString() const
Definition: uint256.h:343
CTransaction()
Definition: main.h:488
std::vector< int64_t > vTxSigOps
Definition: main.h:2250
unsigned int nTransactionsUpdated
Definition: main.cpp:35
bool IsPruned() const
Definition: main.h:1086
void UnregisterWallet(CWallet *pwalletIn)
Unregister a wallet from core.
Definition: main.cpp:104
void SetNull()
Definition: main.h:235
void GenerateBitcoins(bool fGenerate, CWallet *pwallet)
Run the miner threads.
Definition: main.cpp:4800
Stats stats
Definition: db_bench.cc:291
bool exists(uint256 hash)
Definition: main.h:2119
int64 nTotalAmount
Definition: main.h:2140
An inpoint - a combination of a transaction and an index n into its vin.
Definition: main.h:263
A CWallet is an extension of a keystore, which also maintains a set of transactions and balances...
Definition: wallet.h:69
void FormatHashBuffers(CBlock *pblock, char *pmidstate, char *pdata, char *phash1)
Do mining precalculation.
Definition: main.cpp:4586
unsigned int nBlocks
Definition: main.h:1547
bool CheckWork(CBlock *pblock, CWallet &wallet, CReserveKey &reservekey)
Check mined block.
Definition: main.cpp:4632
bool fImporting
Definition: main.cpp:49
bool GetWalletFile(CWallet *pwallet, std::string &strWalletFileOut)
uint64 nTransactionOutputs
Definition: main.h:2137
bool IsCoinBase() const
Definition: main.h:965
std::string ToString() const
Definition: main.h:1579
bool ProcessMessages(CNode *pfrom)
Process protocol messages received from a given node.
Definition: main.cpp:3921
bool IsCoinBase() const
Definition: main.h:566
BlockStatus
Definition: main.h:1601
CBlockIndex * pindexTip
Definition: main.h:2197
void SyncWithWallets(const uint256 &hash, const CTransaction &tx, const CBlock *pblock=NULL, bool fUpdate=false)
Push an updated transaction to all registered wallets.
Definition: main.cpp:129
bool IsInvalid()
Definition: main.h:1940
CBlock block
Definition: main.h:2248
bool IsNull() const
Definition: main.h:288
unsigned int nIn
Definition: main.h:1101
int nVersion
Definition: main.h:732
std::vector< CTransaction > vtx
Definition: main.h:1338
uint64 nTransactions
Definition: main.h:2136
bool IsNull() const
Definition: main.h:1316
friend bool operator<(const COutPoint &a, const COutPoint &b)
Definition: main.h:290
CMerkleTx()
Definition: main.h:1134
CDiskBlockPos GetUndoPos() const
Definition: main.h:1722
FILE * OpenUndoFile(const CDiskBlockPos &pos, bool fReadOnly=false)
Open an undo file (rev?????.dat)
Definition: main.cpp:2633
The basic transaction that is broadcasted on the network and contained in blocks. ...
Definition: main.h:477
int nHeight
Definition: main.h:1639
CCoinsView backed by another CCoinsView.
Definition: main.h:2176
Information about a peer.
Definition: net.h:154
static const int CURRENT_VERSION
Definition: main.h:482
bool SendMessages(CNode *pto, bool fSendTrickle)
Send queued protocol messages to be sent to a give node.
Definition: main.cpp:4044
CCoinsView that adds a memory cache for transactions to another CCoinsView.
Definition: main.h:2194
unsigned int nBits
Definition: main.h:1287
uint64 nSerializedSize
Definition: main.h:2138
friend bool operator==(const CTxIn &a, const CTxIn &b)
Definition: main.h:361
void Set(const CBlockIndex *pindex)
Definition: main.h:2012
std::string HexStr(const T itbegin, const T itend, bool fSpaces=false)
Definition: util.h:292
CTxIn(COutPoint prevoutIn, CScript scriptSigIn=CScript(), unsigned int nSequenceIn=std::numeric_limits< unsigned int >::max())
Definition: main.h:335
void SetNull()
Definition: main.h:255
CCriticalSection cs_main
Definition: main.cpp:32
CTxInUndo(const CTxOut &txoutIn, bool fCoinBaseIn=false, unsigned int nHeightIn=0, int nVersionIn=0)
Definition: main.h:735
std::vector< CTxUndo > vtxundo
Definition: main.h:779
int nFile
Definition: main.h:210
CDiskTxPos()
Definition: main.h:251
COutPoint prevout
Definition: main.h:326
T & REF(const T &val)
Definition: serialize.h:36
bool ReadFromDisk(const CDiskBlockPos &pos)
Definition: main.h:1468
void print() const
Definition: main.h:310
bool SetBestChain(CValidationState &state, CBlockIndex *pindexNew)
Connect/disconnect blocks until pindexNew is the new tip of the active block chain.
Definition: main.cpp:1832
uint64 nTimeLast
Definition: main.h:1553
friend bool operator!=(const CTxIn &a, const CTxIn &b)
Definition: main.h:368
CCoinsView that brings transactions from a memorypool into view.
Definition: main.h:2229
CBlockIndex * pindexBest
Definition: main.cpp:45
uint32_t hash
Definition: cache.cc:34
static int64 nMinRelayTxFee
Fees smaller than this (in satoshi) are considered zero fee (for relaying)
Definition: main.h:481
CBlockLocator(uint256 hashBlock)
Definition: main.h:1983
unsigned int nNonce
Definition: main.h:1668
bool MoneyRange(int64 nValue)
Definition: main.h:58
unsigned int nTx
Definition: main.h:1655
bool IsNull() const
Definition: main.h:510
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: main.h:1278
Definition: main.h:471
RAII wrapper for FILE*.
Definition: serialize.h:1108
CTxMemPool & mempool
Definition: main.h:2232
bool AbortNode(const std::string &msg)
Abort with a message.
Definition: main.cpp:2583
bool fBenchmark
Definition: main.cpp:51
bool fTxIndex
Definition: main.cpp:52
static uint256 CheckMerkleBranch(uint256 hash, const std::vector< uint256 > &vMerkleBranch, int nIndex)
Definition: main.h:1427
uint256 GetBlockHash() const
Definition: main.h:1744
A transaction with a merkle branch linking it to the block chain.
Definition: main.h:1123
friend bool operator==(const CTransaction &a, const CTransaction &b)
Definition: main.h:635
static const CTxOut & GetOutputFor(const CTxIn &input, CCoinsViewCache &mapInputs)
Definition: main.cpp:1392
std::map< uint256, CBlock * > mapOrphanBlocks
Definition: main.cpp:69
friend bool operator!=(const CCoins &a, const CCoins &b)
Definition: main.h:940
std::map< uint256, CCoins > cacheCoins
Definition: main.h:2198
uint256 hash
Definition: main.h:281
long long int64
Definition: serialize.h:25
friend bool operator!=(const CTransaction &a, const CTransaction &b)
Definition: main.h:643
const uint256 * phashBlock
Definition: main.h:1630
int GetDistanceBack()
Definition: main.h:2029