6 #ifndef BITCOIN_CHAIN_H
7 #define BITCOIN_CHAIN_H
21 #include <unordered_map>
85 int _nVersion = s.GetVersion();
99 if (obj.nStatus.hasData() || obj.nStatus.hasUndo()) {
102 if (obj.nStatus.hasData()) {
105 if (obj.nStatus.hasUndo()) {
130 std::string str =
"CDiskBlockIndex(";
132 str +=
strprintf(
"\n hashBlock=%s, hashPrev=%s)",
166 if (nHeight < 0 || nHeight >= (
int)
vChain.size()) {
174 return (*
this)[pindex->
nHeight] == pindex;
186 return (*
this)[pindex->
nHeight + 1];
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 h...
static constexpr int64_t MAX_BLOCK_TIME_GAP
Maximum gap between node time and block time used for the "Catching up..." mode in GUI.
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 ...
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the forking point between two chain tips.
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
RecursiveMutex cs_main
Global state.
bool AreOnTheSameFork(const CBlockIndex *pa, const CBlockIndex *pb)
Check if two block index are on the same fork.
The block chain is a tree shaped structure starting with the genesis block at the root,...
std::string ToString() const
CBlockIndex * pprev
pointer to the index of the predecessor of this block
int32_t nVersion
block header
BlockHash GetBlockHash() const
int nHeight
height of the entry in the chain. The genesis block has height 0
An in-memory indexed chain of blocks.
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or nullptr if no such height exists.
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...
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
CBlockLocator GetLocator(const CBlockIndex *pindex=nullptr) const
Return a CBlockLocator that refers to a block in this chain (by default the tip).
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...
int Height() const
Return the maximal height in the chain.
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
void SetTip(CBlockIndex *pindex)
Set/initialize a chain with a given tip.
std::vector< CBlockIndex * > vChain
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
Used to marshal pointers into hashes for db storage.
BlockHash GetBlockHash() const
std::string ToString() const
static constexpr int TRACK_SIZE_VERSION
SERIALIZE_METHODS(CDiskBlockIndex, obj)
CDiskBlockIndex(const CBlockIndex *pindex)
256-bit unsigned big integer.
std::string ToString() const
#define VARINT_MODE(obj, mode)
A BlockHash is a unqiue identifier for a block.
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
Parameters that influence chain consensus.