6 #ifndef BITCOIN_CHAIN_H 7 #define BITCOIN_CHAIN_H 79 void AddBlock(
unsigned int nHeightIn, uint64_t nTimeIn) {
80 if (nBlocks==0 || nHeightFirst > nHeightIn)
81 nHeightFirst = nHeightIn;
82 if (nBlocks==0 || nTimeFirst > nTimeIn)
85 if (nHeightIn > nHeightLast)
86 nHeightLast = nHeightIn;
87 if (nTimeIn > nTimeLast)
156 unsigned int nDataPos{0};
159 unsigned int nUndoPos{0};
171 unsigned int nChainTx{0};
184 int32_t nSequenceId{0};
187 unsigned int nTimeMax{0};
195 hashMerkleRoot{block.hashMerkleRoot},
249 return (int64_t)nTime;
254 return (int64_t)nTimeMax;
257 static constexpr
int nMedianTimeSpan = 11;
261 int64_t pmedian[nMedianTimeSpan];
262 int64_t* pbegin = &pmedian[nMedianTimeSpan];
263 int64_t* pend = &pmedian[nMedianTimeSpan];
266 for (
int i = 0; i < nMedianTimeSpan && pindex; i++, pindex = pindex->
pprev)
269 std::sort(pbegin, pend);
270 return pbegin[(pend - pbegin)/2];
275 return strprintf(
"CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
277 hashMerkleRoot.ToString(),
278 GetBlockHash().ToString());
298 nStatus = (nStatus & ~BLOCK_VALID_MASK) | nUpTo;
330 hashPrev = (pprev ? pprev->GetBlockHash() :
uint256());
335 int _nVersion = s.GetVersion();
369 std::string str =
"CDiskBlockIndex(";
371 str +=
strprintf(
"\n hashBlock=%s, hashPrev=%s)",
386 return vChain.size() > 0 ? vChain[0] :
nullptr;
391 return vChain.size() > 0 ? vChain[vChain.size() - 1] :
nullptr;
396 if (nHeight < 0 || nHeight >= (
int)vChain.size())
403 return (*
this)[pindex->
nHeight] == pindex;
408 if (Contains(pindex))
409 return (*
this)[pindex->
nHeight + 1];
416 return vChain.size() - 1;
429 CBlockIndex* FindEarliestAtLeast(int64_t nTime,
int height)
const;
432 #endif // BITCOIN_CHAIN_H
std::string ToString() const
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...
descends from failed block
Reserved (was BLOCK_VALID_HEADER).
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void AddBlock(unsigned int nHeightIn, uint64_t nTimeIn)
update statistics (does not update nSize)
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the forking point between two chain tips.
An in-memory indexed chain of blocks.
All parent headers found, difficulty matches, timestamp >= median previous, checkpoint.
CBlockHeader GetBlockHeader() const
int Height() const
Return the maximal height in the chain.
stage after last reached validness failed
Only first tx is coinbase, 2 <= coinbase input script length <= 100, transactions valid...
unsigned int nSize
number of used bytes of block file
FlatFilePos GetBlockPos() const
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)
static constexpr int64_t TIMESTAMP_WINDOW
Timestamp window used as a grace period by code that compares external timestamps (such as timestamps...
unsigned int nHeightLast
highest height of block in file
unsigned int nUndoSize
number of used bytes in the undo file
uint256 GetBlockHash() const
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
#define VARINT_MODE(obj, mode)
arith_uint256 GetBlockProof(const CBlockIndex &block)
Outputs do not overspend inputs, no double spends, coinbase output ok, no immature coinbase spends...
uint64_t nTimeFirst
earliest time of block in file
CBlockIndex * operator[](int nHeight) const
Returns the index entry at a particular height in this chain, or nullptr if no such height exists...
Scripts & signatures ok. Implies all parents are also at least SCRIPTS.
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...
int64_t GetBlockTimeMax() const
unsigned int nHeightFirst
lowest height of block in file
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 GetMedianTimePast() const
block data in blk*.data was received with a witness-enforcing client
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...
CDiskBlockIndex(const CBlockIndex *pindex)
The block chain is a tree shaped structure starting with the genesis block at the root...
CBlockIndex * Tip() const
Returns the index entry for the tip of this chain, or nullptr if none.
unsigned int nBlocks
number of blocks stored in file
std::string ToString() const
bool RaiseValidity(enum BlockStatus nUpTo)
Raise the validity level of this block index entry.
FlatFilePos GetUndoPos() const
uint64_t nTimeLast
latest time of block in file
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
full block available in blk*.dat
uint256 GetBlockHash() const
SERIALIZE_METHODS(CBlockFileInfo, obj)
std::string ToString() const
static constexpr int64_t MAX_BLOCK_TIME_GAP
Maximum gap between node time and block time used for the "Catching up..." mode in GUI...
bool HaveTxsDownloaded() const
Check whether this block's and all previous blocks' transactions have been downloaded (and stored to ...