6 #ifndef BITCOIN_CHAIN_H
7 #define BITCOIN_CHAIN_H
31 template <
typename Stream,
typename Operation>
59 void AddBlock(
unsigned int nHeightIn, uint64_t nTimeIn) {
79 template <
typename Stream,
typename Operation>
275 return (int64_t)
nTime;
295 std::sort(pbegin, pend);
296 return pbegin[(pend - pbegin)/2];
301 return strprintf(
"CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
382 template <
typename Stream,
typename Operation>
422 std::string str =
"CDiskBlockIndex(";
424 str +=
strprintf(
"\n hashBlock=%s, hashPrev=%s)",
449 if (nHeight < 0 || nHeight >= (
int)
vChain.size())
462 return (*
this)[pindex->
nHeight] == pindex;
468 return (*
this)[pindex->
nHeight + 1];
@ BLOCK_VALID_CHAIN
Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends,...
@ BLOCK_VALID_MASK
All validity bits.
@ BLOCK_VALID_TRANSACTIONS
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid,...
@ BLOCK_VALID_SCRIPTS
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
@ BLOCK_VALID_TREE
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
@ BLOCK_HAVE_UNDO
undo data available in rev*.dat
@ BLOCK_HAVE_DATA
full block available in blk*.dat
@ BLOCK_FAILED_CHILD
descends from failed block
@ BLOCK_VALID_HEADER
Parsed, version ok, hash satisfies claimed PoW, 1 <= vtx count <= max, timestamp not in future.
@ BLOCK_FAILED_VALID
stage after last reached validness failed
@ BLOCK_OPT_WITNESS
block data in blk*.data was received with a witness-enforcing client
@ BLOCK_VALID_UNKNOWN
Unused.
arith_uint256 GetBlockProof(const CBlockIndex &block)
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...
uint64_t nTimeFirst
earliest time of block in file
uint64_t nTimeLast
latest time of block in file
std::string ToString() const
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
update statistics (does not update nSize)
unsigned int nHeightFirst
lowest height of block in file
void SerializationOp(Stream &s, Operation ser_action)
unsigned int nHeightLast
highest height of block in file
unsigned int nUndoSize
number of used bytes in the undo file
unsigned int nBlocks
number of blocks stored in file
unsigned int nSize
number of used bytes of block file
The block chain is a tree shaped structure starting with the genesis block at the root,...
bool RaiseValidity(enum BlockStatus nUpTo)
Raise the validity level of this block index entry.
std::string ToString() const
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void BuildSkip()
Build the skiplist pointer for this entry.
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
int32_t GetChainId() const
Extract the chain ID.
int nFile
Which # file this block is stored in (blk?????.dat)
CBlockHeader GetBlockHeader(const Consensus::Params &consensusParams, bool fCheckPOW=true) const
int GetBaseVersion() const
unsigned int nTimeMax
(memory only) Maximum nTime in the chain upto and including this block.
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
unsigned int nUndoPos
Byte offset within rev?????.dat where this block's undo data is stored.
uint256 GetBlockHash() const
int64_t GetBlockTime() const
CDiskBlockPos GetUndoPos() const
bool IsAuxpow() const
Check if the auxpow flag is set in the version.
int64_t GetMedianTimePast() const
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
int64_t GetBlockTimeMax() const
unsigned int nStatus
Verification status of this block. See enum BlockStatus.
unsigned int nTx
Number of transactions in this block.
CBlockIndex(const CBlockHeader &block)
CDiskBlockPos GetBlockPos() const
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
unsigned int nDataPos
Byte offset within blk?????.dat where this block's data is stored.
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block.
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
An in-memory indexed chain of blocks.
CBlockLocator GetLocator(const CBlockIndex *pindex=NULL) const
Return a CBlockLocator that refers to a block in this chain (by default the tip).
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or NULL if none.
friend bool operator==(const CChain &a, const CChain &b)
Compare two chains efficiently.
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or NULL if no such height exists.
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.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or NULL if none.
int Height() const
Return the maximal height in the chain.
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
std::vector< CBlockIndex * > vChain
void SetTip(CBlockIndex *pindex)
Set/initialize a chain with a given tip.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
CBlockIndex * FindEarliestAtLeast(int64_t nTime) const
Find the earliest block with timestamp equal or greater than the given.
Used to marshal pointers into hashes for db storage.
void SerializationOp(Stream &s, Operation ser_action)
std::string ToString() const
CDiskBlockIndex(const CBlockIndex *pindex)
uint256 GetBlockHash() const
256-bit unsigned big integer.
std::string ToString() const
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
friend bool operator==(const CDiskBlockPos &a, const CDiskBlockPos &b)
CDiskBlockPos(int nFileIn, unsigned int nPosIn)
void SerializationOp(Stream &s, Operation ser_action)
std::string ToString() const
friend bool operator!=(const CDiskBlockPos &a, const CDiskBlockPos &b)
Parameters that influence chain consensus.