[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.
This commit is contained in:
parent
8899b68d1a
commit
0723405ee6
|
@ -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,
|
||||
|
|
|
@ -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 =
|
||||
|
|
|
@ -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
|
||||
|
||||
|
@ -27,6 +27,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.}
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -127,7 +127,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 9ab65ae5a61a09a6849cc4adbd8ef58fb89c037e
|
||||
Subproject commit 9a382234c5de427e8ef824d579b734c2bc861486
|
Loading…
Reference in New Issue