mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
refactor: combine Chain::findFirstBlockWithTime/findFirstBlockWithTimeAndHeight
As suggested in #14711, pass height to CChain::FindEarliestAtLeast to simplify Chain interface by combining findFirstBlockWithTime and findFirstBlockWithTimeAndHeight into one Extend findearliestatleast_edge_test in consequence
This commit is contained in:
@@ -83,29 +83,15 @@ class LockImpl : public Chain::Lock
|
||||
CBlockIndex* block = ::chainActive[height];
|
||||
return block && ((block->nStatus & BLOCK_HAVE_DATA) != 0) && block->nTx > 0;
|
||||
}
|
||||
Optional<int> findFirstBlockWithTime(int64_t time, uint256* hash) override
|
||||
Optional<int> findFirstBlockWithTimeAndHeight(int64_t time, int height, uint256* hash) override
|
||||
{
|
||||
CBlockIndex* block = ::chainActive.FindEarliestAtLeast(time);
|
||||
CBlockIndex* block = ::chainActive.FindEarliestAtLeast(time, height);
|
||||
if (block) {
|
||||
if (hash) *hash = block->GetBlockHash();
|
||||
return block->nHeight;
|
||||
}
|
||||
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> stop_height) override
|
||||
{
|
||||
if (::fPruneMode) {
|
||||
|
||||
Reference in New Issue
Block a user