MCPcopy Create free account
hub / github.com/ElementsProject/elements / GetAncestor

Method GetAncestor

src/chain.cpp:113–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111}
112
113const CBlockIndex* CBlockIndex::GetAncestor(int height) const
114{
115 if (height > nHeight || height < 0) {
116 return nullptr;
117 }
118
119 const CBlockIndex* pindexWalk = this;
120 int heightWalk = nHeight;
121 while (heightWalk > height) {
122 int heightSkip = GetSkipHeight(heightWalk);
123 int heightSkipPrev = GetSkipHeight(heightWalk - 1);
124 if (pindexWalk->pskip != nullptr &&
125 (heightSkip == height ||
126 (heightSkip > height && !(heightSkipPrev < heightSkip - 2 &&
127 heightSkipPrev >= height)))) {
128 // Only follow pskip if pprev->pskip isn't better than pskip->pprev.
129 pindexWalk = pindexWalk->pskip;
130 heightWalk = heightSkip;
131 } else {
132 assert(pindexWalk->pprev);
133 pindexWalk = pindexWalk->pprev;
134 heightWalk--;
135 }
136 }
137 return pindexWalk;
138}
139
140CBlockIndex* CBlockIndex::GetAncestor(int height)
141{

Callers 15

GetValidFedpegScriptsFunction · 0.80
GetNextWorkRequiredFunction · 0.80
EXCLUSIVE_LOCKS_REQUIREDFunction · 0.80
ProcessGetCFHeadersMethod · 0.80
ProcessGetCFCheckPtMethod · 0.80
GetLocatorMethod · 0.80
FindForkMethod · 0.80
BuildSkipMethod · 0.80
LastCommonAncestorFunction · 0.80

Calls 1

GetSkipHeightFunction · 0.85

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.64
BOOST_AUTO_TEST_CASEFunction · 0.64