16 if (pindex ==
nullptr) {
23 pindex = pindex->
pprev;
30 std::vector<uint256> vHave;
41 int nHeight = std::max(pindex->
nHeight - nStep, 0);
44 pindex = (*this)[nHeight];
49 if (vHave.size() > 10)
58 if (pindex ==
nullptr)
63 pindex = pindex->
pprev;
69 std::vector<CBlockIndex*>::const_iterator lower = std::lower_bound(
vChain.begin(),
vChain.end(), nTime,
70 [](
CBlockIndex* pBlock,
const int64_t& time) ->
bool { return pBlock->GetBlockTimeMax() < time; });
71 return (lower ==
vChain.end() ?
nullptr : *lower);
75 int static inline InvertLowestOne(
int n) {
return n & (n - 1); }
78 int static inline GetSkipHeight(
int height)
85 return (height & 1) ? InvertLowestOne(InvertLowestOne(height - 1)) + 1 : InvertLowestOne(height);
90 if (height >
nHeight || height < 0) {
96 while (heightWalk > height) {
97 int heightSkip = GetSkipHeight(heightWalk);
98 int heightSkipPrev = GetSkipHeight(heightWalk - 1);
99 if (heightSkip == height ||
100 (heightSkip > height && !(heightSkipPrev < heightSkip - 2 && heightSkipPrev >= height))) {
102 pindexWalk = pindexWalk->
pskip;
103 heightWalk = heightSkip;
105 assert(pindexWalk->
pprev);
106 pindexWalk = pindexWalk->
pprev;
125 nVersion{block.nVersion},
126 hashMerkleRoot{block.hashMerkleRoot},
127 hashFinalSaplingRoot(block.hashFinalSaplingRoot),
140 return strprintf(
"CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
214 std::sort(pbegin, pend);
215 return pbegin[(pend - pbegin) / 2];
236 const size_t modSize =
sizeof(nStakeModifier);
239 if (fGeneratedStakeModifier)
249 LogPrintf(
"%s : SetStakeEntropyBit() failed\n", __func__);
250 uint64_t nStakeModifier = 0;
251 bool fGeneratedStakeModifier =
false;
253 LogPrintf(
"%s : ComputeNextStakeModifier() failed \n", __func__);
269 if (!
pprev)
throw std::runtime_error(
strprintf(
"%s : ERROR: null pprev", __func__));
283 uint64_t nStakeModifier;
285 return nStakeModifier;
295 return nStakeModifier;
345 while (pa != pb && pa && pb) {
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the last common ancestor two blocks have.
@ BLOCK_VALID_MASK
All validity bits.
@ BLOCK_HAVE_UNDO
full block available in blk*.dat
@ BLOCK_FAILED_MASK
descends from failed block
const CChainParams & Params()
Return the currently selected parameters.
bool IsProofOfStake() const
The block chain is a tree shaped structure starting with the genesis block at the root,...
bool RaiseValidity(enum BlockStatus nUpTo)
Raise the validity level of this block index entry.
uint256 GetStakeModifierV2() const
std::string ToString() const
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void BuildSkip()
Build the skiplist pointer for this entry.
unsigned int GetStakeEntropyBit() const
std::vector< unsigned char > vStakeModifier
CBlockHeader GetBlockHeader() const
int nFile
Which # file this block is stored in (blk?????.dat)
FlatFilePos GetBlockPos() const
void SetNewStakeModifier()
int64_t MaxFutureBlockTime() const
void SetStakeModifier(const uint64_t nStakeModifier, bool fGeneratedStakeModifier)
bool SetStakeEntropyBit(unsigned int nEntropyBit)
unsigned int nUndoPos
Byte offset within rev?????.dat where this block's undo data is stored.
uint256 nAccumulatorCheckpoint
uint256 GetBlockHash() const
int64_t GetBlockTime() const
void SetChainSaplingValue()
int64_t GetMedianTimePast() const
CAmount nSaplingValue
Change in value held by the Sapling circuit over this block.
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
uint256 hashFinalSaplingRoot
int64_t MinPastBlockTime() const
FlatFilePos GetUndoPos() const
bool IsValid(enum BlockStatus nUpTo=BLOCK_VALID_TRANSACTIONS) const
Check whether this block index entry is valid up to the passed validity level.
int32_t nVersion
block header
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
int nHeight
height of the entry in the chain. The genesis block has height 0
uint32_t nStatus
Verification status of this block. See enum BlockStatus.
unsigned int nDataPos
Byte offset within blk?????.dat where this block's data is stored.
Optional< CAmount > nChainSaplingValue
(memory only) Total value held by the Sapling circuit up to and including this block.
uint64_t GetStakeModifierV1() const
CBlockIndex * Tip(bool fProofOfStake=false) 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).
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.
std::vector< CBlockIndex * > vChain
void SetTip(CBlockIndex *pindex)
Set/initialize a chain with a given tip.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
CBlockIndex * FindEarliestAtLeast(int64_t nTime) const
Find the earliest block with timestamp equal or greater than the given.
const Consensus::Params & GetConsensus() const
A writer stream (for serialization) that computes a 256-bit hash.
std::string ToString() const
uint64_t GetCheapHash() const
A cheap hash function that just returns 64 bits from the result, it can be used when the contents are...
void * memcpy(void *a, const void *b, size_t c)
bool ComputeNextStakeModifier(const CBlockIndex *pindexPrev, uint64_t &nStakeModifier, bool &fGeneratedStakeModifier)
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
int nActivationHeight
Height of the first block for which the new consensus rules will be active.
Parameters that influence chain consensus.
bool IsTimeProtocolV2(const int nHeight) const
NetworkUpgrade vUpgrades[MAX_NETWORK_UPGRADES]
int FutureBlockTimeDrift(const int nHeight) const
int64_t GetAdjustedTime()
const uint256 UINT256_ZERO
constant uint256 instances
bool NetworkUpgradeActive(int nHeight, const Consensus::Params ¶ms, Consensus::UpgradeIndex idx)
Returns true if the given network upgrade is active as of the given block height.