[marketplace] support freeing of slots and failed state

Support storage contract parameters to free slots after too many proofs missed, as well as fail a contract after too many slots have been freed.

# Conflicts:
#	vendor/dagger-contracts
This commit is contained in:
Eric Mastro 2022-08-26 14:08:02 +10:00 committed by Eric Mastro
parent 8dd110765f
commit b9e53e182f
7 changed files with 19 additions and 10 deletions

View File

@ -36,10 +36,14 @@ method requestStorage(market: OnChainMarket,
method getRequest(market: OnChainMarket,
id: RequestId): Future[?StorageRequest] {.async.} =
let request = await market.contract.getRequest(id)
if request != StorageRequest.default:
return some request
else:
try:
let request = await market.contract.getRequest(id)
if request != StorageRequest.default:
return some request
else:
return none StorageRequest
except ValueError:
# Unknown request
return none StorageRequest
method getHost(market: OnChainMarket,

View File

@ -19,6 +19,7 @@ type
duration*: UInt256
proofProbability*: UInt256
reward*: UInt256
maxSlotLoss*: uint64
StorageContent* = object
cid*: string
erasure*: StorageErasure
@ -56,7 +57,8 @@ func fromTuple(_: type StorageAsk, tupl: tuple): StorageAsk =
slotSize: tupl[1],
duration: tupl[2],
proofProbability: tupl[3],
reward: tupl[4]
reward: tupl[4],
maxSlotLoss: tupl[5]
)
func fromTuple(_: type StorageContent, tupl: tuple): StorageContent =

View File

@ -15,7 +15,7 @@ type
SlotFilled* = object of Event
requestId* {.indexed.}: RequestId
slotIndex* {.indexed.}: UInt256
slotId* {.indexed.}: SlotId
slotId*: SlotId
RequestFulfilled* = object of Event
requestId* {.indexed.}: RequestId
RequestCancelled* = object of Event
@ -28,6 +28,7 @@ type
proc collateralAmount*(storage: Storage): UInt256 {.contract, view.}
proc slashMisses*(storage: Storage): UInt256 {.contract, view.}
proc slashPercentage*(storage: Storage): UInt256 {.contract, view.}
proc minCollateralThreshold*(storage: Storage): UInt256 {.contract, view.}
proc deposit*(storage: Storage, amount: UInt256) {.contract.}
proc withdraw*(storage: Storage) {.contract.}

View File

@ -270,7 +270,8 @@ proc requestStorage*(self: CodexNodeRef,
slots: nodes + tolerance,
slotSize: (encoded.blockSize * encoded.steps).u256,
duration: duration,
reward: reward
reward: reward,
maxSlotLoss: tolerance
),
content: StorageContent(
cid: $encodedBlk.cid,

View File

@ -17,7 +17,8 @@ proc example*(_: type StorageRequest): StorageRequest =
slotSize: (1 * 1024 * 1024 * 1024).u256, # 1 Gigabyte
duration: (10 * 60 * 60).u256, # 10 hours
proofProbability: 4.u256, # require a proof roughly once every 4 periods
reward: 84.u256
reward: 84.u256,
maxSlotLoss: 2 # 2 slots can be freed without data considered to be lost
),
content: StorageContent(
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob",

View File

@ -135,7 +135,7 @@ ethersuite "On-Chain Market":
await token.approve(storage.address, request.price)
discard await market.requestStorage(request)
await token.approve(storage.address, otherrequest.price)
await token.approve(storage.address, otherRequest.price)
discard await market.requestStorage(otherRequest)
var receivedIds: seq[RequestId]

@ -1 +1 @@
Subproject commit 06e58fdc4923999cb93e54b55a5e68da26435628
Subproject commit c27d4f870c99f8657027ec9b1ab24223adba9859