Skip to content

Commit

Permalink
Feat/bump questionable (#627)
Browse files Browse the repository at this point in the history
* Bumps questionable version to 0.10.12

* removes unnecessary questionnable bindings.

* Fixes tests

* unnecessary whitespaces
  • Loading branch information
benbierens authored Nov 17, 2023
1 parent 40d7714 commit bece1b8
Show file tree
Hide file tree
Showing 17 changed files with 37 additions and 71 deletions.
2 changes: 1 addition & 1 deletion codex.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions codex/sales/reservations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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:
Expand Down
14 changes: 5 additions & 9 deletions codex/sales/states/cancelled.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions codex/sales/states/downloading.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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))

Expand Down
5 changes: 2 additions & 3 deletions codex/sales/states/errored.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 2 additions & 5 deletions codex/sales/states/failed.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
14 changes: 6 additions & 8 deletions codex/sales/states/filled.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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 market = context.market
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
info "Slot succesfully filled", requestId = $data.requestId, slotIndex = $data.slotIndex

if request =? data.request and 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:
Expand Down
7 changes: 2 additions & 5 deletions codex/sales/states/filling.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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)
5 changes: 1 addition & 4 deletions codex/sales/states/finished.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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()
5 changes: 1 addition & 4 deletions codex/sales/states/initialproving.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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))
7 changes: 2 additions & 5 deletions codex/sales/states/payout.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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())
9 changes: 3 additions & 6 deletions codex/sales/states/proving.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
10 changes: 2 additions & 8 deletions codex/sales/states/unknown.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 1 addition & 2 deletions tests/codex/sales/testreservations.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 1 addition & 2 deletions tests/integration/nodes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -88,5 +88,4 @@ proc restart*(node: NodeProcess) =
node.waitUntilStarted()

proc removeDataDir*(node: NodeProcess) =
if dataDir =? node.dataDir:
removeDir(dataDir)
removeDir(node.dataDir)
4 changes: 3 additions & 1 deletion tests/integration/testIntegration.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion vendor/questionable

0 comments on commit bece1b8

Please sign in to comment.