diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index be15bcd1..60419343 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -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, diff --git a/codex/contracts/requests.nim b/codex/contracts/requests.nim index f591b785..10612765 100644 --- a/codex/contracts/requests.nim +++ b/codex/contracts/requests.nim @@ -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 = diff --git a/codex/contracts/storage.nim b/codex/contracts/storage.nim index 9989a2e5..2c1c0028 100644 --- a/codex/contracts/storage.nim +++ b/codex/contracts/storage.nim @@ -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.} diff --git a/codex/node.nim b/codex/node.nim index 5b4c5b90..ee15154f 100644 --- a/codex/node.nim +++ b/codex/node.nim @@ -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, diff --git a/tests/contracts/examples.nim b/tests/contracts/examples.nim index 96255034..55388f5d 100644 --- a/tests/contracts/examples.nim +++ b/tests/contracts/examples.nim @@ -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", diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index 058d8bf0..b98e10d4 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -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] diff --git a/vendor/dagger-contracts b/vendor/dagger-contracts index 06e58fdc..c27d4f87 160000 --- a/vendor/dagger-contracts +++ b/vendor/dagger-contracts @@ -1 +1 @@ -Subproject commit 06e58fdc4923999cb93e54b55a5e68da26435628 +Subproject commit c27d4f870c99f8657027ec9b1ab24223adba9859