diff --git a/codex/node.nim b/codex/node.nim index 956acd49..f180fd62 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -757,15 +757,15 @@ proc stop*(self: CodexNodeRef) {.async.} = if not self.discovery.isNil: await self.discovery.stop() - if not self.clock.isNil: - await self.clock.stop() - if clientContracts =? self.contracts.client: await clientContracts.stop() if hostContracts =? self.contracts.host: await hostContracts.stop() + if not self.clock.isNil: + await self.clock.stop() + if validatorContracts =? self.contracts.validator: await validatorContracts.stop() diff --git a/codex/utils/asyncstatemachine.nim b/codex/utils/asyncstatemachine.nim index 3f10cfbe..8cd3390a 100644 --- a/codex/utils/asyncstatemachine.nim +++ b/codex/utils/asyncstatemachine.nim @@ -67,23 +67,21 @@ proc run(machine: Machine, state: State) {.async.} = proc scheduler(machine: Machine) {.async.} = var running: Future[void] - try: - while machine.started: - let event = await machine.scheduled.get().track(machine) - if next =? event(machine.state): - if not running.isNil and not running.finished: - await running.cancelAndWait() - let fromState = if machine.state.isNil: "" else: $machine.state - machine.state = next - debug "enter state", state = fromState & " => " & $machine.state - running = machine.run(machine.state) - running - .track(machine) - .catch((err: ref CatchableError) => - machine.schedule(machine.onError(err)) - ) - except CancelledError: - discard + while machine.started: + let event = await machine.scheduled.get().track(machine) + if next =? event(machine.state): + if not running.isNil and not running.finished: + trace "cancelling current state", state = $machine.state + await running.cancelAndWait() + let fromState = if machine.state.isNil: "" else: $machine.state + machine.state = next + debug "enter state", state = fromState & " => " & $machine.state + try: + running = machine.run(machine.state).track(machine) + except CancelledError as e: + trace("run cancelled in state, swallowing", state = $machine.state) + except CatchableError as e: + machine.schedule(machine.onError(e)) proc start*(machine: Machine, initialState: State) = if machine.started: @@ -93,12 +91,13 @@ proc start*(machine: Machine, initialState: State) = machine.scheduled = newAsyncQueue[Event]() machine.started = true - machine.scheduler() - .track(machine) - .catch((err: ref CatchableError) => - error("Error in scheduler", error = err.msg) - ) - machine.schedule(Event.transition(machine.state, initialState)) + try: + discard machine.scheduler().track(machine) + machine.schedule(Event.transition(machine.state, initialState)) + except CancelledError as e: + discard + except CatchableError as e: + error("Error in scheduler", error = e.msg) proc stop*(machine: Machine) {.async.} = if not machine.started: diff --git a/vendor/nim-ethers b/vendor/nim-ethers index 507ac6a4..d11c3cb1 160000 --- a/vendor/nim-ethers +++ b/vendor/nim-ethers @@ -1 +1 @@ -Subproject commit 507ac6a4cc71cec9be7693fa393db4a49b52baf9 +Subproject commit d11c3cb1e69c9cce3ddb5c026594ac37ebed373b