Skip to content

chore(marketplace): use canProofBeMarkedAsMissing #1188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions codex/contracts/market.nim
Original file line number Diff line number Diff line change
Expand Up @@ -362,14 +362,12 @@

discard await market.contract.markProofAsMissing(id, period, overrides).confirm(1)

method canProofBeMarkedAsMissing*(
method canMarkProofAsMissing*(

Check warning on line 365 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L365

Added line #L365 was not covered by tests
market: OnChainMarket, id: SlotId, period: Period
): Future[bool] {.async.} =
let provider = market.contract.provider
let contractWithoutSigner = market.contract.connect(provider)
let overrides = CallOverrides(blockTag: some BlockTag.pending)
): Future[bool] {.async: (raises: [CancelledError]).} =

Check warning on line 367 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L367

Added line #L367 was not covered by tests
try:
discard await contractWithoutSigner.markProofAsMissing(id, period, overrides)
let overrides = CallOverrides(blockTag: some BlockTag.pending)
discard await market.contract.canMarkProofAsMissing(id, period, overrides)

Check warning on line 370 in codex/contracts/market.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/market.nim#L369-L370

Added lines #L369 - L370 were not covered by tests
return true
except EthersError as e:
trace "Proof cannot be marked as missing", msg = e.msg
Expand Down
11 changes: 11 additions & 0 deletions codex/contracts/marketplace.nim
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,17 @@
]
.}

proc canMarkProofAsMissing*(
marketplace: Marketplace, id: SlotId, period: uint64
): Confirmable {.
contract,
errors: [
Marketplace_SlotNotAcceptingProofs, Proofs_PeriodNotEnded,
Proofs_ValidationTimedOut, Proofs_ProofNotMissing, Proofs_ProofNotRequired,
Proofs_ProofAlreadyMarkedMissing,
]
.}

Check warning on line 191 in codex/contracts/marketplace.nim

View check run for this annotation

Codecov / codecov/patch

codex/contracts/marketplace.nim#L181-L191

Added lines #L181 - L191 were not covered by tests
proc reserveSlot*(
marketplace: Marketplace, requestId: RequestId, slotIndex: uint64
): Confirmable {.contract.}
Expand Down
4 changes: 2 additions & 2 deletions codex/market.nim
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ method markProofAsMissing*(
) {.base, async: (raises: [CancelledError, MarketError]).} =
raiseAssert("not implemented")

method canProofBeMarkedAsMissing*(
method canMarkProofAsMissing*(
market: Market, id: SlotId, period: Period
): Future[bool] {.base, async.} =
): Future[bool] {.base, async: (raises: [CancelledError]).} =
raiseAssert("not implemented")

