cryptonote_protocol: accurate next_needed_height when there is an overlap

This commit is contained in:
0xFFFC0000
2025-11-05 21:07:25 +00:00
committed by 0xfffc
parent 8a53c96b12
commit 52b4c73ab4

View File

@@ -153,18 +153,26 @@ uint64_t block_queue::get_next_needed_height(uint64_t blockchain_height) const
boost::unique_lock<boost::recursive_mutex> lock(mutex); boost::unique_lock<boost::recursive_mutex> lock(mutex);
if (blocks.empty()) if (blocks.empty())
return blockchain_height; return blockchain_height;
uint64_t last_needed_height = blockchain_height;
bool first = true; uint64_t covered_until = blockchain_height;
for (const auto &span: blocks) for (const auto &span: blocks)
{ {
if (span.start_block_height + span.nblocks - 1 < blockchain_height) // Ignore spans entirely below current chain height
const uint64_t span_end = span.start_block_height + span.nblocks - 1;
if (span_end < blockchain_height)
continue; continue;
if (span.start_block_height != last_needed_height || (first && span.blocks.empty()))
return last_needed_height; // If this span starts after what we already have/scheduled, we found the first gap
last_needed_height = span.start_block_height + span.nblocks; if (span.start_block_height > covered_until)
first = false; return covered_until;
// This span overlaps or is adjacent; extend coverage regardless of filled/scheduled
if (span.start_block_height <= covered_until)
covered_until = std::max(covered_until, span.start_block_height + span.nblocks);
} }
return last_needed_height;
return covered_until;
} }
void block_queue::print() const void block_queue::print() const