[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) =
|
contracts.sales.onClear = proc(availability: Availability, request: StorageRequest) =
|
||||||
# TODO: remove data from local storage
|
# TODO: remove data from local storage
|
||||||
discard
|
discard
|
||||||
|
contracts.sales.onProve = proc(request: StorageRequest,
|
||||||
contracts.sales.onProve = proc(cid: string): Future[seq[byte]] {.async.} =
|
slot: UInt256): Future[seq[byte]] {.async.} =
|
||||||
# TODO: generate proof
|
# TODO: generate proof
|
||||||
return @[42'u8]
|
return @[42'u8]
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,8 @@ type
|
||||||
OnStore = proc(request: StorageRequest,
|
OnStore = proc(request: StorageRequest,
|
||||||
slot: UInt256,
|
slot: UInt256,
|
||||||
availability: Availability): Future[void] {.gcsafe, upraises: [].}
|
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: [].}
|
OnClear = proc(availability: Availability, request: StorageRequest) {.gcsafe, upraises: [].}
|
||||||
OnSale = proc(availability: Availability,
|
OnSale = proc(availability: Availability,
|
||||||
request: StorageRequest,
|
request: StorageRequest,
|
||||||
|
@ -187,7 +188,7 @@ proc start(agent: SalesAgent) {.async.} =
|
||||||
agent.waiting = some agent.waitForExpiry()
|
agent.waiting = some agent.waitForExpiry()
|
||||||
|
|
||||||
await onStore(request, slotIndex, availability)
|
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)
|
await market.fillSlot(request.id, slotIndex, proof)
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
raise
|
raise
|
||||||
|
|
|
@ -37,7 +37,8 @@ suite "Sales":
|
||||||
slot: UInt256,
|
slot: UInt256,
|
||||||
availability: Availability) {.async.} =
|
availability: Availability) {.async.} =
|
||||||
discard
|
discard
|
||||||
sales.onProve = proc(cid: string): Future[seq[byte]] {.async.} =
|
sales.onProve = proc(request: StorageRequest,
|
||||||
|
slot: UInt256): Future[seq[byte]] {.async.} =
|
||||||
return proof
|
return proof
|
||||||
await sales.start()
|
await sales.start()
|
||||||
request.expiry = (clock.now() + 42).u256
|
request.expiry = (clock.now() + 42).u256
|
||||||
|
@ -113,11 +114,16 @@ suite "Sales":
|
||||||
check sales.available == @[availability]
|
check sales.available == @[availability]
|
||||||
|
|
||||||
test "generates proof of storage":
|
test "generates proof of storage":
|
||||||
var provingCid: string
|
var provingRequest: StorageRequest
|
||||||
sales.onProve = proc(cid: string): Future[seq[byte]] {.async.} = provingCid = cid
|
var provingSlot: UInt256
|
||||||
|
sales.onProve = proc(request: StorageRequest,
|
||||||
|
slot: UInt256): Future[seq[byte]] {.async.} =
|
||||||
|
provingRequest = request
|
||||||
|
provingSlot = slot
|
||||||
sales.add(availability)
|
sales.add(availability)
|
||||||
discard await market.requestStorage(request)
|
let requested = await market.requestStorage(request)
|
||||||
check provingCid == request.content.cid
|
check provingRequest == requested
|
||||||
|
check provingSlot < request.ask.slots.u256
|
||||||
|
|
||||||
test "fills a slot":
|
test "fills a slot":
|
||||||
sales.add(availability)
|
sales.add(availability)
|
||||||
|
@ -145,7 +151,8 @@ suite "Sales":
|
||||||
check soldSlotIndex < request.ask.slots.u256
|
check soldSlotIndex < request.ask.slots.u256
|
||||||
|
|
||||||
test "calls onClear when storage becomes available again":
|
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")
|
raise newException(IOError, "proof failed")
|
||||||
var clearedAvailability: Availability
|
var clearedAvailability: Availability
|
||||||
var clearedRequest: StorageRequest
|
var clearedRequest: StorageRequest
|
||||||
|
|
Loading…
Reference in New Issue