12 return strprintf(
"CBlockIndex(pprev=%p, nHeight=%d, merkle=%s, hashBlock=%s)",
22 pindex = pindex->
pprev;
29 std::vector<uint256> have;
30 if (index ==
nullptr)
return have;
37 int height = std::max(index->
nHeight - step, 0);
40 if (have.size() > 10) step *= 2;
51 if (pindex ==
nullptr) {
57 pindex = pindex->
pprev;
63 std::pair<int64_t, int> blockparams = std::make_pair(nTime, height);
64 std::vector<CBlockIndex*>::const_iterator lower = std::lower_bound(
vChain.begin(),
vChain.end(), blockparams,
65 [](
CBlockIndex* pBlock,
const std::pair<int64_t, int>& blockparams) ->
bool {
return pBlock->GetBlockTimeMax() < blockparams.first || pBlock->nHeight < blockparams.second; });
66 return (lower ==
vChain.end() ? nullptr : *lower);
85 if (height >
nHeight || height < 0) {
91 while (heightWalk > height) {
94 if (pindexWalk->
pskip !=
nullptr &&
95 (heightSkip == height ||
96 (heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
97 heightSkipPrev >= height)))) {
99 pindexWalk = pindexWalk->
pskip;
100 heightWalk = heightSkip;
103 pindexWalk = pindexWalk->
pprev;
126 bnTarget.
SetCompact(bits, &fNegative, &fOverflow);
127 if (fNegative || fOverflow || bnTarget == 0)
133 return (~bnTarget / (bnTarget + 1)) + 1;
148 return sign * std::numeric_limits<int64_t>::max();
arith_uint256 nChainWork
(memory only) Total amount of work (expected number of hashes) in the chain up to and including this ...
std::string ToString() const
CBlockIndex * pskip
pointer to the index of some further predecessor of this block
std::vector< CBlockIndex * > vChain
Describes a place in the block chain to another node such that if the other node doesn't have the sam...
CBlockIndex * pprev
pointer to the index of the predecessor of this block
const CBlockIndex * LastCommonAncestor(const CBlockIndex *pa, const CBlockIndex *pb)
Find the last common ancestor two blocks have.
int Height() const
Return the maximal height in the chain.
void SetTip(CBlockIndex &block)
Set/initialize a chain with a given tip.
uint256 GetBlockHash() const
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...
arith_uint256 GetBlockProof(const CBlockIndex &block)
Compute how much work a block index entry corresponds to.
bool Contains(const CBlockIndex *pindex) const
Efficiently check whether a block is present in this chain.
std::vector< uint256 > LocatorEntries(const CBlockIndex *index)
Construct a list of hash entries to put in a locator.
int64_t nPowTargetSpacing
void BuildSkip()
Build the skiplist pointer for this entry.
std::string ToString() const
Parameters that influence chain consensus.
#define Assume(val)
Assume is the identity function.
256-bit unsigned big integer.
static int sign(const secp256k1_context *ctx, struct signer_secrets *signer_secrets, struct signer *signer, const secp256k1_musig_keyagg_cache *cache, const unsigned char *msg32, unsigned char *sig64)
static int InvertLowestOne(int n)
Turn the lowest '1' bit in the binary representation of a number into a '0'.
The block chain is a tree shaped structure starting with the genesis block at the root...
uint64_t GetLow64() const
arith_uint256 & SetCompact(uint32_t nCompact, bool *pfNegative=nullptr, bool *pfOverflow=nullptr)
The "compact" format is a representation of a whole number N using an unsigned 32bit number similar t...
static int GetSkipHeight(int height)
Compute what height to jump back to with the CBlockIndex::pskip pointer.
CBlockLocator GetLocator(const CBlockIndex *index)
Get a locator for a block index entry.
int nHeight
height of the entry in the chain. The genesis block has height 0
CBlockIndex * GetAncestor(int height)
Efficiently find an ancestor of this block.
arith_uint256 GetBitsProof(uint32_t bits)
Compute how much work an nBits value corresponds to.
const CBlockIndex * FindFork(const CBlockIndex *pindex) const
Find the last common block between this chain and a block index entry.
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...
unsigned int bits() const
Returns the position of the highest bit set plus one, or zero if the value is zero.