diff options
| author | 0xFFFC0000 <0xFFFC0000@proton.me> | 2025-11-05 21:07:25 +0000 |
|---|---|---|
| committer | 0xfffc <0xfffc0000@proton.me> | 2025-11-11 00:28:50 +0330 |
| commit | dafecd0addb171751efd31fea417d36da84e5efe (patch) | |
| tree | 366f9c377ecf48576dd1b57a98e67c9fa924da2b /src/cryptonote_protocol | |
| parent | 3cc9d65c9374b541e64320052c933184944375ea (diff) | |
| download | monzero-core-dafecd0addb171751efd31fea417d36da84e5efe.tar.gz monzero-core-dafecd0addb171751efd31fea417d36da84e5efe.tar.xz monzero-core-dafecd0addb171751efd31fea417d36da84e5efe.zip | |
cryptonote_protocol: accurate next_needed_height when there is an overlap
Diffstat (limited to 'src/cryptonote_protocol')
| -rw-r--r-- | src/cryptonote_protocol/block_queue.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/cryptonote_protocol/block_queue.cpp b/src/cryptonote_protocol/block_queue.cpp index f8962df06..7eadb72f2 100644 --- a/src/cryptonote_protocol/block_queue.cpp +++ b/src/cryptonote_protocol/block_queue.cpp @@ -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); if (blocks.empty()) return blockchain_height; - uint64_t last_needed_height = blockchain_height; - bool first = true; + + uint64_t covered_until = blockchain_height; + 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; - if (span.start_block_height != last_needed_height || (first && span.blocks.empty())) - return last_needed_height; - last_needed_height = span.start_block_height + span.nblocks; - first = false; + + // If this span starts after what we already have/scheduled, we found the first gap + if (span.start_block_height > covered_until) + 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 |
