MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / GetAncestor

Method GetAncestor

src/chain.cpp:82–107  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

80}
81
82const CBlockIndex* CBlockIndex::GetAncestor(int height) const
83{
84 if (height > nHeight || height < 0) {
85 return nullptr;
86 }
87
88 const CBlockIndex* pindexWalk = this;
89 int heightWalk = nHeight;
90 while (heightWalk > height) {
91 int heightSkip = GetSkipHeight(heightWalk);
92 int heightSkipPrev = GetSkipHeight(heightWalk - 1);
93 if (pindexWalk->pskip != nullptr &&
94 (heightSkip == height ||
95 (heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
96 heightSkipPrev >= height)))) {
97 // Only follow pskip if pprev->pskip isn't better than pskip->pprev.
98 pindexWalk = pindexWalk->pskip;
99 heightWalk = heightSkip;
100 } else {
101 assert(pindexWalk->pprev);
102 pindexWalk = pindexWalk->pprev;
103 heightWalk--;
104 }
105 }
106 return pindexWalk;
107}
108
109CBlockIndex* CBlockIndex::GetAncestor(int height)
110{

Callers 15

GetNextWorkRequiredFunction · 0.45
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.45
FindNextBlocksMethod · 0.45
ProcessGetCFHeadersMethod · 0.45
ProcessGetCFCheckPtMethod · 0.45
LocatorEntriesFunction · 0.45
FindForkMethod · 0.45

Calls 1

GetSkipHeightFunction · 0.85

Tested by

no test coverage detected