Fix issue when VC could not be interrupted while its in pre-genesis period. (#5424)

This commit is contained in:
Eugene Kabanov 2023-09-15 13:39:26 +03:00 committed by GitHub
parent 325d5a6afa
commit 12ef43bcc0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 8 deletions

View File

@ -411,14 +411,16 @@ proc runPreGenesisWaitingLoop(vc: ValidatorClientRef) {.async.} =
try:
await sleepAsync(vc.beaconClock.durationToNextSlot())
false
except CancelledError:
except CancelledError as exc:
debug "Pre-genesis waiting loop was interrupted"
true
raise exc
except CatchableError as exc:
error "Pre-genesis waiting loop failed with unexpected error",
err_name = $exc.name, err_msg = $exc.msg
true
vc.preGenesisEvent.fire()
if not(breakLoop):
vc.preGenesisEvent.fire()
proc runGenesisWaitingLoop(vc: ValidatorClientRef) {.async.} =
var breakLoop = false
@ -436,14 +438,16 @@ proc runGenesisWaitingLoop(vc: ValidatorClientRef) {.async.} =
try:
await sleepAsync(vc.beaconClock.durationToNextSlot())
false
except CancelledError:
except CancelledError as exc:
debug "Genesis waiting loop was interrupted"
true
raise exc
except CatchableError as exc:
error "Genesis waiting loop failed with unexpected error",
err_name = $exc.name, err_msg = $exc.msg
true
vc.genesisEvent.fire()
if not(breakLoop):
vc.genesisEvent.fire()
proc asyncRun*(vc: ValidatorClientRef) {.async.} =
vc.fallbackService.start()
@ -488,9 +492,10 @@ proc asyncRun*(vc: ValidatorClientRef) {.async.} =
debug "Stopping main processing loop"
var pending: seq[Future[void]]
if not(vc.runSlotLoopFut.finished()):
if not(isNil(vc.runSlotLoopFut)) and not(vc.runSlotLoopFut.finished()):
pending.add(vc.runSlotLoopFut.cancelAndWait())
if not(vc.runKeystoreCachePruningLoopFut.finished()):
if not(isNil(vc.runKeystoreCachePruningLoopFut)) and
not(vc.runKeystoreCachePruningLoopFut.finished()):
pending.add(vc.runKeystoreCachePruningLoopFut.cancelAndWait())
if not(doppelEventFut.finished()):
pending.add(doppelEventFut.cancelAndWait())