PRCYCoin  2.0.0.7rc1
P2P Digital Currency
chain.h
Go to the documentation of this file.
1 // Copyright (c) 2009-2010 Satoshi Nakamoto
2 // Copyright (c) 2009-2014 The Bitcoin developers
3 // Copyright (c) 2015-2018 The PIVX developers
4 // Copyright (c) 2018-2020 The DAPS Project developers
5 // Distributed under the MIT software license, see the accompanying
6 // file COPYING or http://www.opensource.org/licenses/mit-license.php.
7 
8 #ifndef BITCOIN_CHAIN_H
9 #define BITCOIN_CHAIN_H
10 
11 #include "primitives/block.h"
12 #include "tinyformat.h"
13 #include "uint256.h"
14 #include "util.h"
15 
16 #include <vector>
17 
19 {
20 public:
21  unsigned int nBlocks;
22  unsigned int nSize;
23  unsigned int nUndoSize;
24  unsigned int nHeightFirst;
25  unsigned int nHeightLast;
26  uint64_t nTimeFirst;
27  uint64_t nTimeLast;
28 
30 
31  template <typename Stream, typename Operation>
32  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
33  {
41  }
42 
43  void SetNull()
44  {
45  nBlocks = 0;
46  nSize = 0;
47  nUndoSize = 0;
48  nHeightFirst = 0;
49  nHeightLast = 0;
50  nTimeFirst = 0;
51  nTimeLast = 0;
52  }
53 
55  {
56  SetNull();
57  }
58 
59  std::string ToString() const;
60 
62  void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
63  {
64  if (nBlocks == 0 || nHeightFirst > nHeightIn)
65  nHeightFirst = nHeightIn;
66  if (nBlocks == 0 || nTimeFirst > nTimeIn)
67  nTimeFirst = nTimeIn;
68  nBlocks++;
69  if (nHeightIn > nHeightLast)
70  nHeightLast = nHeightIn;
71  if (nTimeIn > nTimeLast)
72  nTimeLast = nTimeIn;
73  }
74 };
75 
76 struct CDiskBlockPos {
77  int nFile;
78  unsigned int nPos;
79 
81 
82  template <typename Stream, typename Operation>
83  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
84  {
87  }
88 
90  {
91  SetNull();
92  }
93 
94  CDiskBlockPos(int nFileIn, unsigned int nPosIn)
95  {
96  nFile = nFileIn;
97  nPos = nPosIn;
98  }
99 
100  friend bool operator==(const CDiskBlockPos& a, const CDiskBlockPos& b)
101  {
102  return (a.nFile == b.nFile && a.nPos == b.nPos);
103  }
104 
105  friend bool operator!=(const CDiskBlockPos& a, const CDiskBlockPos& b)
106  {
107  return !(a == b);
108  }
109 
110  void SetNull()
111  {
112  nFile = -1;
113  nPos = 0;
114  }
115  bool IsNull() const { return (nFile == -1); }
116 };
117 
121 
124 
128 
135 
139 
142 
147 
151 
155 };
156 
163 {
164 public:
167 
170 
173 
176 
177  //ppcoin: trust score of block chain
179 
181  int nHeight;
182 
184  int nFile;
185 
187  unsigned int nDataPos;
188 
190  unsigned int nUndoPos;
191 
194 
197  unsigned int nTx;
198 
202  unsigned int nChainTx;
203 
205  unsigned int nStatus;
206 
207  unsigned int nFlags; // ppcoin: block index flags
208  enum {
209  BLOCK_PROOF_OF_STAKE = (1 << 0), // is proof-of-stake block
210  BLOCK_STAKE_ENTROPY = (1 << 1), // entropy bit for stake modifier
211  BLOCK_STAKE_MODIFIER = (1 << 2), // regenerated stake modifier
212  BLOCK_PROOF_OF_AUDIT = (1 << 3), //Added for PoA blocks
213  };
214 
215  // proof-of-stake specific fields
216  uint256 GetBlockTrust() const;
217  uint64_t nStakeModifier; // hash modifier for proof-of-stake
218  unsigned int nStakeModifierChecksum; // checksum of index; in-memeory only
220  unsigned int nStakeTime;
222  int64_t nMint;
223  int64_t nMoneySupply;
224 
226  int nVersion;
228  unsigned int nTime;
229  unsigned int nBits;
230  unsigned int nNonce;
232 
237 
239  uint32_t nSequenceId;
240 
241  void SetNull()
242  {
243  phashBlock = NULL;
244  pprev = NULL;
245  pskip = NULL;
246  nHeight = 0;
247  nFile = 0;
248  nDataPos = 0;
249  nUndoPos = 0;
250  nChainWork = 0;
251  nTx = 0;
252  nChainTx = 0;
253  nStatus = 0;
254  nSequenceId = 0;
255 
256  nMint = 0;
257  nMoneySupply = 0;
258  nFlags = 0;
259  nStakeModifier = 0;
262  nStakeTime = 0;
263 
264  nVersion = 0;
266  nTime = 0;
267  nBits = 0;
268  nNonce = 0;
270 
274  }
275 
277  {
278  SetNull();
279  }
280 
281  CBlockIndex(const CBlock& block)
282  {
283  SetNull();
284 
285  nVersion = block.nVersion;
287  nTime = block.nTime;
288  nBits = block.nBits;
289  nNonce = block.nNonce;
290  if(block.nVersion > 3)
292 
293  //Proof of Stake
295  nMint = 0;
296  nMoneySupply = 0;
297  nFlags = 0;
298  nStakeModifier = 0;
301 
302  if (block.IsProofOfAudit()) {
303  SetProofOfAudit();
305  minedHash = block.minedHash;
308  nStakeTime = 0;
309  } else if (block.IsProofOfStake()) {
310  SetProofOfStake();
311  prevoutStake = block.vtx[1].vin[0].prevout;
312  nStakeTime = block.nTime;
313  } else {
315  nStakeTime = 0;
316  }
317  }
318 
319 
321  {
322  CDiskBlockPos ret;
323  if (nStatus & BLOCK_HAVE_DATA) {
324  ret.nFile = nFile;
325  ret.nPos = nDataPos;
326  }
327  return ret;
328  }
329 
331  {
332  CDiskBlockPos ret;
333  if (nStatus & BLOCK_HAVE_UNDO) {
334  ret.nFile = nFile;
335  ret.nPos = nUndoPos;
336  }
337  return ret;
338  }
339 
341  {
342  CBlockHeader block;
343  block.nVersion = nVersion;
344  if (IsProofOfAudit()) {
346  block.minedHash = minedHash;
348  }
349  if (pprev)
350  block.hashPrevBlock = pprev->GetBlockHash();
352  block.nTime = nTime;
353  block.nBits = nBits;
354  block.nNonce = nNonce;
356  return block;
357  }
358 
360  {
361  return *phashBlock;
362  }
363 
364  int64_t GetBlockTime() const
365  {
366  return (int64_t)nTime;
367  }
368 
369  enum { nMedianTimeSpan = 11 };
370 
371  int64_t GetMedianTimePast() const
372  {
373  int64_t pmedian[nMedianTimeSpan];
374  int64_t* pbegin = &pmedian[nMedianTimeSpan];
375  int64_t* pend = &pmedian[nMedianTimeSpan];
376 
377  const CBlockIndex* pindex = this;
378  for (int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->pprev)
379  *(--pbegin) = pindex->GetBlockTime();
380 
381  std::sort(pbegin, pend);
382  return pbegin[(pend - pbegin) / 2];
383  }
384 
385  bool IsProofOfWork() const
386  {
387  return !(nFlags & BLOCK_PROOF_OF_STAKE) && !IsProofOfAudit();
388  }
389 
390  bool IsProofOfStake() const
391  {
392  return (nFlags & BLOCK_PROOF_OF_STAKE) && !IsProofOfAudit();
393  }
394 
396  {
398  }
399 
400  bool IsProofOfAudit() const {
401  return (nFlags & BLOCK_PROOF_OF_AUDIT);
402  }
403 
405  {
407  }
408 
409  unsigned int GetStakeEntropyBit() const
410  {
411  unsigned int nEntropyBit = ((GetBlockHash().GetCheapHash()) & 1);
412  if (GetBoolArg("-printstakemodifier", false))
413  LogPrintf("GetStakeEntropyBit: nHeight=%u hashBlock=%s nEntropyBit=%u\n", nHeight, GetBlockHash().ToString().c_str(), nEntropyBit);
414 
415  return nEntropyBit;
416  }
417 
418  bool SetStakeEntropyBit(unsigned int nEntropyBit)
419  {
420  if (nEntropyBit > 1)
421  return false;
422  nFlags |= (nEntropyBit ? BLOCK_STAKE_ENTROPY : 0);
423  return true;
424  }
425 
427  {
428  return (nFlags & BLOCK_STAKE_MODIFIER);
429  }
430 
431  void SetStakeModifier(uint64_t nModifier, bool fGeneratedStakeModifier)
432  {
433  nStakeModifier = nModifier;
434  if (fGeneratedStakeModifier)
436  }
437 
443  static bool IsSuperMajority(int minVersion, const CBlockIndex* pstart, unsigned int nRequired);
444 
445  std::string ToString() const
446  {
447  return strprintf("CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
448  pprev, nHeight,
450  GetBlockHash().ToString());
451  }
452 
455  {
456  assert(!(nUpTo & ~BLOCK_VALID_MASK)); // Only validity flags allowed.
458  return false;
459  return ((nStatus & BLOCK_VALID_MASK) >= nUpTo);
460  }
461 
464  bool RaiseValidity(enum BlockStatus nUpTo)
465  {
466  assert(!(nUpTo & ~BLOCK_VALID_MASK)); // Only validity flags allowed.
468  return false;
469  if ((nStatus & BLOCK_VALID_MASK) < nUpTo) {
470  nStatus = (nStatus & ~BLOCK_VALID_MASK) | nUpTo;
471  return true;
472  }
473  return false;
474  }
475 
477  void BuildSkip();
478 
480  CBlockIndex* GetAncestor(int height);
481  const CBlockIndex* GetAncestor(int height) const;
482 };
483 
486 {
487 public:
490 
492  {
495  }
496 
497  explicit CDiskBlockIndex(const CBlockIndex* pindex) : CBlockIndex(*pindex)
498  {
500  if (IsProofOfAudit()) {
502  minedHash = pindex->minedHash;
504  }
505  }
506 
508 
509  template <typename Stream, typename Operation>
510  inline void SerializationOp(Stream& s, Operation ser_action, int nType, int nVersion)
511  {
512  if (!(nType & SER_GETHASH))
514 
517  READWRITE(VARINT(nTx));
520  if (nStatus & BLOCK_HAVE_DATA)
522  if (nStatus & BLOCK_HAVE_UNDO)
524 
525 
526  READWRITE(nMint);
528  READWRITE(nFlags);
530 
531  if (IsProofOfStake()) {
534  } if (IsProofOfAudit()) {
538  } else {
539  const_cast<CDiskBlockIndex*>(this)->prevoutStake.SetNull();
540  const_cast<CDiskBlockIndex*>(this)->nStakeTime = 0;
541  const_cast<CDiskBlockIndex*>(this)->hashProofOfStake = UINT256_ZERO;
542  }
543 
544  // block header
545  READWRITE(this->nVersion);
549  READWRITE(nTime);
550  READWRITE(nBits);
551  READWRITE(nNonce);
552 
553  }
554 
556  {
557  CBlockHeader block;
558  block.nVersion = nVersion;
559  block.hashPrevBlock = hashPrev;
562  block.minedHash = minedHash;
563  block.nTime = nTime;
564  block.nBits = nBits;
565  block.nNonce = nNonce;
567  return block.GetHash();
568  }
569 
570 
571  std::string ToString() const
572  {
573  std::string str = "CDiskBlockIndex(";
574  str += CBlockIndex::ToString();
575  str += strprintf("\n hashBlock=%s, hashPrev=%s)",
577  hashPrev.ToString());
578  return str;
579  }
580 };
581 
583 class CChain
584 {
585 private:
586  std::vector<CBlockIndex*> vChain;
587 
588 public:
591  {
592  return vChain.size() > 0 ? vChain[0] : NULL;
593  }
594 
596  CBlockIndex* Tip(bool fProofOfStake = false) const
597  {
598  if (vChain.size() < 1)
599  return NULL;
600 
601  CBlockIndex* pindex = vChain[vChain.size() - 1];
602 
603  if (fProofOfStake) {
604  while (pindex && pindex->pprev && !pindex->IsProofOfStake())
605  pindex = pindex->pprev;
606  }
607  return pindex;
608  }
609 
611  CBlockIndex* operator[](int nHeight) const
612  {
613  if (nHeight < 0 || nHeight >= (int)vChain.size())
614  return NULL;
615  return vChain[nHeight];
616  }
617 
619  friend bool operator==(const CChain& a, const CChain& b)
620  {
621  return a.vChain.size() == b.vChain.size() &&
622  a.vChain[a.vChain.size() - 1] == b.vChain[b.vChain.size() - 1];
623  }
624 
626  bool Contains(const CBlockIndex* pindex) const
627  {
628  return (*this)[pindex->nHeight] == pindex;
629  }
630 
632  CBlockIndex* Next(const CBlockIndex* pindex) const
633  {
634  if (Contains(pindex))
635  return (*this)[pindex->nHeight + 1];
636  else
637  return NULL;
638  }
639 
641  int Height() const
642  {
643  return vChain.size() - 1;
644  }
645 
647  void SetTip(CBlockIndex* pindex);
648 
650  CBlockLocator GetLocator(const CBlockIndex* pindex = NULL) const;
651 
653  const CBlockIndex* FindFork(const CBlockIndex* pindex) const;
654 };
655 
656 #endif // BITCOIN_CHAIN_H
CBlockIndex::minedHash
uint256 minedHash
Definition: chain.h:235
CBlockIndex::GetBlockTime
int64_t GetBlockTime() const
Definition: chain.h:364
block.h
CBlockIndex::pnext
CBlockIndex * pnext
pointer to the index of the next block
Definition: chain.h:172
CBlockHeader::hashPoAMerkleRoot
uint256 hashPoAMerkleRoot
Definition: block.h:75
BLOCK_FAILED_CHILD
@ BLOCK_FAILED_CHILD
stage after last reached validness failed
Definition: chain.h:153
CDiskBlockPos::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
Definition: chain.h:80
UINT256_ZERO
const uint256 UINT256_ZERO
constant uint256 instances
Definition: uint256.h:129
CBlockIndex::BLOCK_PROOF_OF_AUDIT
@ BLOCK_PROOF_OF_AUDIT
Definition: chain.h:212
CBlockIndex::RaiseValidity
bool RaiseValidity(enum BlockStatus nUpTo)
Raise the validity level of this block index entry.
Definition: chain.h:464
CBlockIndex::IsProofOfStake
bool IsProofOfStake() const
Definition: chain.h:390
CBlockIndex::BLOCK_PROOF_OF_STAKE
@ BLOCK_PROOF_OF_STAKE
Definition: chain.h:209
CBlockFileInfo::nTimeFirst
uint64_t nTimeFirst
highest height of block in file
Definition: chain.h:26
CBlockIndex::nFile
int nFile
Which # file this block is stored in (blk?????.dat)
Definition: chain.h:184
CBlockIndex::nMint
int64_t nMint
Definition: chain.h:222
CBlockIndex::GetAncestor
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
Definition: main.cpp:4856
CBlockIndex::phashBlock
const uint256 * phashBlock
pointer to the hash of the block, if any. memory is owned by this CBlockIndex
Definition: chain.h:166
SER_GETHASH
@ SER_GETHASH
Definition: serialize.h:161
CBlockHeader::hashMerkleRoot
uint256 hashMerkleRoot
Definition: block.h:62
CBlockIndex::SetProofOfStake
void SetProofOfStake()
Definition: chain.h:395
CDiskBlockPos::SetNull
void SetNull()
Definition: chain.h:110
CBlockIndex::SetStakeEntropyBit
bool SetStakeEntropyBit(unsigned int nEntropyBit)
Definition: chain.h:418
CBlockHeader::nBits
uint32_t nBits
Definition: block.h:65
b
void const uint64_t * b
Definition: field_5x52_asm_impl.h:10
COutPoint::SetNull
void SetNull()
Definition: transaction.h:53
CBlockHeader
Nodes collect new transactions into a block, hash them into a hash tree, and scan through nonce value...
Definition: block.h:52
BLOCK_HAVE_DATA
@ BLOCK_HAVE_DATA
Definition: chain.h:148
CDiskBlockPos::CDiskBlockPos
CDiskBlockPos()
Definition: chain.h:89
CBlockIndex::nTx
unsigned int nTx
Number of transactions in this block.
Definition: chain.h:197
CBlockHeader::nVersion
int32_t nVersion
Definition: block.h:59
CBlockIndex::nMoneySupply
int64_t nMoneySupply
Definition: chain.h:223
BLOCK_FAILED_MASK
@ BLOCK_FAILED_MASK
descends from failed block
Definition: chain.h:154
CBlockIndex::nNonce
unsigned int nNonce
Definition: chain.h:230
uint256.h
CBlockIndex::pprev
CBlockIndex * pprev
pointer to the index of the predecessor of this block
Definition: chain.h:169
CBlockIndex::nStakeTime
unsigned int nStakeTime
Definition: chain.h:220
CBlockIndex::nHeight
int nHeight
height of the entry in the chain. The genesis block has height 0
Definition: chain.h:181
CDiskBlockPos::nFile
int nFile
Definition: chain.h:77
BLOCK_VALID_TREE
@ BLOCK_VALID_TREE
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
Definition: chain.h:127
CBlockIndex::GetStakeEntropyBit
unsigned int GetStakeEntropyBit() const
Definition: chain.h:409
CBlockIndex::SetNull
void SetNull()
Definition: chain.h:241
CBlockHeader::nAccumulatorCheckpoint
uint256 nAccumulatorCheckpoint
Definition: block.h:67
BLOCK_HAVE_MASK
@ BLOCK_HAVE_MASK
undo data available in rev*.dat
Definition: chain.h:150
CBlockIndex::ToString
std::string ToString() const
Definition: chain.h:445
CDiskBlockIndex::CDiskBlockIndex
CDiskBlockIndex(const CBlockIndex *pindex)
Definition: chain.h:497
CBlockIndex::nBits
unsigned int nBits
Definition: chain.h:229
CBlockIndex::nChainWork
uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
Definition: chain.h:193
BlockStatus
BlockStatus
Definition: chain.h:118
CBlockIndex::BLOCK_STAKE_ENTROPY
@ BLOCK_STAKE_ENTROPY
Definition: chain.h:210
CBlockIndex::nChainTx
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block.
Definition: chain.h:202
CBlockIndex::nDataPos
unsigned int nDataPos
Byte offset within blk?????.dat where this block's data is stored.
Definition: chain.h:187
CDiskBlockPos::operator!=
friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b)
Definition: chain.h:105
CDiskBlockIndex
Used to marshal pointers into hashes for db storage.
Definition: chain.h:485
CBlockIndex::nStatus
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
Definition: chain.h:205
CDiskBlockPos::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: chain.h:83
CBlockIndex::pskip
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
Definition: chain.h:175
BLOCK_FAILED_VALID
@ BLOCK_FAILED_VALID
Definition: chain.h:152
CDiskBlockIndex::hashNext
uint256 hashNext
Definition: chain.h:489
BLOCK_VALID_MASK
@ BLOCK_VALID_MASK
All validity bits.
Definition: chain.h:144
CBlockHeader::GetHash
uint256 GetHash() const
Definition: block.cpp:80
CChain::FindFork
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
Definition: chain.cpp:54
CBlockIndex::nFlags
unsigned int nFlags
Definition: chain.h:207
BLOCK_VALID_HEADER
@ BLOCK_VALID_HEADER
Parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, timestamp not in future.
Definition: chain.h:123
CDiskBlockPos::IsNull
bool IsNull() const
Definition: chain.h:115
CDiskBlockIndex::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
Definition: chain.h:507
tinyformat.h
CDiskBlockPos::CDiskBlockPos
CDiskBlockPos(int nFileIn, unsigned int nPosIn)
Definition: chain.h:94
CBlockIndex::nTime
unsigned int nTime
Definition: chain.h:228
base_uint::GetCheapHash
uint64_t GetCheapHash() const
Definition: arith_uint256.h:304
CBlockHeader::nNonce
uint32_t nNonce
Definition: block.h:66
CBlockIndex::GetBlockHeader
CBlockHeader GetBlockHeader() const
Definition: chain.h:340
BLOCK_VALID_TRANSACTIONS
@ BLOCK_VALID_TRANSACTIONS
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid,...
Definition: chain.h:134
CBlockFileInfo::nTimeLast
uint64_t nTimeLast
earliest time of block in file
Definition: chain.h:27
CBlockFileInfo::CBlockFileInfo
CBlockFileInfo()
Definition: chain.h:54
CBlockIndex::IsSuperMajority
static bool IsSuperMajority(int minVersion, const CBlockIndex *pstart, unsigned int nRequired)
Returns true if there are nRequired or more blocks of minVersion or above in the last Params()....
Definition: main.cpp:4829
CBlockIndex::hashPrevPoABlock
uint256 hashPrevPoABlock
Definition: chain.h:236
CBlockFileInfo::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: chain.h:32
BLOCK_VALID_UNKNOWN
@ BLOCK_VALID_UNKNOWN
Unused.
Definition: chain.h:120
CBlockFileInfo::nBlocks
unsigned int nBlocks
Definition: chain.h:21
CBlockIndex::GetMedianTimePast
int64_t GetMedianTimePast() const
Definition: chain.h:371
VARINT
#define VARINT(obj)
Definition: serialize.h:366
CBlockFileInfo::nHeightFirst
unsigned int nHeightFirst
number of used bytes in the undo file
Definition: chain.h:24
CBlockIndex::CBlockIndex
CBlockIndex()
Definition: chain.h:276
CBlockIndex::hashMerkleRoot
uint256 hashMerkleRoot
Definition: chain.h:227
CBlockIndex::IsValid
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
Definition: chain.h:454
CDiskBlockIndex::ToString
std::string ToString() const
Definition: chain.h:571
CBlockIndex::nMedianTimeSpan
@ nMedianTimeSpan
Definition: chain.h:369
GetBoolArg
bool GetBoolArg(const std::string &strArg, bool fDefault)
Return boolean argument or default value.
Definition: util.cpp:255
CDiskBlockPos
Definition: chain.h:76
LogPrintf
#define LogPrintf(...)
Definition: logging.h:147
CBlockIndex::IsProofOfWork
bool IsProofOfWork() const
Definition: chain.h:385
CBlockHeader::minedHash
uint256 minedHash
Definition: block.h:79
CBlockIndex::nStakeModifier
uint64_t nStakeModifier
Definition: chain.h:217
CBlockHeader::nTime
uint32_t nTime
Definition: block.h:64
CBlockIndex::prevoutStake
COutPoint prevoutStake
Definition: chain.h:219
uint256
256-bit unsigned big integer.
Definition: uint256.h:38
CBlockIndex::GeneratedStakeModifier
bool GeneratedStakeModifier() const
Definition: chain.h:426
CDiskBlockPos::operator==
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b)
Definition: chain.h:100
CBlockIndex::nVersion
int nVersion
block header
Definition: chain.h:226
CBlockFileInfo::nHeightLast
unsigned int nHeightLast
lowest height of block in file
Definition: chain.h:25
CBlockFileInfo::AddBlock
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
update statistics (does not update nSize)
Definition: chain.h:62
CBlockIndex::nStakeModifierChecksum
unsigned int nStakeModifierChecksum
Definition: chain.h:218
BLOCK_VALID_SCRIPTS
@ BLOCK_VALID_SCRIPTS
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
Definition: chain.h:141
CChain::SetTip
void SetTip(CBlockIndex *pindex)
Set/initialize a chain with a given tip.
Definition: chain.cpp:12
CBlockIndex::SetProofOfAudit
void SetProofOfAudit()
Definition: chain.h:404
CBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:359
CBlockIndex::BLOCK_STAKE_MODIFIER
@ BLOCK_STAKE_MODIFIER
Definition: chain.h:211
CChain::Height
int Height() const
Return the maximal height in the chain.
Definition: chain.h:641
CBlockFileInfo::ADD_SERIALIZE_METHODS
ADD_SERIALIZE_METHODS
latest time of block in file
Definition: chain.h:29
CBlockIndex::nAccumulatorCheckpoint
uint256 nAccumulatorCheckpoint
Definition: chain.h:231
CBlockHeader::hashPrevBlock
uint256 hashPrevBlock
Definition: block.h:61
CBlock::vtx
std::vector< CTransaction > vtx
Definition: block.h:146
CDiskBlockPos::nPos
unsigned int nPos
Definition: chain.h:78
CBlock
Definition: block.h:142
strprintf
#define strprintf
Definition: tinyformat.h:1056
CChain
An in-memory indexed chain of blocks.
Definition: chain.h:583
READWRITE
#define READWRITE(obj)
Definition: serialize.h:164
CChain::GetLocator
CBlockLocator GetLocator(const CBlockIndex *pindex=NULL) const
Return a CBlockLocator that refers to a block in this chain (by default the tip).
Definition: chain.cpp:25
CBlockIndex::GetBlockPos
CDiskBlockPos GetBlockPos() const
Definition: chain.h:320
CBlockIndex::nUndoPos
unsigned int nUndoPos
Byte offset within rev?????.dat where this block's undo data is stored.
Definition: chain.h:190
CBlockIndex::BuildSkip
void BuildSkip()
Build the skiplist pointer for this entry.
Definition: main.cpp:4884
CBlockFileInfo
Definition: chain.h:18
CChain::vChain
std::vector< CBlockIndex * > vChain
Definition: chain.h:586
CBlockIndex::nSequenceId
uint32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
Definition: chain.h:239
CBlockHeader::hashPrevPoABlock
uint256 hashPrevPoABlock
Definition: block.h:73
CChain::Contains
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Definition: chain.h:626
CBlockFileInfo::SetNull
void SetNull()
Definition: chain.h:43
CBlockFileInfo::nUndoSize
unsigned int nUndoSize
number of used bytes of block file
Definition: chain.h:23
CBlockIndex::hashPoAMerkleRoot
uint256 hashPoAMerkleRoot
PoA block header.
Definition: chain.h:234
CDiskBlockIndex::hashPrev
uint256 hashPrev
Definition: chain.h:488
CDiskBlockIndex::GetBlockHash
uint256 GetBlockHash() const
Definition: chain.h:555
CBlock::IsProofOfAudit
bool IsProofOfAudit() const
Definition: block.h:228
COutPoint
An outpoint - a combination of a transaction hash and an index n into its vout.
Definition: transaction.h:36
CBlockIndex::hashProofOfStake
uint256 hashProofOfStake
Definition: chain.h:221
CBlockIndex::CBlockIndex
CBlockIndex(const CBlock &block)
Definition: chain.h:281
CChain::Tip
CBlockIndex * Tip(bool fProofOfStake=false) const
Returns the index entry for the tip of this chain, or NULL if none.
Definition: chain.h:596
CBlockIndex::IsProofOfAudit
bool IsProofOfAudit() const
Definition: chain.h:400
CBlockFileInfo::ToString
std::string ToString() const
Definition: main.cpp:7226
CBlockIndex::bnChainTrust
uint256 bnChainTrust
Definition: chain.h:178
CDiskBlockIndex::CDiskBlockIndex
CDiskBlockIndex()
Definition: chain.h:491
CBlockLocator
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Definition: block.h:249
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:162
BLOCK_VALID_CHAIN
@ BLOCK_VALID_CHAIN
Outputs do not overspend inputs, no double spends, coinbase output ok, immature coinbase spends,...
Definition: chain.h:138
CBlockIndex::GetBlockTrust
uint256 GetBlockTrust() const
Definition: chain.cpp:66
CChain::operator[]
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or NULL if no such height exists.
Definition: chain.h:611
CBlockFileInfo::nSize
unsigned int nSize
number of blocks stored in file
Definition: chain.h:22
CBlockIndex::SetStakeModifier
void SetStakeModifier(uint64_t nModifier, bool fGeneratedStakeModifier)
Definition: chain.h:431
BLOCK_HAVE_UNDO
@ BLOCK_HAVE_UNDO
full block available in blk*.dat
Definition: chain.h:149
CBlockIndex::GetUndoPos
CDiskBlockPos GetUndoPos() const
Definition: chain.h:330
util.h
CChain::operator==
friend bool operator==(const CChain &a, const CChain &b)
Compare two chains efficiently.
Definition: chain.h:619
CChain::Next
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or NULL if the given index is not found or is the tip.
Definition: chain.h:632
CBlock::IsProofOfStake
bool IsProofOfStake() const
Definition: block.h:213
CChain::Genesis
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or NULL if none.
Definition: chain.h:590
CDiskBlockIndex::SerializationOp
void SerializationOp(Stream &s, Operation ser_action, int nType, int nVersion)
Definition: chain.h:510
base_uint::ToString
std::string ToString() const
Definition: arith_uint256.cpp:199