6 #ifndef BITCOIN_CHAIN_H 7 #define BITCOIN_CHAIN_H 21 #include <unordered_map> 85 static constexpr
int TRACK_SIZE_VERSION = 220800;
92 hashPrev = (pprev ? pprev->GetBlockHash() :
BlockHash());
96 int _nVersion = s.GetVersion();
106 if (obj.nStatus.hasData() && _nVersion >= TRACK_SIZE_VERSION) {
110 if (obj.nStatus.hasData() || obj.nStatus.hasUndo()) {
113 if (obj.nStatus.hasData()) {
116 if (obj.nStatus.hasUndo()) {
141 std::string str =
"CDiskBlockIndex(";
143 str +=
strprintf(
"\n hashBlock=%s, hashPrev=%s)",
162 return vChain.size() > 0 ? vChain[0] :
nullptr;
169 return vChain.size() > 0 ? vChain[vChain.size() - 1] :
nullptr;
177 if (nHeight < 0 || nHeight >= (
int)vChain.size()) {
191 return (*
this)[pindex->
nHeight] == pindex;
199 if (!Contains(pindex)) {
203 return (*
this)[pindex->
nHeight + 1];
210 int Height()
const {
return vChain.size() - 1; }
230 CBlockIndex *FindEarliestAtLeast(int64_t nTime,
int height)
const;
233 #endif // BITCOIN_CHAIN_H
BlockHash GetBlockHash() const
std::string ToString() const
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
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 Height() const
Return the maximal height in the chain.
CBlockIndex * Genesis() const
Returns the index entry for the genesis block of this chain, or nullptr if none.
SERIALIZE_METHODS(CDiskBlockIndex, obj)
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
std::vector< CBlockIndex * > vChain
#define VARINT_MODE(obj, mode)
std::string ToString(const T &t)
Locale-independent version of std::to_string.
arith_uint256 GetBlockProof(const CBlockIndex &block)
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or nullptr if no such height exists...
bool AreOnTheSameFork(const CBlockIndex *pa, const CBlockIndex *pb)
Check if two block index are on the same fork.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
size_t operator()(const BlockHash &hash) const
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...
friend bool operator==(const CChain &a, const CChain &b)
Compare two chains efficiently.
Used to marshal pointers into hashes for db storage.
std::string ToString() const
Parameters that influence chain consensus.
256-bit unsigned big integer.
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...
Maintain a map of CBlockIndex for all known headers.
A BlockHash is a unqiue identifier for a block.
CDiskBlockIndex(const CBlockIndex *pindex)
The block chain is a tree shaped structure starting with the genesis block at the root...
RecursiveMutex cs_main
Global state.
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
std::string ToString() const
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 ...
int nHeight
height of the entry in the chain. The genesis block has height 0
static uint64_t ReadLE64(const uint8_t *ptr)
static constexpr int64_t MAX_BLOCK_TIME_GAP
Maximum gap between node time and block time used for the "Catching up..." mode in GUI...