Changeset View
Changeset View
Standalone View
Standalone View
src/interfaces/chain.cpp
Show First 20 Lines • Show All 69 Lines • ▼ Show 20 Lines | class LockImpl : public Chain::Lock, public UniqueLock<RecursiveMutex> { | ||||
CBlockIndex *block = ::ChainActive()[height]; | CBlockIndex *block = ::ChainActive()[height]; | ||||
assert(block != nullptr); | assert(block != nullptr); | ||||
return block->GetMedianTimePast(); | return block->GetMedianTimePast(); | ||||
} | } | ||||
bool haveBlockOnDisk(int height) override { | bool haveBlockOnDisk(int height) override { | ||||
CBlockIndex *block = ::ChainActive()[height]; | CBlockIndex *block = ::ChainActive()[height]; | ||||
return block && (block->nStatus.hasData() != 0) && block->nTx > 0; | return block && (block->nStatus.hasData() != 0) && block->nTx > 0; | ||||
} | } | ||||
Optional<int> findFirstBlockWithTime(int64_t time, | Optional<int> | ||||
findFirstBlockWithTimeAndHeight(int64_t time, int height, | |||||
BlockHash *hash) override { | BlockHash *hash) override { | ||||
CBlockIndex *block = ::ChainActive().FindEarliestAtLeast(time); | CBlockIndex *block = | ||||
::ChainActive().FindEarliestAtLeast(time, height); | |||||
if (block) { | if (block) { | ||||
if (hash) { | if (hash) { | ||||
*hash = block->GetBlockHash(); | *hash = block->GetBlockHash(); | ||||
} | } | ||||
return block->nHeight; | return block->nHeight; | ||||
} | } | ||||
return nullopt; | return nullopt; | ||||
} | } | ||||
Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, | |||||
int height) override { | |||||
// TODO: Could update CChain::FindEarliestAtLeast() to take a height | |||||
// parameter and use it with std::lower_bound() to make this | |||||
// implementation more efficient and allow combining | |||||
// findFirstBlockWithTime and findFirstBlockWithTimeAndHeight into | |||||
// one method. | |||||
for (CBlockIndex *block = ::ChainActive()[height]; block; | |||||
block = ::ChainActive().Next(block)) { | |||||
if (block->GetBlockTime() >= time) { | |||||
return block->nHeight; | |||||
} | |||||
} | |||||
return nullopt; | |||||
} | |||||
Optional<int> findPruned(int start_height, | Optional<int> findPruned(int start_height, | ||||
Optional<int> stop_height) override { | Optional<int> stop_height) override { | ||||
if (::fPruneMode) { | if (::fPruneMode) { | ||||
CBlockIndex *block = stop_height ? ::ChainActive()[*stop_height] | CBlockIndex *block = stop_height ? ::ChainActive()[*stop_height] | ||||
: ::ChainActive().Tip(); | : ::ChainActive().Tip(); | ||||
while (block && block->nHeight >= start_height) { | while (block && block->nHeight >= start_height) { | ||||
if (block->nStatus.hasData() == 0) { | if (block->nStatus.hasData() == 0) { | ||||
return block->nHeight; | return block->nHeight; | ||||
▲ Show 20 Lines • Show All 292 Lines • Show Last 20 Lines |