[marketplace] Remove `isSlotCancelled` and `isCancelled`
Remove `isSlotCancelled` and `isCancelled` from proving, as it did not fit in the module. Update the proving module to not rely on checking the contract to understand if a request was cancelled. Instead, `proofEnd` was modified in `dagger-contracts` such that it returns a past timestamp when the contract is cancelled. This successfully removes
This commit is contained in:
parent
b4a14e00f7
commit
9d218c88a5
|
@ -22,14 +22,6 @@ method periodicity*(proofs: OnChainProofs): Future[Periodicity] {.async.} =
|
|||
let period = await proofs.storage.proofPeriod()
|
||||
return Periodicity(seconds: period)
|
||||
|
||||
method isSlotCancelled*(proofs: OnChainProofs,
|
||||
id: SlotId): Future[bool] {.async.} =
|
||||
return await proofs.storage.isSlotCancelled(id)
|
||||
|
||||
method isCancelled*(proofs: OnChainProofs,
|
||||
id: RequestId): Future[bool] {.async.} =
|
||||
return await proofs.storage.isCancelled(id)
|
||||
|
||||
method isProofRequired*(proofs: OnChainProofs,
|
||||
id: SlotId): Future[bool] {.async.} =
|
||||
return await proofs.storage.isProofRequired(id)
|
||||
|
|
|
@ -45,8 +45,6 @@ proc proofTimeout*(storage: Storage): UInt256 {.contract, view.}
|
|||
|
||||
proc proofEnd*(storage: Storage, id: SlotId): UInt256 {.contract, view.}
|
||||
proc missingProofs*(storage: Storage, id: SlotId): UInt256 {.contract, view.}
|
||||
proc isCancelled*(storage: Storage, id: RequestId): bool {.contract, view.}
|
||||
proc isSlotCancelled*(storage: Storage, id: SlotId): bool {.contract, view.}
|
||||
proc isProofRequired*(storage: Storage, id: SlotId): bool {.contract, view.}
|
||||
proc willProofBeRequired*(storage: Storage, id: SlotId): bool {.contract, view.}
|
||||
proc getChallenge*(storage: Storage, id: SlotId): array[32, byte] {.contract, view.}
|
||||
|
|
|
@ -42,19 +42,11 @@ proc removeEndedContracts(proving: Proving) {.async.} =
|
|||
ended.incl(id)
|
||||
proving.slots.excl(ended)
|
||||
|
||||
proc removeCancelledContracts(proving: Proving) {.async.} =
|
||||
var cancelled: HashSet[SlotId]
|
||||
for id in proving.slots:
|
||||
if (await proving.proofs.isSlotCancelled(id)):
|
||||
cancelled.incl(id)
|
||||
proving.slots.excl(cancelled)
|
||||
|
||||
proc run(proving: Proving) {.async.} =
|
||||
try:
|
||||
while true:
|
||||
let currentPeriod = await proving.getCurrentPeriod()
|
||||
await proving.removeEndedContracts()
|
||||
await proving.removeCancelledContracts()
|
||||
for id in proving.slots:
|
||||
if (await proving.proofs.isProofRequired(id)) or
|
||||
(await proving.proofs.willProofBeRequired(id)):
|
||||
|
|
|
@ -18,14 +18,6 @@ method periodicity*(proofs: Proofs):
|
|||
Future[Periodicity] {.base, async.} =
|
||||
raiseAssert("not implemented")
|
||||
|
||||
method isSlotCancelled*(proofs: Proofs,
|
||||
id: SlotId): Future[bool] {.base, async.} =
|
||||
raiseAssert("not implemented")
|
||||
|
||||
method isCancelled*(proofs: Proofs,
|
||||
id: RequestId): Future[bool] {.base, async.} =
|
||||
raiseAssert("not implemented")
|
||||
|
||||
method isProofRequired*(proofs: Proofs,
|
||||
id: SlotId): Future[bool] {.base, async.} =
|
||||
raiseAssert("not implemented")
|
||||
|
|
|
@ -7,7 +7,6 @@ import pkg/codex/storageproofs
|
|||
type
|
||||
MockProofs* = ref object of Proofs
|
||||
periodicity: Periodicity
|
||||
cancelledSlots: HashSet[SlotId]
|
||||
proofsRequired: HashSet[SlotId]
|
||||
proofsToBeRequired: HashSet[SlotId]
|
||||
proofEnds: Table[SlotId, UInt256]
|
||||
|
@ -33,16 +32,6 @@ proc setProofRequired*(mock: MockProofs, id: SlotId, required: bool) =
|
|||
else:
|
||||
mock.proofsRequired.excl(id)
|
||||
|
||||
proc setSlotCancelled*(mock: MockProofs, id: SlotId, required: bool) =
|
||||
if required:
|
||||
mock.cancelledSlots.incl(id)
|
||||
else:
|
||||
mock.cancelledSlots.excl(id)
|
||||
|
||||
method isSlotCancelled*(mock: MockProofs,
|
||||
id: SlotId): Future[bool] {.async.} =
|
||||
return mock.cancelledSlots.contains(id)
|
||||
|
||||
method isProofRequired*(mock: MockProofs,
|
||||
id: SlotId): Future[bool] {.async.} =
|
||||
return mock.proofsRequired.contains(id)
|
||||
|
|
|
@ -90,19 +90,6 @@ suite "Proving":
|
|||
proving.onProofRequired = onProofRequired
|
||||
proofs.setProofRequired(id, true)
|
||||
await proofs.advanceToNextPeriod()
|
||||
check not called
|
||||
|
||||
test "stops watching when contract is cancelled":
|
||||
let id = SlotId.example
|
||||
proving.add(id)
|
||||
var called: bool
|
||||
proc onProofRequired(id: SlotId) =
|
||||
called = true
|
||||
proofs.setProofRequired(id, true)
|
||||
await proofs.advanceToNextPeriod()
|
||||
proving.onProofRequired = onProofRequired
|
||||
proofs.setSlotCancelled(id, true)
|
||||
await proofs.advanceToNextPeriod()
|
||||
check not proving.slots.contains(id)
|
||||
check not called
|
||||
|
||||
|
|
|
@ -76,20 +76,10 @@ ethersuite "Storage contracts":
|
|||
await provider.advanceTimeTo(await storage.proofEnd(slotId))
|
||||
await storage.payoutSlot(request.id, 0.u256)
|
||||
|
||||
test "a request is cancelled after expiry":
|
||||
check not await storage.isCancelled(request.id)
|
||||
await provider.advanceTimeTo(request.expiry + 1)
|
||||
check await storage.isCancelled(request.id)
|
||||
|
||||
test "a slot is cancelled after expiry":
|
||||
check not await storage.isSlotCancelled(slotId)
|
||||
await provider.advanceTimeTo(request.expiry + 1)
|
||||
check await storage.isSlotCancelled(slotId)
|
||||
|
||||
test "cannot mark proofs missing for cancelled request":
|
||||
await provider.advanceTimeTo(request.expiry + 1)
|
||||
switchAccount(client)
|
||||
let missingPeriod = periodicity.periodOf(await provider.currentTime())
|
||||
await provider.advanceTime(periodicity.seconds)
|
||||
revertsWith "Request was cancelled":
|
||||
revertsWith "Slot not accepting proofs":
|
||||
await storage.markProofAsMissing(slotId, missingPeriod)
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 06bbfdb3a64428d1f5367f8cb6488ec093eddff5
|
||||
Subproject commit 06e58fdc4923999cb93e54b55a5e68da26435628
|
Loading…
Reference in New Issue