[sales] Pass along request and slot index in onProve callback
This commit is contained in:
parent
cb5427ca95
commit
fd6f8a1386
|
@ -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]
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue