From 45ade0e3c133db01ee188360aa987f1820ec7a63 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Tue, 3 Jun 2025 11:08:57 +0200 Subject: [PATCH] chore(marketplace): use canMarkProofAsMissing (#1188) * Add canProofBeMarkedAsMissing * Add more tests * Update contracts submodule --- codex/contracts/market.nim | 10 +++----- codex/contracts/marketplace.nim | 11 ++++++++ codex/market.nim | 4 +-- codex/validation.nim | 2 +- tests/codex/helpers/mockmarket.nim | 6 ++--- tests/codex/testvalidation.nim | 4 +-- tests/contracts/testMarket.nim | 41 +++++++++++++++++++++++++++++- vendor/codex-contracts-eth | 2 +- 8 files changed, 64 insertions(+), 16 deletions(-) diff --git a/codex/contracts/market.nim b/codex/contracts/market.nim index 3708478f..f415711d 100644 --- a/codex/contracts/market.nim +++ b/codex/contracts/market.nim @@ -379,14 +379,12 @@ method markProofAsMissing*( discard await market.contract.markProofAsMissing(id, period, overrides).confirm(1) -method canProofBeMarkedAsMissing*( +method canMarkProofAsMissing*( 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]).} = try: - discard await contractWithoutSigner.markProofAsMissing(id, period, overrides) + let overrides = CallOverrides(blockTag: some BlockTag.pending) + discard await market.contract.canMarkProofAsMissing(id, period, overrides) return true except EthersError as e: trace "Proof cannot be marked as missing", msg = e.msg diff --git a/codex/contracts/marketplace.nim b/codex/contracts/marketplace.nim index 11eca5be..95de3dcf 100644 --- a/codex/contracts/marketplace.nim +++ b/codex/contracts/marketplace.nim @@ -178,6 +178,17 @@ proc markProofAsMissing*( ] .} +proc canMarkProofAsMissing*( + marketplace: Marketplace, id: SlotId, period: uint64 +): Confirmable {. + contract, + errors: [ + Marketplace_SlotNotAcceptingProofs, Proofs_PeriodNotEnded, + Proofs_ValidationTimedOut, Proofs_ProofNotMissing, Proofs_ProofNotRequired, + Proofs_ProofAlreadyMarkedMissing, + ] +.} + proc reserveSlot*( marketplace: Marketplace, requestId: RequestId, slotIndex: uint64 ): Confirmable {.contract.} diff --git a/codex/market.nim b/codex/market.nim index 31c0687f..0303a906 100644 --- a/codex/market.nim +++ b/codex/market.nim @@ -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*( diff --git a/codex/validation.nim b/codex/validation.nim index e6d74840..58a0e6b7 100644 --- a/codex/validation.nim +++ b/codex/validation.nim @@ -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: diff --git a/tests/codex/helpers/mockmarket.nim b/tests/codex/helpers/mockmarket.nim index 55abeb14..9d2fbea3 100644 --- a/tests/codex/helpers/mockmarket.nim +++ b/tests/codex/helpers/mockmarket.nim @@ -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*( diff --git a/tests/codex/testvalidation.nim b/tests/codex/testvalidation.nim index 30d6e3f3..5c95cd76 100644 --- a/tests/codex/testvalidation.nim +++ b/tests/codex/testvalidation.nim @@ -142,7 +142,7 @@ 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) @@ -150,7 +150,7 @@ asyncchecksuite "validation": 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 diff --git a/tests/contracts/testMarket.nim b/tests/contracts/testMarket.nim index 6d47ab9a..a13d0c67 100644 --- a/tests/contracts/testMarket.nim +++ b/tests/contracts/testMarket.nim @@ -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": + 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) + 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) diff --git a/vendor/codex-contracts-eth b/vendor/codex-contracts-eth index 470a4df4..aee91f1a 160000 --- a/vendor/codex-contracts-eth +++ b/vendor/codex-contracts-eth @@ -1 +1 @@ -Subproject commit 470a4df4152b53a8065c2984d55efcd7350b549a +Subproject commit aee91f1ac411258af338af5145e0112e6ab6f5df