CBlockIndex

The block chain is a tree shaped structure starting with the genesis block at the root, with each block potentially having multiple candidates to be the next block. A blockindex may have multiple pprev pointing to it, but at most one of them can be part of the currently active branch.

Synopsis

Declared in <chain.h>

class CBlockIndex;

Member Functions

NameDescription
CBlockIndex [constructor]Constructors
~CBlockIndex [destructor]Destroys the block index entry.
BuildSkip Build the skiplist pointer for this entry.
GetAncestor GetAncestor overloads
GetBlockHash Returns the hash of this block.
GetBlockHeader Reconstructs the block header for this entry.
GetBlockPos Returns the on-disk position of this block's data.
GetBlockTime Returns this block's timestamp.
GetBlockTimeMax Returns the maximum timestamp seen in the chain up to and including this block.
GetMedianTimePast Returns the median timestamp of the previous nMedianTimeSpan blocks.
GetUndoPos Returns the on-disk position of this block's undo data.
HaveNumChainTxs Check whether this block and all previous blocks back to the genesis block or an assumeutxo snapshot block have reached VALID_TRANSACTIONS and had transactions downloaded (and stored to disk) at some point.
IsValid Check whether this block index entry is valid up to the passed validity level.
RaiseValidity Raise the validity level of this block index entry. Returns true if the validity was changed.
Time Returns this block's timestamp as a time point.
ToString Returns a human-readable description of this block index entry.

Data Members

NameDescription
hashMerkleRoot Merkle root of the block's transactions
m_chain_tx_count (memory only) Number of transactions in the chain up to and including this block. This value will be non-zero if this block and all previous blocks back to the genesis block or an assumeutxo snapshot block have reached the VALID_TRANSACTIONS level.
nBits Compact-encoded proof-of-work difficulty target
nChainWork (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block
nDataPos Byte offset within blk?????.dat where this block's data is stored
nFile Which # file this block is stored in (blk?????.dat)
nHeight height of the entry in the chain. The genesis block has height 0
nNonce Proof-of-work nonce
nSequenceId (memory only) Sequential id assigned to distinguish order in which blocks are received. Initialized to SEQ_ID_INIT_FROM_DISK{1} when loading blocks from disk, except for blocks belonging to the best chain which overwrite it to SEQ_ID_BEST_CHAIN_FROM_DISK{0}.
nStatus Verification status of this block. See enum BlockStatus
nTime Block timestamp, in seconds since the Unix epoch
nTimeMax (memory only) Maximum nTime in the chain up to and including this block.
nTx Number of transactions in this block. This will be nonzero if the block reached the VALID_TRANSACTIONS level, and zero otherwise. Note: in a potential headers-first mode, this number cannot be relied upon
nUndoPos Byte offset within rev?????.dat where this block's undo data is stored
nVersion block header
phashBlock pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
pprev pointer to the index of the predecessor of this block
pskip pointer to the index of some further predecessor of this block

Static Data Members

NameDescription
nMedianTimeSpan Number of blocks considered when computing the median time past.

Protected Member Functions

NameDescription
CBlockIndex [constructor]Constructors
operator= Assignment operators

Non-Member Functions

NameDescription
CalculateLockPointsAtTipCalculate LockPoints required to check if transaction will be BIP68 final in the next block to be created on top of tip.
CalculateNextWorkRequiredCompute the retargeted proof-of-work target after a difficulty adjustment interval.
CheckFinalTxAtTipCheck if transaction will be final in the next block to be created.
CheckSequenceLocksAtTipCheck if transaction will be BIP68 final in the next block to be created on top of tip.
DeploymentActiveAfterDetermine if a deployment is active for the next block
DeploymentActiveAfterDetermine if a version-bits deployment is active for the next block.
DeploymentActiveAfterWhether a deployment is active after the given block, resolved via ChainstateManager.
DeploymentActiveAtDetermine if a version-bits deployment is active for this block.
DeploymentActiveAtWhether a deployment is active at the given block, resolved via ChainstateManager.
DeploymentActiveAtDetermine if a deployment is active for this block
EvaluateSequenceLocksChecks whether previously computed sequence locks are satisfied by a block.
GetBlockProofCompute how much work a block index entry corresponds to.
GetBlockProofEquivalentTimeReturn the time it would take to redo the work difference between from and to, assuming the current hashrate corresponds to the difficulty at tip, in seconds.
GetBlockScriptFlagsReturn the script flags which should be checked for a given block.
GetDifficultyGet the difficulty of the net wrt to the given block index.
GetLocatorGet a locator for a block index entry.
GetNextWorkRequiredCompute the proof-of-work target (nBits) required for the block following pindexLast.
GetTarget* Get the target for a given block index.
IsBIP30RepeatIdentifies blocks that overwrote an existing coinbase output in the UTXO set (see BIP30).
LastCommonAncestorFind the forking point between two chain tips.
LocatorEntriesConstruct a list of hash entries to put in a locator.
NextEmptyBlockIndexReturn an empty block index on top of the tip, with height, time and nBits set
blockheaderToJSONBlock header to JSON
kernel::MakeBlockInfoBuilds block metadata from a block index entry.
node::GetMinimumTimeGet the minimum time a miner should use in the next block. This always accounts for the BIP94 timewarp rule, so does not necessarily reflect the consensus limit.
node::GetTransactionReturn transaction with a given hash. If mempool is provided and block_index is not provided, check it first for the tx. If -txindex is available, check it next for the tx. Finally, if block_index is provided, check for tx by reading entire block from disk.

Derived Classes

NameDescription
CDiskBlockIndex Used to marshal pointers into hashes for db storage.