From fd6f8a13866a47518c10f2e751f1f8dc6d25ccff Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Tue, 2 Aug 2022 17:33:32 +0200 Subject: [PATCH] [sales] Pass along request and slot index in onProve callback --- codex/node.nim | 4 ++-- codex/sales.nim | 5 +++-- tests/codex/testsales.nim | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/codex/node.nim b/codex/node.nim index 4d489c83..dba57555 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -339,8 +339,8 @@ proc start*(node: CodexNodeRef) {.async.} = contracts.sales.onClear = proc(availability: Availability, request: StorageRequest) = # TODO: remove data from local storage discard - - contracts.sales.onProve = proc(cid: string): Future[seq[byte]] {.async.} = + contracts.sales.onProve = proc(request: StorageRequest, + slot: UInt256): Future[seq[byte]] {.async.} = # TODO: generate proof return @[42'u8] diff --git a/codex/sales.nim b/codex/sales.nim index 1fc0f8ce..3664c81a 100644 --- a/codex/sales.nim +++ b/codex/sales.nim @@ -57,7 +57,8 @@ type OnStore = proc(request: StorageRequest, slot: UInt256, availability: Availability): Future[void] {.gcsafe, upraises: [].} - OnProve = proc(cid: string): Future[seq[byte]] {.gcsafe, upraises: [].} + OnProve = proc(request: StorageRequest, + slot: UInt256): Future[seq[byte]] {.gcsafe, upraises: [].} OnClear = proc(availability: Availability, request: StorageRequest) {.gcsafe, upraises: [].} OnSale = proc(availability: Availability, request: StorageRequest, @@ -187,7 +188,7 @@ proc start(agent: SalesAgent) {.async.} = agent.waiting = some agent.waitForExpiry() await onStore(request, slotIndex, availability) - let proof = await onProve(request.content.cid) + let proof = await onProve(request, slotIndex) await market.fillSlot(request.id, slotIndex, proof) except CancelledError: raise diff --git a/tests/codex/testsales.nim b/tests/codex/testsales.nim index b164d3d2..26d3aefb 100644 --- a/tests/codex/testsales.nim +++ b/tests/codex/testsales.nim @@ -37,7 +37,8 @@ suite "Sales": slot: UInt256, availability: Availability) {.async.} = discard - sales.onProve = proc(cid: string): Future[seq[byte]] {.async.} = + sales.onProve = proc(request: StorageRequest, + slot: UInt256): Future[seq[byte]] {.async.} = return proof await sales.start() request.expiry = (clock.now() + 42).u256 @@ -113,11 +114,16 @@ suite "Sales": check sales.available == @[availability] test "generates proof of storage": - var provingCid: string - sales.onProve = proc(cid: string): Future[seq[byte]] {.async.} = provingCid = cid + var provingRequest: StorageRequest + var provingSlot: UInt256 + sales.onProve = proc(request: StorageRequest, + slot: UInt256): Future[seq[byte]] {.async.} = + provingRequest = request + provingSlot = slot sales.add(availability) - discard await market.requestStorage(request) - check provingCid == request.content.cid + let requested = await market.requestStorage(request) + check provingRequest == requested + check provingSlot < request.ask.slots.u256 test "fills a slot": sales.add(availability) @@ -145,7 +151,8 @@ suite "Sales": check soldSlotIndex < request.ask.slots.u256 test "calls onClear when storage becomes available again": - sales.onProve = proc(cid: string): Future[seq[byte]] {.async.} = + sales.onProve = proc(request: StorageRequest, + slot: UInt256): Future[seq[byte]] {.async.} = raise newException(IOError, "proof failed") var clearedAvailability: Availability var clearedRequest: StorageRequest