fix #3674 (Sync progress >100% on checkpoint sync) (#3736)

Corrects an off-by-1 in the reported sync percentage computation.
New logic is based on `SyncQueue.total` and `SyncQueue.progress`
with `pivot` instead of `sq.startSlot`.
This commit is contained in:
Etan Kissling 2022-06-13 19:00:36 +02:00 committed by GitHub
parent 51885519a2
commit 7b04a94d43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 9 deletions

View File

@ -562,18 +562,29 @@ proc syncLoop[A, B](man: SyncManager[A, B]) {.async.} =
let let
pivot = man.progressPivot pivot = man.progressPivot
progress = float( progress =
if man.queue.kind == SyncQueueKind.Forward: man.queue.outSlot - pivot case man.queue.kind
else: pivot - man.queue.outSlot) of SyncQueueKind.Forward:
total = float( man.queue.outSlot - pivot
if man.queue.kind == SyncQueueKind.Forward: man.queue.finalSlot - pivot of SyncQueueKind.Backward:
else: pivot - man.queue.finalSlot) pivot - man.queue.outSlot
total =
case man.queue.kind
of SyncQueueKind.Forward:
man.queue.finalSlot + 1'u64 - pivot
of SyncQueueKind.Backward:
pivot + 1'u64 - man.queue.finalSlot
remaining = total - progress remaining = total - progress
done = if total > 0.0: progress / total else: 1.0 done =
if total > 0:
progress.float / total.float
else:
1.0
timeleft = timeleft =
if man.avgSyncSpeed >= 0.001: if man.avgSyncSpeed >= 0.001:
Duration.fromFloatSeconds(remaining / man.avgSyncSpeed) Duration.fromFloatSeconds(remaining.float / man.avgSyncSpeed)
else: InfiniteDuration else:
InfiniteDuration
currentSlot = Base10.toString( currentSlot = Base10.toString(
if man.queue.kind == SyncQueueKind.Forward: if man.queue.kind == SyncQueueKind.Forward:
max(uint64(man.queue.outSlot), 1'u64) - 1'u64 max(uint64(man.queue.outSlot), 1'u64) - 1'u64