6 #ifndef BITCOIN_CHAIN_H 7 #define BITCOIN_CHAIN_H 17 #include <util/time.h> 223 return (int64_t)
nTime;
243 std::sort(pbegin, pend);
244 return pbegin[(pend - pbegin) / 2];
404 if (nHeight < 0 || nHeight >= (
int)
vChain.size())
412 return (*
this)[pindex->
nHeight] == pindex;
419 return (*
this)[pindex->
nHeight + 1];
427 return int(
vChain.size()) - 1;
433 const auto tip{
Tip()};
436 tip->Time() >= Now<NodeSeconds>() - max_tip_age;
455 #endif // BITCOIN_CHAIN_H
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
std::string ToString() const
int32_t nSequenceId
(memory only) Sequential id assigned to distinguish order in which blocks are received.
bool HaveNumChainTxs() const
Check whether this block and all previous blocks back to the genesis block or an assumeutxo snapshot ...
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
std::vector< CBlockIndex * > vChain
int64_t GetBlockTime() const
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Unused flag that was previously set when descending from failed block.
Reserved (was BLOCK_VALID_HEADER).
CBlockIndex * pprev
pointer to the index of the predecessor of this block
CBlockLocator GetLocator(const CBlockIndex *index)
Get a locator for a block index entry.
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the forking point between two chain tips.
An in-memory indexed chain of blocks.
int nFile GUARDED_BY(::cs_main)
Which # file this block is stored in (blk?????.dat)
All parent headers found, difficulty matches, timestamp >= median previous.
CBlockHeader GetBlockHeader() const
int Height() const
Return the maximal height in the chain.
Unused flag that was previously set on assumeutxo snapshot blocks and their ancestors before they wer...
stage after last reached validness failed
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid...
static constexpr int32_t SEQ_ID_BEST_CHAIN_FROM_DISK
Init values for CBlockIndex nSequenceId when loaded from disk.
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
undo data available in rev*.dat
SERIALIZE_METHODS(CDiskBlockIndex, obj)
void SetTip(CBlockIndex &block)
Set/initialize a chain with a given tip.
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
static constexpr int nMedianTimeSpan
uint256 GetBlockHash() 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...
#define VARINT_MODE(obj, mode)
arith_uint256 GetBlockProof(const CBlockIndex &block)
Compute how much work a block index entry corresponds to.
Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends...
unsigned int nTimeMax
(memory only) Maximum nTime in the chain up to and including this block.
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or nullptr if no such height exists...
std::string ToString()=delete
arith_uint256 GetBitsProof(uint32_t bits)
Compute how much work an nBits value corresponds to.
uint64_t m_chain_tx_count
(memory only) Number of transactions in the chain up to and including this block. ...
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
CBlockIndex(const CBlockHeader &block)
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...
std::vector< uint256 > LocatorEntries(const CBlockIndex *index)
Construct a list of hash entries to put in a locator.
int64_t GetBlockTimeMax() const
static constexpr int DUMMY_VERSION
Historically CBlockLocator's version field has been written to disk streams as the client version...
CChain & operator=(const CChain &)=delete
void BuildSkip()
Build the skiplist pointer for this entry.
Used to marshal pointers into hashes for db storage.
Parameters that influence chain consensus.
256-bit unsigned big integer.
int64_t GetMedianTimePast() const
block data in blk*.dat was received with a witness-enforcing client
FlatFilePos GetUndoPos() const EXCLUSIVE_LOCKS_REQUIRED(
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 nDataPos GUARDED_BY(::cs_main)
Byte offset within blk?????.dat where this block's data is stored.
uint32_t nStatus GUARDED_BY(::cs_main)
Verification status of this block.
int32_t nVersion
block header
bool IsTipRecent(const arith_uint256 &min_chain_work, std::chrono::seconds max_tip_age) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this chain's tip exists, has enough work, and is recent.
uint256 ConstructBlockHash() const
#define EXCLUSIVE_LOCKS_REQUIRED(...)
unsigned int nUndoPos GUARDED_BY(::cs_main)
Byte offset within rev?????.dat where this block's undo data is stored.
CDiskBlockIndex(const CBlockIndex *pindex)
The block chain is a tree shaped structure starting with the genesis block at the root...
static constexpr int32_t SEQ_ID_INIT_FROM_DISK
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
bool RaiseValidity(enum BlockStatus nUpTo) EXCLUSIVE_LOCKS_REQUIRED(
Raise the validity level of this block index entry.
std::chrono::time_point< NodeClock, std::chrono::seconds > NodeSeconds
bool IsValid(enum BlockStatus nUpTo) const EXCLUSIVE_LOCKS_REQUIRED(
Check whether this block index entry is valid up to the passed validity level.
static constexpr int64_t MAX_FUTURE_BLOCK_TIME
Maximum amount of time that a block timestamp is allowed to exceed the current time before the block ...
int nHeight
height of the entry in the chain. The genesis block has height 0
FlatFilePos GetBlockPos() const EXCLUSIVE_LOCKS_REQUIRED(
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
full block available in blk*.dat
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate...
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
unsigned int nTx
Number of transactions in this block.
uint256 GetBlockHash()=delete
CBlockIndex & operator=(const CBlockIndex &)=delete
const uint256 * phashBlock
pointer to the hash of the block, if any. Memory is owned by this CBlockIndex