Changeset View
Changeset View
Standalone View
Standalone View
src/chain.cpp
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | if (pindex->nHeight > Height()) { | ||||
pindex = pindex->GetAncestor(Height()); | pindex = pindex->GetAncestor(Height()); | ||||
} | } | ||||
while (pindex && !Contains(pindex)) { | while (pindex && !Contains(pindex)) { | ||||
pindex = pindex->pprev; | pindex = pindex->pprev; | ||||
} | } | ||||
return pindex; | return pindex; | ||||
} | } | ||||
CBlockIndex *CChain::FindEarliestAtLeast(int64_t nTime) const { | CBlockIndex *CChain::FindEarliestAtLeast(int64_t nTime, int height) const { | ||||
std::vector<CBlockIndex *>::const_iterator lower = | std::pair<int64_t, int> blockparams = std::make_pair(nTime, height); | ||||
std::lower_bound(vChain.begin(), vChain.end(), nTime, | std::vector<CBlockIndex *>::const_iterator lower = std::lower_bound( | ||||
[](CBlockIndex *pBlock, const int64_t &time) -> bool { | vChain.begin(), vChain.end(), blockparams, | ||||
return pBlock->GetBlockTimeMax() < time; | [](CBlockIndex *pBlock, | ||||
const std::pair<int64_t, int> &blockparams) -> bool { | |||||
return pBlock->GetBlockTimeMax() < blockparams.first || | |||||
pBlock->nHeight < blockparams.second; | |||||
}); | }); | ||||
return (lower == vChain.end() ? nullptr : *lower); | return (lower == vChain.end() ? nullptr : *lower); | ||||
} | } | ||||
/** Turn the lowest '1' bit in the binary representation of a number into a '0'. | /** Turn the lowest '1' bit in the binary representation of a number into a '0'. | ||||
*/ | */ | ||||
static inline int InvertLowestOne(int n) { | static inline int InvertLowestOne(int n) { | ||||
return n & (n - 1); | return n & (n - 1); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 121 Lines • Show Last 20 Lines |