@@ -970,20 +970,31 @@ proc getStatusPeriod*(
970970 peerFinalizedCheckpoint = peer.getFinalizedCheckpoint ()
971971 secondsPerSlot = int (dag.cfg.timeParams.SECONDS_PER_SLOT )
972972
973+ if peerFinalizedCheckpoint.epoch < overseer.lastSeenCheckpoint.get.epoch:
974+ # Peer is not in sync with the network.
975+ return chronos.seconds (10 * secondsPerSlot)
976+
973977 if localHead.slot.epoch () < peerFinalizedCheckpoint.epoch:
974978 # We are behind peer's finalized checkpoint, performing forward syncing.
975979 # 10 slots (mainnet: 2.minutes)
976- chronos.seconds (10 * secondsPerSlot)
977- else :
978- if peerHead.slot.epoch () - peerFinalizedCheckpoint.epoch >= 3 :
979- # In periods of non-finality we try to follow every peer's head, in
980- # this case we should update peer's status very often.
981- # 1 slot (mainnet: 12.seconds)
982- chronos.seconds (1 * secondsPerSlot)
983- else :
984- # Node is optimistically synced or almost synced.
985- # 5 slots (mainnet: 1.minutes)
986- chronos.seconds (5 * secondsPerSlot)
980+ return chronos.seconds (10 * secondsPerSlot)
981+
982+ if (localHead.slot >= peerHead.slot) and
983+ (localHead.slot < overseer.lastSeenHead.get.slot):
984+ # Peer's head slot is behind ours, but we still not in sync with network.
985+ # So we need to refresh status information immediately.
986+ return chronos.seconds (0 )
987+
988+ if peerHead.slot < overseer.lastSeenHead.get.slot:
989+ # Peer's head is behind network's peer head.
990+ return chronos.seconds (1 * secondsPerSlot)
991+
992+ if localHead.slot == overseer.lastSeenHead.get.slot:
993+ # Node is optimistically synced
994+ return chronos.seconds (5 * secondsPerSlot)
995+
996+ # Node is almost synced, but still behind peer's head.
997+ chronos.seconds (1 * secondsPerSlot)
987998
988999func getMissingSidecarsRoots (entry: SyncDagEntryRef ): seq [BlockId ] =
9891000 var res: seq [BlockId ]
0 commit comments