 |
Bitcoin Core
22.99.0
P2P Digital Currency
|
Go to the documentation of this file.
6 #ifndef BITCOIN_CHAIN_H
7 #define BITCOIN_CHAIN_H
84 void AddBlock(
unsigned int nHeightIn, uint64_t nTimeIn)
280 return (int64_t)
nTime;
300 std::sort(pbegin, pend);
301 return pbegin[(pend - pbegin) / 2];
306 return strprintf(
"CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
386 int _nVersion = s.GetVersion();
420 std::string str =
"CDiskBlockIndex(";
422 str +=
strprintf(
"\n hashBlock=%s, hashPrev=%s)",
455 if (nHeight < 0 || nHeight >= (
int)
vChain.size())
463 return (*
this)[pindex->
nHeight] == pindex;
470 return (*
this)[pindex->
nHeight + 1];
478 return int(
vChain.size()) - 1;
494 #endif // BITCOIN_CHAIN_H
bool RaiseValidity(enum BlockStatus nUpTo) EXCLUSIVE_LOCKS_REQUIRED(
Raise the validity level of this block index entry.
static constexpr int64_t MAX_FUTURE_BLOCK_TIME
Maximum amount of time that a block timestamp is allowed to exceed the current network-adjusted time ...
int64_t GetBlockTime() const
uint64_t nTimeFirst
earliest time of block in file
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex
@ BLOCK_VALID_UNKNOWN
Unused.
static constexpr int64_t MAX_BLOCK_TIME_GAP
Maximum gap between node time and block time used for the "Catching up..." mode in GUI.
unsigned int nTx
Number of transactions in this block.
@ BLOCK_VALID_TREE
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
#define VARINT_MODE(obj, mode)
256-bit unsigned big integer.
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int nHeight
height of the entry in the chain. The genesis block has height 0
FlatFilePos GetBlockPos() const EXCLUSIVE_LOCKS_REQUIRED(
@ BLOCK_VALID_RESERVED
Reserved (was BLOCK_VALID_HEADER).
std::string ToString() const
CDiskBlockIndex(const CBlockIndex *pindex)
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
unsigned int nChainTx
(memory only) Number of transactions in the chain up to and including this block.
Used to marshal pointers into hashes for db storage.
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
int64_t GetBlockTimeMax() const
CBlockIndex * FindEarliestAtLeast(int64_t nTime, int height) const
Find the earliest block with timestamp equal or greater than the given time and height equal or great...
@ BLOCK_FAILED_VALID
stage after last reached validness failed
CBlockHeader GetBlockHeader() const
Parameters that influence chain consensus.
uint64_t nTimeLast
latest time of block in file
unsigned int nBlocks
number of blocks stored in file
int64_t GetMedianTimePast() const
@ BLOCK_VALID_SCRIPTS
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
int32_t nVersion
block header
unsigned int nHeightFirst
lowest height of block in file
static constexpr int nMedianTimeSpan
@ BLOCK_VALID_TRANSACTIONS
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid,...
std::string ToString() const
CBlockLocator GetLocator(const CBlockIndex *pindex=nullptr) const
Return a CBlockLocator that refers to a block in this chain (by default the tip).
@ BLOCK_ASSUMED_VALID
If set, this indicates that the block index entry is assumed-valid.
unsigned int nTimeMax
(memory only) Maximum nTime in the chain up to and including this block.
std::string ToString() const
unsigned int nHeightLast
highest height of block in file
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
update statistics (does not update nSize)
@ BLOCK_VALID_MASK
All validity bits.
void SetTip(CBlockIndex *pindex)
Set/initialize a chain with a given tip.
uint256 GetBlockHash() const
bool IsAssumedValid() const EXCLUSIVE_LOCKS_REQUIRED(
int Height() const
Return the maximal height in the chain.
arith_uint256 GetBlockProof(const CBlockIndex &block)
An in-memory indexed chain of blocks.
#define EXCLUSIVE_LOCKS_REQUIRED(...)
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
unsigned int nDataPos GUARDED_BY(::cs_main)
Byte offset within blk?????.dat where this block's data is stored.
void BuildSkip()
Build the skiplist pointer for this entry.
std::vector< CBlockIndex * > vChain
bool HaveTxsDownloaded() const
Check whether this block's and all previous blocks' transactions have been downloaded (and stored to ...
@ BLOCK_HAVE_UNDO
undo data available in rev*.dat
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
unsigned int nUndoPos GUARDED_BY(::cs_main)
Byte offset within rev?????.dat where this block's undo data is stored.
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 nUndoSize
number of used bytes in the undo file
uint256 GetBlockHash() const
CBlockIndex(const CBlockHeader &block)
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the forking point between two chain tips.
SERIALIZE_METHODS(CDiskBlockIndex, obj)
@ BLOCK_VALID_CHAIN
Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends,...
int nFile GUARDED_BY(::cs_main)
Which # file this block is stored in (blk?????.dat)
std::string ToString() const
@ BLOCK_OPT_WITNESS
block data in blk*.dat was received with a witness-enforcing client
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this block index entry is valid up to the passed validity level.
@ BLOCK_HAVE_DATA
full block available in blk*.dat
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or nullptr if no such height exists.
unsigned int nSize
number of used bytes of block file
CChain & operator=(const CChain &)=delete
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...
FlatFilePos GetUndoPos() const EXCLUSIVE_LOCKS_REQUIRED(
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
uint32_t nStatus GUARDED_BY(::cs_main)
Verification status of this block.
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
@ BLOCK_FAILED_CHILD
descends from failed block
SERIALIZE_METHODS(CBlockFileInfo, obj)