method reserveSlot*(
Expand Down
2 changes: 1 addition & 1 deletion codex/validation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ proc markProofAsMissing(
currentPeriod = validation.getCurrentPeriod()

try:
if await validation.market.canProofBeMarkedAsMissing(slotId, period):
if await validation.market.canMarkProofAsMissing(slotId, period):
trace "Marking proof as missing", slotId, periodProofMissed = period
await validation.market.markProofAsMissing(slotId, period)
else:
Expand Down
6 changes: 3 additions & 3 deletions tests/codex/helpers/mockmarket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -381,15 +381,15 @@ method markProofAsMissing*(
) {.async: (raises: [CancelledError, MarketError]).} =
market.markedAsMissingProofs.add(id)

proc setCanProofBeMarkedAsMissing*(mock: MockMarket, id: SlotId, required: bool) =
proc setCanMarkProofAsMissing*(mock: MockMarket, id: SlotId, required: bool) =
if required:
mock.canBeMarkedAsMissing.incl(id)
else:
mock.canBeMarkedAsMissing.excl(id)

method canProofBeMarkedAsMissing*(
method canMarkProofAsMissing*(
market: MockMarket, id: SlotId, period: Period
): Future[bool] {.async.} =
): Future[bool] {.async: (raises: [CancelledError]).} =
return market.canBeMarkedAsMissing.contains(id)

method reserveSlot*(
Expand Down
4 changes: 2 additions & 2 deletions tests/codex/testvalidation.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ asyncchecksuite "validation":
test "when a proof is missed, it is marked as missing":
await validation.start()
await market.fillSlot(slot.request.id, slot.slotIndex, proof, collateral)
market.setCanProofBeMarkedAsMissing(slot.id, true)
market.setCanMarkProofAsMissing(slot.id, true)
advanceToNextPeriod()
await sleepAsync(100.millis) # allow validation loop to run
check market.markedAsMissingProofs.contains(slot.id)

test "when a proof can not be marked as missing, it will not be marked":
await validation.start()
await market.fillSlot(slot.request.id, slot.slotIndex, proof, collateral)
market.setCanProofBeMarkedAsMissing(slot.id, false)
market.setCanMarkProofAsMissing(slot.id, false)
advanceToNextPeriod()
await sleepAsync(100.millis) # allow validation loop to run
check market.markedAsMissingProofs.len == 0
Expand Down
45 changes: 42 additions & 3 deletions tests/contracts/testMarket.nim
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,46 @@ ethersuite "On-Chain Market":
let missingPeriod =
periodicity.periodOf((await ethProvider.currentTime()).truncate(uint64))
await advanceToNextPeriod()
check (await market.canProofBeMarkedAsMissing(slotId, missingPeriod)) == true
check (await market.canMarkProofAsMissing(slotId, missingPeriod)) == true

test "can check whether a proof cannot be marked as missing when the slot is free":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should add a test that checks if a proof is required before the slot is filled (also free)

let slotId = slotId(request, slotIndex)
await market.requestStorage(request)
await market.reserveSlot(request.id, slotIndex)
await market.fillSlot(request.id, slotIndex, proof, request.ask.collateralPerSlot)
await waitUntilProofRequired(slotId)

await market.freeSlot(slotId(request.id, slotIndex))

let missingPeriod =
periodicity.periodOf((await ethProvider.currentTime()).truncate(uint64))
await advanceToNextPeriod()
check (await market.canMarkProofAsMissing(slotId, missingPeriod)) == false

test "can check whether a proof cannot be marked as missing before a proof is required":
let slotId = slotId(request, slotIndex)
Comment on lines +208 to +209
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that each test starts off at the exact same point and assuming that the block hashes will always be deterministic, this test SHOULD work every time, but there may be a chance that there is a proof required as soon as the slot is filled.

await market.requestStorage(request)
await market.reserveSlot(request.id, slotIndex)
await market.fillSlot(request.id, slotIndex, proof, request.ask.collateralPerSlot)

let missingPeriod =
periodicity.periodOf((await ethProvider.currentTime()).truncate(uint64))
await advanceToNextPeriod()
check (await market.canMarkProofAsMissing(slotId, missingPeriod)) == false

test "can check whether a proof cannot be marked as missing if the proof was submitted":
let slotId = slotId(request, slotIndex)
await market.requestStorage(request)
await market.reserveSlot(request.id, slotIndex)
await market.fillSlot(request.id, slotIndex, proof, request.ask.collateralPerSlot)
await waitUntilProofRequired(slotId)

await market.submitProof(slotId(request.id, slotIndex), proof)

let missingPeriod =
periodicity.periodOf((await ethProvider.currentTime()).truncate(uint64))
await advanceToNextPeriod()
check (await market.canMarkProofAsMissing(slotId, missingPeriod)) == false

test "supports slot filled subscriptions":
await market.requestStorage(request)
Expand Down Expand Up @@ -548,7 +587,7 @@ ethersuite "On-Chain Market":
switchAccount(host)
await market.reserveSlot(request.id, 0.uint64)
await market.fillSlot(request.id, 0.uint64, proof, request.ask.collateralPerSlot)
let filledAt = (await ethProvider.currentTime()) - 1.u256
let filledAt = await ethProvider.currentTime()

for slotIndex in 1 ..< request.ask.slots:
await market.reserveSlot(request.id, slotIndex.uint64)
Expand All @@ -575,7 +614,7 @@ ethersuite "On-Chain Market":
switchAccount(host)
await market.reserveSlot(request.id, 0.uint64)
await market.fillSlot(request.id, 0.uint64, proof, request.ask.collateralPerSlot)
let filledAt = (await ethProvider.currentTime()) - 1.u256
let filledAt = await ethProvider.currentTime()

for slotIndex in 1 ..< request.ask.slots:
await market.reserveSlot(request.id, slotIndex.uint64)
Expand Down
2 changes: 1 addition & 1 deletion vendor/codex-contracts-eth