optimize LC sync task scheduling (#5112)

- When syncing `LightClientUpdatesByRange`, and peer replies with
  fewer periods than requested, no need to delay next request.
- When `FinalityUpdate` / `OptimisticUpdate` sync fails,
  no need to retry immediately.
This commit is contained in:
Etan Kissling 2023-06-21 19:44:49 +02:00 committed by GitHub
parent 6175fa8a79
commit bab6a77abc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -341,6 +341,7 @@ template query[E](
self.query(e, Nothing())
type SchedulingMode = enum
Now,
Soon,
CurrentPeriod,
NextPeriod
@ -353,6 +354,8 @@ func fetchTime(
let
remainingTime =
case schedulingMode:
of Now:
return wallTime
of Soon:
chronos.seconds(0)
of CurrentPeriod:
@ -413,9 +416,12 @@ proc loop(self: LightClientManager) {.async.} =
await self.query(OptimisticUpdate)
schedulingMode =
if not didProgress or not self.isGossipSupported(current):
Soon
elif syncTask.kind != LcSyncKind.OptimisticUpdate:
if not self.isGossipSupported(current):
if didProgress:
Now
else:
Soon
elif self.getFinalizedPeriod() != self.getOptimisticPeriod():
CurrentPeriod
else:
NextPeriod