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

Method GetAncestor

src/main.cpp:2028–2048  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2026}
2027
2028CBlockIndex *CBlockIndex::GetAncestor(int32_t heightIn) {
2029 if (heightIn > height || heightIn < 0)
2030 return nullptr;
2031
2032 CBlockIndex *pindexWalk = this;
2033 int32_t heightWalk = height;
2034 while (heightWalk > heightIn) {
2035 int32_t heightSkip = GetSkipHeight(heightWalk);
2036 int32_t heightSkipPrev = GetSkipHeight(heightWalk - 1);
2037 if (heightSkip == heightIn ||
2038 (heightSkip > heightIn && !(heightSkipPrev < heightSkip - 2 && heightSkipPrev >= heightIn))) {
2039 // Only follow pskip if pprev->pskip isn't better than pskip->pprev.
2040 pindexWalk = pindexWalk->pskip;
2041 heightWalk = heightSkip;
2042 } else {
2043 pindexWalk = pindexWalk->pprev;
2044 heightWalk--;
2045 }
2046 }
2047 return pindexWalk;
2048}
2049
2050const CBlockIndex *CBlockIndex::GetAncestor(int32_t heightIn) const {
2051 return const_cast<CBlockIndex *>(this)->GetAncestor(heightIn);

Callers 3

ReconsiderBlockFunction · 0.80
BuildSkipMethod · 0.80
GetLocatorMethod · 0.80

Calls 1

GetSkipHeightFunction · 0.85

Tested by

no test coverage detected