45 vChain.resize(pindex->
nHeight + 1);
46 while (pindex && vChain[pindex->
nHeight] != pindex) {
47 vChain[pindex->
nHeight] = pindex;
48 pindex = pindex->
pprev;
54 std::vector<uint256> vHave;
65 int nHeight = std::max(pindex->
nHeight - nStep, 0);
66 if (Contains(pindex)) {
68 pindex = (*this)[nHeight];
73 if (vHave.size() > 10)
86 while (pindex && !Contains(pindex))
87 pindex = pindex->
pprev;
93 std::vector<CBlockIndex*>::const_iterator lower = std::lower_bound(vChain.begin(), vChain.end(), nTime,
94 [](
CBlockIndex* pBlock,
const int64_t& time) ->
bool { return pBlock->GetBlockTimeMax() < time; });
95 return (lower == vChain.end() ? NULL : *lower);
99 int static inline InvertLowestOne(
int n) {
return n & (n - 1); }
102 int static inline GetSkipHeight(
int height) {
109 return (height & 1) ? InvertLowestOne(InvertLowestOne(height - 1)) + 1 : InvertLowestOne(height);
114 if (height > nHeight || height < 0)
118 int heightWalk = nHeight;
119 while (heightWalk > height) {
120 int heightSkip = GetSkipHeight(heightWalk);
121 int heightSkipPrev = GetSkipHeight(heightWalk - 1);
122 if (pindexWalk->
pskip != NULL &&
123 (heightSkip == height ||
124 (heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
125 heightSkipPrev >= height)))) {
127 pindexWalk = pindexWalk->
pskip;
128 heightWalk = heightSkip;
130 assert(pindexWalk->
pprev);
131 pindexWalk = pindexWalk->
pprev;
140 return const_cast<CBlockIndex*
>(
this)->GetAncestor(height);
146 pskip = pprev->GetAncestor(GetSkipHeight(nHeight));
155 if (fNegative || fOverflow || bnTarget == 0)
161 return (~bnTarget / (bnTarget + 1)) + 1;
176 return sign * std::numeric_limits<int64_t>::max();
arith_uint256 GetBlockProof(const CBlockIndex &block)
int64_t GetBlockProofEquivalentTime(const CBlockIndex &to, const CBlockIndex &from, const CBlockIndex &tip, const Consensus::Params ¶ms)
Return the time it would take to redo the work difference between from and to, assuming the current h...
The block chain is a tree shaped structure starting with the genesis block at the root,...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
void BuildSkip()
Build the skiplist pointer for this entry.
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
CBlockHeader GetBlockHeader(const Consensus::Params &consensusParams, bool fCheckPOW=true) const
uint256 GetBlockHash() const
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
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
CBlockLocator GetLocator(const CBlockIndex *pindex=NULL) const
Return a CBlockLocator that refers to a block in this chain (by default the tip).
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.
CBlockIndex * FindEarliestAtLeast(int64_t nTime) const
Find the earliest block with timestamp equal or greater than the given.
256-bit unsigned big integer.
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=NULL, bool *pfOverflow=NULL)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
uint64_t GetLow64() const
unsigned int bits() const
Returns the position of the highest bit set plus one, or zero if the value is zero.
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.
int64_t nPowTargetSpacing
bool ReadBlockHeaderFromDisk(CBlockHeader &block, const CBlockIndex *pindex, const Consensus::Params &consensusParams, bool fCheckPOW)