Bitcoin Core  26.99.0
P2P Digital Currency
Classes | Enumerations | Functions | Variables
chain.h File Reference
#include <arith_uint256.h>
#include <consensus/params.h>
#include <flatfile.h>
#include <kernel/cs_main.h>
#include <primitives/block.h>
#include <sync.h>
#include <uint256.h>
#include <util/time.h>
#include <vector>
Include dependency graph for chain.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  CBlockFileInfo
 
class  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. More...
 
class  CDiskBlockIndex
 Used to marshal pointers into hashes for db storage. More...
 
class  CChain
 An in-memory indexed chain of blocks. More...
 

Enumerations

enum  BlockStatus : uint32_t {
  BLOCK_VALID_UNKNOWN = 0 , BLOCK_VALID_RESERVED = 1 , BLOCK_VALID_TREE = 2 , BLOCK_VALID_TRANSACTIONS = 3 ,
  BLOCK_VALID_CHAIN = 4 , BLOCK_VALID_SCRIPTS = 5 , BLOCK_VALID_MASK , BLOCK_HAVE_DATA = 8 ,
  BLOCK_HAVE_UNDO = 16 , BLOCK_HAVE_MASK = BLOCK_HAVE_DATA | BLOCK_HAVE_UNDO , BLOCK_FAILED_VALID = 32 , BLOCK_FAILED_CHILD = 64 ,
  BLOCK_FAILED_MASK = BLOCK_FAILED_VALID | BLOCK_FAILED_CHILD , BLOCK_OPT_WITNESS = 128 , BLOCK_ASSUMED_VALID = 256
}
 

Functions

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 hashrate corresponds to the difficulty at tip, in seconds. More...
 
const CBlockIndexLastCommonAncestor (const CBlockIndex *pa, const CBlockIndex *pb)
 Find the forking point between two chain tips. More...
 
CBlockLocator GetLocator (const CBlockIndex *index)
 Get a locator for a block index entry. More...
 
std::vector< uint256LocatorEntries (const CBlockIndex *index)
 Construct a list of hash entries to put in a locator. More...
 

Variables

static constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60
 Maximum amount of time that a block timestamp is allowed to exceed the current network-adjusted time before the block will be accepted. More...
 
static constexpr int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME
 Timestamp window used as a grace period by code that compares external timestamps (such as timestamps passed to RPCs, or wallet key creation times) to block timestamps. More...
 
static constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 60
 Maximum gap between node time and block time used for the "Catching up..." mode in GUI. More...
 

Enumeration Type Documentation

◆ BlockStatus

enum BlockStatus : uint32_t
Enumerator
BLOCK_VALID_UNKNOWN 

Unused.

BLOCK_VALID_RESERVED 

Reserved (was BLOCK_VALID_HEADER).

BLOCK_VALID_TREE 

All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.

Implies all parents are also at least TREE.

BLOCK_VALID_TRANSACTIONS 

Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid, no duplicate txids, sigops, size, merkle root.

Implies all parents are at least TREE but not necessarily TRANSACTIONS. When all parent blocks also have TRANSACTIONS, CBlockIndex::nChainTx will be set.

BLOCK_VALID_CHAIN 

Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends, BIP30.

Implies all parents are either at least VALID_CHAIN, or are ASSUMED_VALID

BLOCK_VALID_SCRIPTS 

Scripts & signatures ok. Implies all parents are either at least VALID_SCRIPTS, or are ASSUMED_VALID.

BLOCK_VALID_MASK 

All validity bits.

BLOCK_HAVE_DATA 

full block available in blk*.dat

BLOCK_HAVE_UNDO 

undo data available in rev*.dat

BLOCK_HAVE_MASK 
BLOCK_FAILED_VALID 

stage after last reached validness failed

BLOCK_FAILED_CHILD 

descends from failed block

BLOCK_FAILED_MASK 
BLOCK_OPT_WITNESS 

block data in blk*.dat was received with a witness-enforcing client

BLOCK_ASSUMED_VALID 

If ASSUMED_VALID is set, it means that this block has not been validated and has validity status less than VALID_SCRIPTS.

Also that it may have descendant blocks with VALID_SCRIPTS set, because they can be validated based on an assumeutxo snapshot.

When an assumeutxo snapshot is loaded, the ASSUMED_VALID flag is added to unvalidated blocks at the snapshot height and below. Then, as the background validation progresses, and these blocks are validated, the ASSUMED_VALID flags are removed. See doc/design/assumeutxo.md for details.

This flag is only used to implement checks in CheckBlockIndex() and should not be used elsewhere.

Definition at line 83 of file chain.h.

Function Documentation

◆ GetBlockProof()

arith_uint256 GetBlockProof ( const CBlockIndex block)

Definition at line 131 of file chain.cpp.

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

◆ GetBlockProofEquivalentTime()

int64_t GetBlockProofEquivalentTime ( const CBlockIndex to,
const CBlockIndex from,
const CBlockIndex tip,
const Consensus::Params params 
)

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

Definition at line 146 of file chain.cpp.

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

◆ GetLocator()

CBlockLocator GetLocator ( const CBlockIndex index)

Get a locator for a block index entry.

Definition at line 50 of file chain.cpp.

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

◆ LastCommonAncestor()

const CBlockIndex* LastCommonAncestor ( const CBlockIndex pa,
const CBlockIndex pb 
)

Find the forking point between two chain tips.

Find the forking point between two chain tips.

Both pa and pb must be non-nullptr.

Definition at line 165 of file chain.cpp.

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

◆ LocatorEntries()

std::vector<uint256> LocatorEntries ( const CBlockIndex index)

Construct a list of hash entries to put in a locator.


Definition at line 31 of file chain.cpp.

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

Variable Documentation

◆ MAX_BLOCK_TIME_GAP

constexpr int64_t MAX_BLOCK_TIME_GAP = 90 * 60
staticconstexpr

Maximum gap between node time and block time used for the "Catching up..." mode in GUI.

Ref: https://github.com/bitcoin/bitcoin/pull/1026

Definition at line 40 of file chain.h.

◆ MAX_FUTURE_BLOCK_TIME

constexpr int64_t MAX_FUTURE_BLOCK_TIME = 2 * 60 * 60
staticconstexpr

Maximum amount of time that a block timestamp is allowed to exceed the current network-adjusted time before the block will be accepted.

Definition at line 24 of file chain.h.

◆ TIMESTAMP_WINDOW

constexpr int64_t TIMESTAMP_WINDOW = MAX_FUTURE_BLOCK_TIME
staticconstexpr

Timestamp window used as a grace period by code that compares external timestamps (such as timestamps passed to RPCs, or wallet key creation times) to block timestamps.

This should be set at least as high as MAX_FUTURE_BLOCK_TIME.

Definition at line 32 of file chain.h.