sales: do not raise in proving loop when slot is cancelled
Allow the onCancelled callback to handle cancellation, and the onFailed callback to handle failed requests.
This commit is contained in:
parent
ea8ab92a88
commit
fb1de95a3c
|
@ -67,19 +67,26 @@ proc proveLoop(
|
|||
while true:
|
||||
let currentPeriod = await getCurrentPeriod()
|
||||
let slotState = await market.slotState(slot.id)
|
||||
if slotState == SlotState.Finished:
|
||||
|
||||
case slotState
|
||||
of SlotState.Filled:
|
||||
debug "Proving for new period", period = currentPeriod
|
||||
if (await market.isProofRequired(slotId)) or (await market.willProofBeRequired(slotId)):
|
||||
let challenge = await market.getChallenge(slotId)
|
||||
debug "Proof is required", period = currentPeriod, challenge = challenge
|
||||
await state.prove(slot, challenge, onProve, market, currentPeriod)
|
||||
of SlotState.Cancelled:
|
||||
debug "Slot reached cancelled state"
|
||||
# do nothing, let onCancelled callback take care of it
|
||||
of SlotState.Failed:
|
||||
debug "Slot reached failed state"
|
||||
# do nothing, let onFailed callback take care of it
|
||||
of SlotState.Finished:
|
||||
debug "Slot reached finished state", period = currentPeriod
|
||||
return
|
||||
|
||||
if slotState != SlotState.Filled:
|
||||
raise newException(SlotNotFilledError, "Slot is not in Filled state!")
|
||||
|
||||
debug "Proving for new period", period = currentPeriod
|
||||
|
||||
if (await market.isProofRequired(slotId)) or (await market.willProofBeRequired(slotId)):
|
||||
let challenge = await market.getChallenge(slotId)
|
||||
debug "Proof is required", period = currentPeriod, challenge = challenge
|
||||
await state.prove(slot, challenge, onProve, market, currentPeriod)
|
||||
return # exit the loop
|
||||
else:
|
||||
let message = "Slot is not in Filled state, but in state: " & $slotState
|
||||
raise newException(SlotNotFilledError, message)
|
||||
|
||||
debug "waiting until next period"
|
||||
await waitUntilPeriod(currentPeriod + 1)
|
||||
|
|
|
@ -5,6 +5,7 @@ import pkg/codex/sales/states/proving
|
|||
import pkg/codex/sales/states/cancelled
|
||||
import pkg/codex/sales/states/failed
|
||||
import pkg/codex/sales/states/payout
|
||||
import pkg/codex/sales/states/errored
|
||||
import pkg/codex/sales/salesagent
|
||||
import pkg/codex/sales/salescontext
|
||||
|
||||
|
@ -81,6 +82,17 @@ asyncchecksuite "sales state 'proving'":
|
|||
check eventually future.finished
|
||||
check !(future.read()) of SalePayout
|
||||
|
||||
test "switches to error state when slot is no longer filled":
|
||||
market.slotState[slot.id] = SlotState.Filled
|
||||
|
||||
let future = state.run(agent)
|
||||
|
||||
market.slotState[slot.id] = SlotState.Free
|
||||
await market.advanceToNextPeriod()
|
||||
|
||||
check eventually future.finished
|
||||
check !(future.read()) of SaleErrored
|
||||
|
||||
test "onProve callback provides proof challenge":
|
||||
market.proofChallenge = ProofChallenge.example
|
||||
market.slotState[slot.id] = SlotState.Filled
|
||||
|
|
Loading…
Reference in New Issue