diff --git a/codex.nimble b/codex.nimble index 29480888..e1200d71 100644 --- a/codex.nimble +++ b/codex.nimble @@ -20,7 +20,7 @@ requires "nimcrypto >= 0.4.1" requires "nitro >= 0.5.1 & < 0.6.0" requires "presto" requires "protobuf_serialization >= 0.2.0 & < 0.3.0" -requires "questionable >= 0.10.6 & < 0.11.0" +requires "questionable >= 0.10.12 & < 0.11.0" requires "secp256k1" requires "stew" requires "upraises >= 0.1.0 & < 0.2.0" diff --git a/codex/sales/reservations.nim b/codex/sales/reservations.nim index ec5d2777..19aff95d 100644 --- a/codex/sales/reservations.nim +++ b/codex/sales/reservations.nim @@ -181,7 +181,7 @@ proc getImpl( self: Reservations, key: Key): Future[?!seq[byte]] {.async.} = - if exists =? (await self.exists(key)) and not exists: + if not await self.exists(key): let err = newException(NotExistsError, "object with key " & $key & " does not exist") return failure(err) @@ -226,7 +226,7 @@ proc delete( trace "deleting object", key - if exists =? (await self.exists(key)) and not exists: + if not await self.exists(key): return success() if err =? (await self.repo.metaDs.delete(key)).errorOption: diff --git a/codex/sales/states/cancelled.nim b/codex/sales/states/cancelled.nim index 54b8e553..3f0e2157 100644 --- a/codex/sales/states/cancelled.nim +++ b/codex/sales/states/cancelled.nim @@ -20,19 +20,15 @@ method run*(state: SaleCancelled, machine: Machine): Future[?State] {.async.} = without request =? data.request: raiseAssert "no sale request" - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - - let slot = Slot(request: request, slotIndex: slotIndex) - debug "Collecting collateral and partial payout", requestId = $data.requestId, slotIndex + let slot = Slot(request: request, slotIndex: data.slotIndex) + debug "Collecting collateral and partial payout", requestId = $data.requestId, slotIndex = $data.slotIndex await market.freeSlot(slot.id) if onClear =? agent.context.onClear and - request =? data.request and - slotIndex =? data.slotIndex: - onClear(request, slotIndex) + request =? data.request: + onClear(request, data.slotIndex) if onCleanUp =? agent.onCleanUp: await onCleanUp() - warn "Sale cancelled due to timeout", requestId = $data.requestId, slotIndex + warn "Sale cancelled due to timeout", requestId = $data.requestId, slotIndex = $data.slotIndex diff --git a/codex/sales/states/downloading.nim b/codex/sales/states/downloading.nim index 50f4f8e6..6298657c 100644 --- a/codex/sales/states/downloading.nim +++ b/codex/sales/states/downloading.nim @@ -42,15 +42,12 @@ method run*(state: SaleDownloading, machine: Machine): Future[?State] {.async.} without request =? data.request: raiseAssert "no sale request" - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - without reservation =? data.reservation: raiseAssert("no reservation") logScope: requestId = request.id - slotIndex + slotIndex = data.slotIndex reservationId = reservation.id availabilityId = reservation.availabilityId @@ -72,7 +69,7 @@ method run*(state: SaleDownloading, machine: Machine): Future[?State] {.async.} trace "Starting download" if err =? (await onStore(request, - slotIndex, + data.slotIndex, onBatch)).errorOption: return some State(SaleErrored(error: err)) diff --git a/codex/sales/states/errored.nim b/codex/sales/states/errored.nim index a6d5bfb4..c934be4b 100644 --- a/codex/sales/states/errored.nim +++ b/codex/sales/states/errored.nim @@ -25,9 +25,8 @@ method run*(state: SaleErrored, machine: Machine): Future[?State] {.async.} = error "Sale error", error=state.error.msgDetail, requestId = data.requestId, slotIndex = data.slotIndex if onClear =? context.onClear and - request =? data.request and - slotIndex =? data.slotIndex: - onClear(request, slotIndex) + request =? data.request: + onClear(request, data.slotIndex) if onCleanUp =? agent.onCleanUp: await onCleanUp() diff --git a/codex/sales/states/failed.nim b/codex/sales/states/failed.nim index 461beb13..cd954be4 100644 --- a/codex/sales/states/failed.nim +++ b/codex/sales/states/failed.nim @@ -20,11 +20,8 @@ method run*(state: SaleFailed, machine: Machine): Future[?State] {.async.} = without request =? data.request: raiseAssert "no sale request" - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - - let slot = Slot(request: request, slotIndex: slotIndex) - debug "Removing slot from mySlots", requestId = $data.requestId, slotIndex + let slot = Slot(request: request, slotIndex: data.slotIndex) + debug "Removing slot from mySlots", requestId = $data.requestId, slotIndex = $data.slotIndex await market.freeSlot(slot.id) let error = newException(SaleFailedError, "Sale failed") diff --git a/codex/sales/states/filled.nim b/codex/sales/states/filled.nim index 5139a8c3..a6803c25 100644 --- a/codex/sales/states/filled.nim +++ b/codex/sales/states/filled.nim @@ -29,19 +29,17 @@ method run*(state: SaleFilled, machine: Machine): Future[?State] {.async.} = let agent = SalesAgent(machine) let data = agent.data let context = agent.context + let market = context.market - - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - - let host = await market.getHost(data.requestId, slotIndex) + let host = await market.getHost(data.requestId, data.slotIndex) let me = await market.getSigner() - if host == me.some: - info "Slot succesfully filled", requestId = $data.requestId, slotIndex - if request =? data.request and slotIndex =? data.slotIndex: + if host == me.some: + info "Slot succesfully filled", requestId = $data.requestId, slotIndex = $data.slotIndex + + if request =? data.request: if onFilled =? agent.onFilled: - onFilled(request, slotIndex) + onFilled(request, data.slotIndex) when codex_enable_proof_failures: if context.simulateProofFailures > 0: diff --git a/codex/sales/states/filling.nim b/codex/sales/states/filling.nim index 5cf6a06d..b1e8471c 100644 --- a/codex/sales/states/filling.nim +++ b/codex/sales/states/filling.nim @@ -32,8 +32,5 @@ method run(state: SaleFilling, machine: Machine): Future[?State] {.async.} = without (collateral =? data.request.?ask.?collateral): raiseAssert "Request not set" - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - - debug "Filling slot", requestId = $data.requestId, slotIndex - await market.fillSlot(data.requestId, slotIndex, state.proof, collateral) + debug "Filling slot", requestId = $data.requestId, slotIndex = $data.slotIndex + await market.fillSlot(data.requestId, data.slotIndex, state.proof, collateral) diff --git a/codex/sales/states/finished.nim b/codex/sales/states/finished.nim index 5b1c6003..539cde62 100644 --- a/codex/sales/states/finished.nim +++ b/codex/sales/states/finished.nim @@ -27,10 +27,7 @@ method run*(state: SaleFinished, machine: Machine): Future[?State] {.async.} = without request =? data.request: raiseAssert "no sale request" - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - - info "Slot finished and paid out", requestId = $data.requestId, slotIndex + info "Slot finished and paid out", requestId = $data.requestId, slotIndex = $data.slotIndex if onCleanUp =? agent.onCleanUp: await onCleanUp() diff --git a/codex/sales/states/initialproving.nim b/codex/sales/states/initialproving.nim index 7f5da6b6..0cbbb7b7 100644 --- a/codex/sales/states/initialproving.nim +++ b/codex/sales/states/initialproving.nim @@ -30,11 +30,8 @@ method run*(state: SaleInitialProving, machine: Machine): Future[?State] {.async without onProve =? context.onProve: raiseAssert "onProve callback not set" - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - debug "Generating initial proof", requestId = $data.requestId - let proof = await onProve(Slot(request: request, slotIndex: slotIndex)) + let proof = await onProve(Slot(request: request, slotIndex: data.slotIndex)) debug "Finished proof calculation", requestId = $data.requestId return some State(SaleFilling(proof: proof)) diff --git a/codex/sales/states/payout.nim b/codex/sales/states/payout.nim index 68cdfbc9..a70f7eac 100644 --- a/codex/sales/states/payout.nim +++ b/codex/sales/states/payout.nim @@ -28,11 +28,8 @@ method run(state: SalePayout, machine: Machine): Future[?State] {.async.} = without request =? data.request: raiseAssert "no sale request" - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - - let slot = Slot(request: request, slotIndex: slotIndex) - debug "Collecting finished slot's reward", requestId = $data.requestId, slotIndex + let slot = Slot(request: request, slotIndex: data.slotIndex) + debug "Collecting finished slot's reward", requestId = $data.requestId, slotIndex = $data.slotIndex await market.freeSlot(slot.id) return some State(SaleFinished()) diff --git a/codex/sales/states/proving.nim b/codex/sales/states/proving.nim index 5586c9ca..22cd50b4 100644 --- a/codex/sales/states/proving.nim +++ b/codex/sales/states/proving.nim @@ -112,18 +112,15 @@ method run*(state: SaleProving, machine: Machine): Future[?State] {.async.} = without onProve =? context.onProve: raiseAssert "onProve callback not set" - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - without market =? context.market: raiseAssert("market not set") without clock =? context.clock: raiseAssert("clock not set") - debug "Start proving", requestId = $data.requestId, slotIndex + debug "Start proving", requestId = $data.requestId, slotIndex = $data.slotIndex try: - let loop = state.proveLoop(market, clock, request, slotIndex, onProve) + let loop = state.proveLoop(market, clock, request, data.slotIndex, onProve) state.loop = loop await loop except CancelledError: @@ -133,7 +130,7 @@ method run*(state: SaleProving, machine: Machine): Future[?State] {.async.} = return some State(SaleErrored(error: e)) finally: # Cleanup of the proving loop - debug "Stopping proving.", requestId = $data.requestId, slotIndex + debug "Stopping proving.", requestId = $data.requestId, slotIndex = $data.slotIndex if not state.loop.isNil: if not state.loop.finished: diff --git a/codex/sales/states/unknown.nim b/codex/sales/states/unknown.nim index 0cd5684d..3672ed96 100644 --- a/codex/sales/states/unknown.nim +++ b/codex/sales/states/unknown.nim @@ -32,14 +32,8 @@ method run*(state: SaleUnknown, machine: Machine): Future[?State] {.async.} = await agent.retrieveRequest() await agent.subscribe() - without slotIndex =? data.slotIndex: - raiseAssert("no slot index assigned") - - let slotId = slotId(data.requestId, slotIndex) - - without slotState =? await market.slotState(slotId): - let error = newException(SaleUnknownError, "cannot retrieve slot state") - return some State(SaleErrored(error: error)) + let slotId = slotId(data.requestId, data.slotIndex) + let slotState = await market.slotState(slotId) case slotState of SlotState.Free: diff --git a/tests/codex/sales/testreservations.nim b/tests/codex/sales/testreservations.nim index 4a7d94d7..3bfee998 100644 --- a/tests/codex/sales/testreservations.nim +++ b/tests/codex/sales/testreservations.nim @@ -83,8 +83,7 @@ asyncchecksuite "Reservations module": test "reserved availability exists": let availability = createAvailability() - without exists =? await reservations.exists(availability.key.get): - fail() + let exists = await reservations.exists(availability.key.get) check exists diff --git a/tests/integration/nodes.nim b/tests/integration/nodes.nim index d85e9a6f..777de80b 100644 --- a/tests/integration/nodes.nim +++ b/tests/integration/nodes.nim @@ -88,5 +88,4 @@ proc restart*(node: NodeProcess) = node.waitUntilStarted() proc removeDataDir*(node: NodeProcess) = - if dataDir =? node.dataDir: - removeDir(dataDir) + removeDir(node.dataDir) diff --git a/tests/integration/testIntegration.nim b/tests/integration/testIntegration.nim index 5bdc0d1f..9b311a05 100644 --- a/tests/integration/testIntegration.nim +++ b/tests/integration/testIntegration.nim @@ -22,7 +22,9 @@ import ./twonodes twonodessuite "Integration tests", debug1 = false, debug2 = false: proc purchaseStateIs(client: CodexClient, id: PurchaseId, state: string): bool = - client.getPurchase(id).option.?state == some state + without purchase =? client.getPurchase(id): + return false + return purchase.state == state setup: # Our Hardhat configuration does use automine, which means that time tracked by `provider.currentTime()` is not diff --git a/vendor/questionable b/vendor/questionable index e56cf86c..2dd6b6b2 160000 --- a/vendor/questionable +++ b/vendor/questionable @@ -1 +1 @@ -Subproject commit e56cf86c4a089c78a1b7c3005f13343bfbbe3b48 +Subproject commit 2dd6b6b220f9f14a1231f6cafdf24f012bcc8414