Add time monitoring loop into service.

This commit is contained in:
cheatfate 2023-04-13 20:34:45 +03:00
parent 317188e3e7
commit 697006278f
No known key found for this signature in database
GPG Key ID: 46ADD633A7201F95
1 changed files with 6 additions and 1 deletions

View File

@ -226,6 +226,7 @@ proc pollForTime(service: MonitorServiceRef,
timeOffset = tres.get()
timeDuration = nanoseconds(abs(tres.get()))
soffset = if tres.get() < 0: "-" & $timeDuration else: $timeDuration
debug "Remote beacon time offset received", offset = soffset
if timeDuration >= WARNING_TIME_OFFSET:
warn "Remote beacon node has significant time offset", offset = soffset
elif timeDuration >= NOTICE_TIME_OFFSET:
@ -311,18 +312,22 @@ proc mainLoop(service: MonitorServiceRef) {.async.} =
var breakLoop = false
var blockMonitoringLoopFut: Future[void]
var timeMonitoringLoopFut: Future[void]
while not(breakLoop):
breakLoop =
try:
blockMonitoringLoopFut = service.blockMonitoringLoop()
await allFutures(blockMonitoringLoopFut)
timeMonitoringLoopFut = service.timeMonitoringLoop()
await allFutures(blockMonitoringLoopFut, timeMonitoringLoopFut)
false
except CancelledError:
debug "Service interrupted"
var pending: seq[Future[void]]
if not(blockMonitoringLoopFut.finished()):
pending.add(blockMonitoringLoopFut.cancelAndWait())
if not(timeMonitoringLoopFut.finished()):
pending.add(timeMonitoringLoopFut.cancelAndWait())
await allFutures(pending)
true
except CatchableError as exc: