From d57c2dc4e5b28dd868a5d735bbb384cbc3414afc Mon Sep 17 00:00:00 2001 From: Jacek Sieka Date: Thu, 13 Jan 2022 10:37:53 +0100 Subject: [PATCH] use tail block as sync pivot (#3276) When syncing, we show how much of the sync has completed - with checkpoint sync, the syncing does not always go from slot 0 to head, but rather can start in the middle. To show a consistent `%` between restarts, we introduce the concept of a pivot point, such that if I sync 10% of the chain, then restart the client, it picks up at 10% (instead of counting from 0). What it looks like: ``` INF ... sync="01d12h41m (15.96%) 13.5158slots/s (QDDQDDQQDP:339018)" ... ``` --- beacon_chain/nimbus_beacon_node.nim | 3 ++- beacon_chain/sync/sync_manager.nim | 12 ++++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/beacon_chain/nimbus_beacon_node.nim b/beacon_chain/nimbus_beacon_node.nim index 81a4b830a..8bb668da2 100644 --- a/beacon_chain/nimbus_beacon_node.nim +++ b/beacon_chain/nimbus_beacon_node.nim @@ -468,7 +468,8 @@ proc init*(T: type BeaconNode, taskpool) syncManager = newSyncManager[Peer, PeerID]( network.peerPool, SyncQueueKind.Forward, getLocalHeadSlot, getLocalWallSlot, - getFirstSlotAtFinalizedEpoch, getBackfillSlot, blockVerifier) + getFirstSlotAtFinalizedEpoch, getBackfillSlot, dag.tail.slot, + blockVerifier) let stateTtlCache = if config.restCacheSize > 0: StateTtlCache.init( diff --git a/beacon_chain/sync/sync_manager.nim b/beacon_chain/sync/sync_manager.nim index d7a448162..b92c11bb4 100644 --- a/beacon_chain/sync/sync_manager.nim +++ b/beacon_chain/sync/sync_manager.nim @@ -54,6 +54,7 @@ type getSafeSlot: GetSlotCallback getFirstSlot: GetSlotCallback getLastSlot: GetSlotCallback + progressPivot: Slot workers: array[SyncWorkersCount, SyncWorker[A, B]] notInSyncEvent: AsyncEvent rangeAge: uint64 @@ -98,6 +99,7 @@ proc newSyncManager*[A, B](pool: PeerPool[A, B], getLocalWallSlotCb: GetSlotCallback, getFinalizedSlotCb: GetSlotCallback, getBackfillSlotCb: GetSlotCallback, + progressPivot: Slot, blockVerifier: BlockVerifier, maxStatusAge = uint64(SLOTS_PER_EPOCH * 4), maxHeadAge = uint64(SLOTS_PER_EPOCH * 1), @@ -120,6 +122,7 @@ proc newSyncManager*[A, B](pool: PeerPool[A, B], getSafeSlot: getSafeSlot, getFirstSlot: getFirstSlot, getLastSlot: getLastSlot, + progressPivot: progressPivot, maxHeadAge: maxHeadAge, sleepTime: sleepTime, chunkSize: chunkSize, @@ -550,8 +553,13 @@ proc syncLoop[A, B](man: SyncManager[A, B]) {.async.} = direction = man.direction, topics = "syncman" let - progress = float(man.queue.progress()) - total = float(man.queue.total()) + pivot = man.progressPivot + progress = float( + if man.queue.kind == SyncQueueKind.Forward: man.queue.outSlot - pivot + else: pivot - man.queue.outSlot) + total = float( + if man.queue.kind == SyncQueueKind.Forward: man.queue.finalSlot - pivot + else: pivot - man.queue.finalSlot) remaining = total - progress done = if total > 0.0: progress / total else: 1.0 timeleft =