[#628] Fix off-by-one download blocks

This should yield approximatly a 10% performance improvement, as it prevents downloading duplicate blocks.
This commit is contained in:
Carter Jernigan 2022-07-28 09:58:08 -04:00 committed by Carter Jernigan
parent 3535ba905e
commit 1f35e37a5e
1 changed files with 3 additions and 2 deletions

View File

@ -566,7 +566,8 @@ class CompactBlockProcessor internal constructor(
twig("found $missingBlockCount missing blocks, downloading in $batches batches of $DOWNLOAD_BATCH_SIZE...")
for (i in 1..batches) {
retryUpTo(RETRIES, { CompactBlockProcessorException.FailedDownload(it) }) {
val end = BlockHeight(
val end = BlockHeight.new(
network,
min(
(range.start.value + (i * DOWNLOAD_BATCH_SIZE)) - 1,
range.endInclusive.value
@ -581,7 +582,7 @@ class CompactBlockProcessor internal constructor(
_progress.send(progress)
val lastDownloadedHeight = downloader.getLastDownloadedHeight()
updateProgress(lastDownloadedHeight = lastDownloadedHeight)
downloadedBlockHeight = end
downloadedBlockHeight = end + 1
}
}
Twig.clip("downloading")