Bitcoin ABC 0.31.0
P2P Digital Currency
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
CBlockIndex Class Reference

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. More...

#include <blockindex.h>

Inheritance diagram for CBlockIndex:
[legend]
Collaboration diagram for CBlockIndex:
[legend]

Public Member Functions

int nFile GUARDED_BY (::cs_main)
 Which # file this block is stored in (blk?????.dat) More...
 
unsigned int nDataPos GUARDED_BY (::cs_main)
 Byte offset within blk?????.dat where this block's data is stored. More...
 
unsigned int nUndoPos GUARDED_BY (::cs_main)
 Byte offset within rev?????.dat where this block's undo data is stored. More...
 
BlockStatus nStatus GUARDED_BY (::cs_main)
 Verification status of this block. See enum BlockStatus. More...
 
 CBlockIndex ()=default
 
 CBlockIndex (const CBlockHeader &block)
 
FlatFilePos GetBlockPos () const EXCLUSIVE_LOCKS_REQUIRED(
 
FlatFilePos GetUndoPos () const EXCLUSIVE_LOCKS_REQUIRED(
 
CBlockHeader GetBlockHeader () const
 
BlockHash GetBlockHash () const
 
int64_t GetChainTxCount () const
 Get the number of transaction in the chain so far. More...
 
void ResetChainStats ()
 Reset chain tx stats. More...
 
void MaybeResetChainStats (bool is_snapshot_base_block)
 Reset chain tx stats and log a warning if the block is not the snapshot block, and the nChainTx value is not zero or the correct value. More...
 
bool UpdateChainStats ()
 Update chain tx stats and return True if this block is the genesis block or all parents have their tx stats set. More...
 
bool HaveNumChainTxs () const
 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. More...
 
NodeSeconds Time () const
 
int64_t GetBlockTime () const
 
int64_t GetBlockTimeMax () const
 
int64_t GetHeaderReceivedTime () const
 
int64_t GetReceivedTimeDiff () const
 
int64_t GetMedianTimePast () const
 
std::string ToString () const
 
bool IsValid (enum BlockValidity nUpTo=BlockValidity::TRANSACTIONS) const EXCLUSIVE_LOCKS_REQUIRED(
 Check whether this block index entry is valid up to the passed validity level. More...
 
bool RaiseValidity (enum BlockValidity nUpTo) EXCLUSIVE_LOCKS_REQUIRED(
 Raise the validity level of this block index entry. More...
 
void BuildSkip ()
 Build the skiplist pointer for this entry. More...
 
CBlockIndexGetAncestor (int height)
 Efficiently find an ancestor of this block. More...
 
const CBlockIndexGetAncestor (int height) const
 

Public Attributes

const BlockHashphashBlock {nullptr}
 pointer to the hash of the block, if any. More...
 
CBlockIndexpprev {nullptr}
 pointer to the index of the predecessor of this block More...
 
CBlockIndexpskip {nullptr}
 pointer to the index of some further predecessor of this block More...
 
int nHeight {0}
 height of the entry in the chain. The genesis block has height 0 More...
 
arith_uint256 nChainWork {}
 (memory only) Total amount of work (expected number of hashes) in the chain up to and including this block More...
 
unsigned int nTx {0}
 Number of transactions in this block. More...
 
unsigned int nSize {0}
 Size of this block. More...
 
unsigned int nChainTx {0}
 (memory only) Number of transactions in the chain up to and including this block. More...
 
int32_t nVersion {0}
 block header More...
 
uint256 hashMerkleRoot {}
 
uint32_t nTime {0}
 
uint32_t nBits {0}
 
uint32_t nNonce {0}
 
int32_t nSequenceId {0}
 (memory only) Sequential id assigned to distinguish order in which blocks are received. More...
 
int64_t nTimeReceived {0}
 (memory only) block header metadata More...
 
unsigned int nTimeMax {0}
 (memory only) Maximum nTime in the chain up to and including this block. More...
 

Static Public Attributes

static constexpr int nMedianTimeSpan = 11
 

Detailed Description

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.

Definition at line 25 of file blockindex.h.

Constructor & Destructor Documentation

◆ CBlockIndex() [1/2]

CBlockIndex::CBlockIndex ( )
explicitdefault

◆ CBlockIndex() [2/2]

CBlockIndex::CBlockIndex ( const CBlockHeader block)
inlineexplicit

Definition at line 92 of file blockindex.h.

Member Function Documentation

◆ BuildSkip()

void CBlockIndex::BuildSkip ( )

Build the skiplist pointer for this entry.

Definition at line 107 of file blockindex.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAncestor() [1/2]

CBlockIndex * CBlockIndex::GetAncestor ( int  height)

Efficiently find an ancestor of this block.

Definition at line 102 of file blockindex.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetAncestor() [2/2]

const CBlockIndex * CBlockIndex::GetAncestor ( int  height) const

Definition at line 76 of file blockindex.cpp.

Here is the call graph for this function:

◆ GetBlockHash()

BlockHash CBlockIndex::GetBlockHash ( ) const
inline

Definition at line 130 of file blockindex.h.

Here is the call graph for this function:

◆ GetBlockHeader()

CBlockHeader CBlockIndex::GetBlockHeader ( ) const
inline

Definition at line 117 of file blockindex.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBlockPos()

FlatFilePos CBlockIndex::GetBlockPos ( ) const
inline

Definition at line 97 of file blockindex.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetBlockTime()

int64_t CBlockIndex::GetBlockTime ( ) const
inline

Definition at line 179 of file blockindex.h.

Here is the caller graph for this function:

◆ GetBlockTimeMax()

int64_t CBlockIndex::GetBlockTimeMax ( ) const
inline

Definition at line 181 of file blockindex.h.

Here is the caller graph for this function:

◆ GetChainTxCount()

int64_t CBlockIndex::GetChainTxCount ( ) const
inline

Get the number of transaction in the chain so far.

Definition at line 138 of file blockindex.h.

Here is the caller graph for this function:

◆ GetHeaderReceivedTime()

int64_t CBlockIndex::GetHeaderReceivedTime ( ) const
inline

Definition at line 183 of file blockindex.h.

Here is the caller graph for this function:

◆ GetMedianTimePast()

int64_t CBlockIndex::GetMedianTimePast ( ) const
inline

Definition at line 191 of file blockindex.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetReceivedTimeDiff()

int64_t CBlockIndex::GetReceivedTimeDiff ( ) const
inline

Definition at line 185 of file blockindex.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetUndoPos()

FlatFilePos CBlockIndex::GetUndoPos ( ) const
inline

Definition at line 107 of file blockindex.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GUARDED_BY() [1/4]

int nFile CBlockIndex::GUARDED_BY ( ::cs_main  )
inline

Which # file this block is stored in (blk?????.dat)

Definition at line 41 of file blockindex.h.

◆ GUARDED_BY() [2/4]

unsigned int nDataPos CBlockIndex::GUARDED_BY ( ::cs_main  )
inline

Byte offset within blk?????.dat where this block's data is stored.

Definition at line 44 of file blockindex.h.

◆ GUARDED_BY() [3/4]

unsigned int nUndoPos CBlockIndex::GUARDED_BY ( ::cs_main  )
inline

Byte offset within rev?????.dat where this block's undo data is stored.

Definition at line 47 of file blockindex.h.

◆ GUARDED_BY() [4/4]

BlockStatus nStatus CBlockIndex::GUARDED_BY ( ::cs_main  )
inline

Verification status of this block. See enum BlockStatus.

Definition at line 71 of file blockindex.h.

◆ HaveNumChainTxs()

bool CBlockIndex::HaveNumChainTxs ( ) const
inline

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.

Does not imply the transactions are consensus-valid (ConnectTip might fail) Does not imply the transactions are still stored on disk. (IsBlockPruned might return true)

Note that this will be true for the snapshot base block, if one is loaded, since its nChainTx value will have been set manually based on the related AssumeutxoData entry.

Definition at line 173 of file blockindex.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsValid()

bool CBlockIndex::IsValid ( enum BlockValidity  nUpTo = BlockValidity::TRANSACTIONS) const
inline

Check whether this block index entry is valid up to the passed validity level.

Definition at line 210 of file blockindex.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ MaybeResetChainStats()

void CBlockIndex::MaybeResetChainStats ( bool  is_snapshot_base_block)

Reset chain tx stats and log a warning if the block is not the snapshot block, and the nChainTx value is not zero or the correct value.

Don't modify the value otherwise.

Definition at line 40 of file blockindex.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RaiseValidity()

bool CBlockIndex::RaiseValidity ( enum BlockValidity  nUpTo)
inline

Raise the validity level of this block index entry.

Returns true if the validity was changed.

Definition at line 218 of file blockindex.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ResetChainStats()

void CBlockIndex::ResetChainStats ( )

Reset chain tx stats.

Definition at line 36 of file blockindex.cpp.

Here is the caller graph for this function:

◆ Time()

NodeSeconds CBlockIndex::Time ( ) const
inline

Definition at line 175 of file blockindex.h.

◆ ToString()

std::string CBlockIndex::ToString ( ) const

Definition at line 30 of file blockindex.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UpdateChainStats()

bool CBlockIndex::UpdateChainStats ( )

Update chain tx stats and return True if this block is the genesis block or all parents have their tx stats set.

Else, do nothing and return False.

Definition at line 56 of file blockindex.cpp.

Here is the caller graph for this function:

Member Data Documentation

◆ hashMerkleRoot

uint256 CBlockIndex::hashMerkleRoot {}

Definition at line 75 of file blockindex.h.

◆ nBits

uint32_t CBlockIndex::nBits {0}

Definition at line 77 of file blockindex.h.

◆ nChainTx

unsigned int CBlockIndex::nChainTx {0}

(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. Change to 64-bit type when necessary; won't happen before 2030

Definition at line 68 of file blockindex.h.

◆ nChainWork

arith_uint256 CBlockIndex::nChainWork {}

(memory only) Total amount of work (expected number of hashes) in the chain up to and including this block

Definition at line 51 of file blockindex.h.

◆ nHeight

int CBlockIndex::nHeight {0}

height of the entry in the chain. The genesis block has height 0

Definition at line 38 of file blockindex.h.

◆ nMedianTimeSpan

constexpr int CBlockIndex::nMedianTimeSpan = 11
staticconstexpr

Definition at line 189 of file blockindex.h.

◆ nNonce

uint32_t CBlockIndex::nNonce {0}

Definition at line 78 of file blockindex.h.

◆ nSequenceId

int32_t CBlockIndex::nSequenceId {0}

(memory only) Sequential id assigned to distinguish order in which blocks are received.

Definition at line 82 of file blockindex.h.

◆ nSize

unsigned int CBlockIndex::nSize {0}

Size of this block.

Note: in a potential headers-first mode, this number cannot be relied upon

Definition at line 60 of file blockindex.h.

◆ nTime

uint32_t CBlockIndex::nTime {0}

Definition at line 76 of file blockindex.h.

◆ nTimeMax

unsigned int CBlockIndex::nTimeMax {0}

(memory only) Maximum nTime in the chain up to and including this block.

Definition at line 88 of file blockindex.h.

◆ nTimeReceived

int64_t CBlockIndex::nTimeReceived {0}

(memory only) block header metadata

Definition at line 85 of file blockindex.h.

◆ nTx

unsigned int CBlockIndex::nTx {0}

Number of transactions in this block.

This will be nonzero if the block reached the VALID_TRANSACTIONS level, and zero otherwise.

Definition at line 55 of file blockindex.h.

◆ nVersion

int32_t CBlockIndex::nVersion {0}

block header

Definition at line 74 of file blockindex.h.

◆ phashBlock

const BlockHash* CBlockIndex::phashBlock {nullptr}

pointer to the hash of the block, if any.

Memory is owned by this CBlockIndex

Definition at line 29 of file blockindex.h.

◆ pprev

CBlockIndex* CBlockIndex::pprev {nullptr}

pointer to the index of the predecessor of this block

Definition at line 32 of file blockindex.h.

◆ pskip

CBlockIndex* CBlockIndex::pskip {nullptr}

pointer to the index of some further predecessor of this block

Definition at line 35 of file blockindex.h.


The documentation for this class was generated from the following files: