Skip to content

Commit

Permalink
fix(validation): asyncSpawns run (#1039)
Browse files Browse the repository at this point in the history
- annotates run with raises: []
- asyncSpawns run, to ensure there are no escaping exceptions
  • Loading branch information
emizzle authored Dec 16, 2024
1 parent b0cc27f commit bef1160
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions codex/validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ proc markProofsAsMissing(validation: Validation) {.async.} =
let previousPeriod = validation.getCurrentPeriod() - 1
await validation.markProofAsMissing(slotId, previousPeriod)

proc run(validation: Validation) {.async.} =
proc run(validation: Validation) {.async: (raises: []).} =
trace "Validation started"
try:
while true:
Expand All @@ -118,7 +118,7 @@ proc run(validation: Validation) {.async.} =
await validation.markProofsAsMissing()
except CancelledError:
trace "Validation stopped"
discard
discard # do not propagate as run is asyncSpawned
except CatchableError as e:
error "Validation failed", msg = e.msg

Expand Down Expand Up @@ -149,9 +149,10 @@ proc start*(validation: Validation) {.async.} =
await validation.subscribeSlotFilled()
await validation.restoreHistoricalState()
validation.running = validation.run()
asyncSpawn validation.running

proc stop*(validation: Validation) {.async.} =
if not isNil(validation.running):
if not validation.running.isNil and not validation.running.finished:
await validation.running.cancelAndWait()
while validation.subscriptions.len > 0:
let subscription = validation.subscriptions.pop()
Expand Down

0 comments on commit bef1160

Please sign in to comment.