[WIP sales] make storage available again upon failure

This commit is contained in:
Mark Spanbroek 2022-07-05 10:32:09 +02:00 committed by markspanbroek
parent a7f3ead44e
commit 5abd5dd674
2 changed files with 8 additions and 0 deletions

View File

@ -153,6 +153,7 @@ proc start(negotiation: Negotiation) {.async.} =
negotiation.waiting = some negotiation.waitForExpiry() negotiation.waiting = some negotiation.waitForExpiry()
except CatchableError as e: except CatchableError as e:
error "Negotiation failed", msg = e.msg error "Negotiation failed", msg = e.msg
negotiation.finish(success = false)
proc handleRequest(sales: Sales, requestId: array[32, byte], ask: StorageAsk) = proc handleRequest(sales: Sales, requestId: array[32, byte], ask: StorageAsk) =
without availability =? sales.findAvailability(ask): without availability =? sales.findAvailability(ask):

View File

@ -80,6 +80,13 @@ suite "Sales":
discard await market.requestStorage(request) discard await market.requestStorage(request)
check retrievingCid == request.content.cid check retrievingCid == request.content.cid
test "makes storage available again when data retrieval fails":
let error = newException(IOError, "data retrieval failed")
sales.retrieve = proc(cid: string) {.async.} = raise error
sales.add(availability)
discard await market.requestStorage(request)
check sales.available == @[availability]
test "generates proof of storage": test "generates proof of storage":
var provingCid: string var provingCid: string
sales.prove = proc(cid: string): Future[seq[byte]] {.async.} = provingCid = cid sales.prove = proc(cid: string): Future[seq[byte]] {.async.} = provingCid = cid