[marketplace] make availability optional for node restart
This commit is contained in:
parent
e2ceb431e2
commit
0a4c1c7e22
|
@ -323,7 +323,7 @@ proc start*(node: CodexNodeRef) {.async.} =
|
|||
# TODO: remove Sales callbacks, pass BlockStore and StorageProofs instead
|
||||
contracts.sales.onStore = proc(request: StorageRequest,
|
||||
slot: UInt256,
|
||||
availability: Availability) {.async.} =
|
||||
availability: ?Availability) {.async.} =
|
||||
## store data in local storage
|
||||
##
|
||||
|
||||
|
@ -344,7 +344,7 @@ proc start*(node: CodexNodeRef) {.async.} =
|
|||
if fetchRes.isErr:
|
||||
raise newException(CodexError, "Unable to retrieve blocks")
|
||||
|
||||
contracts.sales.onClear = proc(availability: Availability,
|
||||
contracts.sales.onClear = proc(availability: ?Availability,
|
||||
request: StorageRequest,
|
||||
slotIndex: UInt256) =
|
||||
# TODO: remove data from local storage
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import std/sets
|
||||
import std/times
|
||||
import pkg/asynctest
|
||||
import pkg/chronos
|
||||
import pkg/codex/contracts/requests
|
||||
import pkg/codex/proving
|
||||
import pkg/codex/sales
|
||||
import ./helpers/mockmarket
|
||||
import ./helpers/mockclock
|
||||
|
@ -24,7 +24,8 @@ suite "Sales":
|
|||
),
|
||||
content: StorageContent(
|
||||
cid: "some cid"
|
||||
)
|
||||
),
|
||||
expiry: (getTime() + initDuration(hours=1)).toUnix.u256
|
||||
)
|
||||
let proof = exampleProof()
|
||||
|
||||
|
@ -40,7 +41,7 @@ suite "Sales":
|
|||
sales = Sales.new(market, clock, proving)
|
||||
sales.onStore = proc(request: StorageRequest,
|
||||
slot: UInt256,
|
||||
availability: Availability) {.async.} =
|
||||
availability: ?Availability) {.async.} =
|
||||
discard
|
||||
sales.onProve = proc(request: StorageRequest,
|
||||
slot: UInt256): Future[seq[byte]] {.async.} =
|
||||
|
@ -98,10 +99,11 @@ suite "Sales":
|
|||
var storingAvailability: Availability
|
||||
sales.onStore = proc(request: StorageRequest,
|
||||
slot: UInt256,
|
||||
availability: Availability) {.async.} =
|
||||
availability: ?Availability) {.async.} =
|
||||
storingRequest = request
|
||||
storingSlot = slot
|
||||
storingAvailability = availability
|
||||
check availability.isSome
|
||||
storingAvailability = !availability
|
||||
sales.add(availability)
|
||||
let requested = await market.requestStorage(request)
|
||||
check storingRequest == requested
|
||||
|
@ -112,7 +114,7 @@ suite "Sales":
|
|||
let error = newException(IOError, "data retrieval failed")
|
||||
sales.onStore = proc(request: StorageRequest,
|
||||
slot: UInt256,
|
||||
availability: Availability) {.async.} =
|
||||
availability: ?Availability) {.async.} =
|
||||
raise error
|
||||
sales.add(availability)
|
||||
discard await market.requestStorage(request)
|
||||
|
@ -143,10 +145,11 @@ suite "Sales":
|
|||
var soldAvailability: Availability
|
||||
var soldRequest: StorageRequest
|
||||
var soldSlotIndex: UInt256
|
||||
sales.onSale = proc(availability: Availability,
|
||||
sales.onSale = proc(availability: ?Availability,
|
||||
request: StorageRequest,
|
||||
slotIndex: UInt256) =
|
||||
soldAvailability = availability
|
||||
if a =? availability:
|
||||
soldAvailability = a
|
||||
soldRequest = request
|
||||
soldSlotIndex = slotIndex
|
||||
sales.add(availability)
|
||||
|
@ -164,10 +167,11 @@ suite "Sales":
|
|||
var clearedAvailability: Availability
|
||||
var clearedRequest: StorageRequest
|
||||
var clearedSlotIndex: UInt256
|
||||
sales.onClear = proc(availability: Availability,
|
||||
sales.onClear = proc(availability: ?Availability,
|
||||
request: StorageRequest,
|
||||
slotIndex: UInt256) =
|
||||
clearedAvailability = availability
|
||||
if a =? availability:
|
||||
clearedAvailability = a
|
||||
clearedRequest = request
|
||||
clearedSlotIndex = slotIndex
|
||||
sales.add(availability)
|
||||
|
@ -180,8 +184,8 @@ suite "Sales":
|
|||
let otherHost = Address.example
|
||||
sales.onStore = proc(request: StorageRequest,
|
||||
slot: UInt256,
|
||||
availability: Availability) {.async.} =
|
||||
await sleepAsync(1.hours)
|
||||
availability: ?Availability) {.async.} =
|
||||
await sleepAsync(chronos.hours(1))
|
||||
sales.add(availability)
|
||||
discard await market.requestStorage(request)
|
||||
for slotIndex in 0..<request.ask.slots:
|
||||
|
@ -191,17 +195,17 @@ suite "Sales":
|
|||
test "makes storage available again when request expires":
|
||||
sales.onStore = proc(request: StorageRequest,
|
||||
slot: UInt256,
|
||||
availability: Availability) {.async.} =
|
||||
await sleepAsync(1.hours)
|
||||
availability: ?Availability) {.async.} =
|
||||
await sleepAsync(chronos.hours(1))
|
||||
sales.add(availability)
|
||||
discard await market.requestStorage(request)
|
||||
clock.set(request.expiry.truncate(int64))
|
||||
await sleepAsync(2.seconds)
|
||||
await sleepAsync(chronos.seconds(2))
|
||||
check sales.available == @[availability]
|
||||
|
||||
test "adds proving for slot when slot is filled":
|
||||
var soldSlotIndex: UInt256
|
||||
sales.onSale = proc(availability: Availability,
|
||||
sales.onSale = proc(availability: ?Availability,
|
||||
request: StorageRequest,
|
||||
slotIndex: UInt256) =
|
||||
soldSlotIndex = slotIndex
|
||||
|
|
Loading…
Reference in New Issue