22 static const int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60;
23 static const int64_t MAX_FUTURE_BLOCK_TIME_DGW = MAX_FUTURE_BLOCK_TIME / 10;
31 static const int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME;
46 template <
typename Stream,
typename Operation>
74 void AddBlock(
unsigned int nHeightIn, uint64_t nTimeIn) {
75 if (nBlocks==0 || nHeightFirst > nHeightIn)
76 nHeightFirst = nHeightIn;
77 if (nBlocks==0 || nTimeFirst > nTimeIn)
80 if (nHeightIn > nHeightLast)
81 nHeightLast = nHeightIn;
82 if (nTimeIn > nTimeLast)
94 template <
typename Stream,
typename Operation>
118 bool IsNull()
const {
return (nFile == -1); }
122 return strprintf(
"CBlockDiskPos(nFile=%i, nPos=%i)", nFile, nPos);
226 phashBlock =
nullptr;
301 return (int64_t)nTime;
306 return (int64_t)nTimeMax;
309 enum { nMedianTimeSpan=11 };
313 int64_t pmedian[nMedianTimeSpan];
314 int64_t* pbegin = &pmedian[nMedianTimeSpan];
315 int64_t* pend = &pmedian[nMedianTimeSpan];
318 for (
int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->
pprev)
321 std::sort(pbegin, pend);
322 return pbegin[(pend - pbegin)/2];
327 return strprintf(
"CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
330 GetBlockHash().ToString());
350 nStatus = (nStatus & ~BLOCK_VALID_MASK) | nUpTo;
382 hashPrev = (pprev ? pprev->GetBlockHash() :
uint256());
387 template <
typename Stream,
typename Operation>
389 int _nVersion = s.GetVersion();
427 std::string str =
"CDiskBlockIndex(";
429 str +=
strprintf(
"\n hashBlock=%s, hashPrev=%s)",
444 return vChain.size() > 0 ? vChain[0] :
nullptr;
449 return vChain.size() > 0 ? vChain[vChain.size() - 1] :
nullptr;
454 if (nHeight < 0 || nHeight >= (
int)vChain.size())
456 return vChain[nHeight];
467 return (*
this)[pindex->
nHeight] == pindex;
472 if (Contains(pindex))
473 return (*
this)[pindex->
nHeight + 1];
480 return vChain.size() - 1;
493 CBlockIndex* FindEarliestAtLeast(int64_t nTime)
const;
496 #endif // RAVEN_CHAIN_H
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
CDiskBlockPos GetBlockPos() const
std::string ToString() const
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
std::vector< CBlockIndex * > vChain
CDiskBlockPos(int nFileIn, unsigned int nPosIn)
int64_t GetBlockTime() const
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
descends from failed block
CBlockIndex * pprev
pointer to the index of the predecessor of this block
uint32_t nStatus
Verification status of this block. See enum BlockStatus.
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
update statistics (does not update nSize)
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the forking point between two chain tips.
An in-memory indexed chain of blocks.
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
CBlockHeader GetBlockHeader() const
int Height() const
Return the maximal height in the chain.
stage after last reached validness failed
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid...
unsigned int nSize
number of used bytes of block file
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b)
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
undo data available in rev*.dat
int nFile
Which # file this block is stored in (blk?????.dat)
unsigned int nHeightLast
highest height of block in file
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block. ...
unsigned int nUndoSize
number of used bytes in the undo file
friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b)
uint256 GetBlockHash() const
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
arith_uint256 GetBlockProof(const CBlockIndex &block)
Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends...
unsigned int nTimeMax
(memory only) Maximum nTime in the chain up to and including this block.
uint64_t nTimeFirst
earliest time of block in file
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or nullptr if no such height exists...
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
void SerializationOp(Stream &s, Operation ser_action)
unsigned int nDataPos
Byte offset within blk?????.dat where this block's data is stored.
Parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, timestamp not in future...
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
CBlockIndex(const CBlockHeader &block)
CBlockIndex * Next(const CBlockIndex *pindex) const
Find the successor of a block in this chain, or nullptr if the given index is not found or is the tip...
int64_t GetBlockTimeMax() const
friend bool operator==(const CChain &a, const CChain &b)
Compare two chains efficiently.
unsigned int nHeightFirst
lowest height of block in file
std::string ToString() const
Used to marshal pointers into hashes for db storage.
std::string ToString() const
Parameters that influence chain consensus.
256-bit unsigned big integer.
int64_t GetMedianTimePast() const
block data in blk*.data was received with a witness-enforcing client
void SerializationOp(Stream &s, Operation ser_action)
int64_t GetBlockProofEquivalentTime(const CBlockIndex &to, const CBlockIndex &from, const CBlockIndex &tip, const Consensus::Params &)
Return the time it would take to redo the work difference between from and to, assuming the current h...
unsigned int nUndoPos
Byte offset within rev?????.dat where this block's undo data is stored.
int32_t nVersion
block header
void SerializationOp(Stream &s, Operation ser_action)
CDiskBlockIndex(const CBlockIndex *pindex)
The block chain is a tree shaped structure starting with the genesis block at the root...
CDiskBlockPos GetUndoPos() const
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
unsigned int nBlocks
number of blocks stored in file
std::string ToString() const
bool RaiseValidity(enum BlockStatus nUpTo)
Raise the validity level of this block index entry.
uint64_t nTimeLast
latest time of block in file
int nHeight
height of the entry in the chain. The genesis block has height 0
full block available in blk*.dat
uint256 GetBlockHash() const
std::string ToString() const
unsigned int nTx
Number of transactions in this block.
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex