From 8b39ef8f4a0deb24f86d8b78ee2cc5758fc3f781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adam=20Uhl=C3=AD=C5=99?= Date: Wed, 8 Mar 2023 17:19:49 +0100 Subject: [PATCH] fix: reset missed counter when slot is freed (#48) --- contracts/Marketplace.sol | 1 + contracts/Proofs.sol | 4 ++++ test/Marketplace.test.js | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 6229c73..3926381 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -152,6 +152,7 @@ contract Marketplace is Proofs, StateRetrieval { delete _slots[slotId]; context.slotsFilled -= 1; emit SlotFreed(requestId, slotId); + resetMissingProofs(slotId); Request storage request = _requests[requestId]; uint256 slotsLost = request.ask.slots - context.slotsFilled; diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index a169506..80be37b 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -25,6 +25,10 @@ abstract contract Proofs is Periods { return _missed[slotId]; } + function resetMissingProofs(SlotId slotId) internal { + _missed[slotId] = 0; + } + function _startRequiringProofs(SlotId id, uint256 probability) internal { _slotStarts[id] = block.timestamp; _probabilities[id] = probability; diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 788f5c3..a4878fc 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -777,6 +777,24 @@ describe("Marketplace", function () { expect(await marketplace.slotState(slotId(slot))).to.equal(SlotState.Free) expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.lte(minimum) }) + + it("free slot when minimum reached and resets missed proof counter", async function () { + const minimum = config.collateral.minimumAmount + await waitUntilStarted(marketplace, request, proof, token) + let missedProofs = 0 + while ((await marketplace.slotState(slotId(slot))) === SlotState.Filled) { + expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.gt(minimum) + await waitUntilProofIsRequired(slotId(slot)) + const missedPeriod = periodOf(await currentTime()) + await advanceTime(period) + expect(await marketplace.missingProofs(slotId(slot))).to.equal(missedProofs) + await marketplace.markProofAsMissing(slotId(slot), missedPeriod) + missedProofs += 1 + } + expect(await marketplace.slotState(slotId(slot))).to.equal(SlotState.Free) + expect(await marketplace.missingProofs(slotId(slot))).to.equal(0) + expect(await marketplace.getSlotCollateral(slotId(slot))).to.be.lte(minimum) + }) }) describe("list of active requests", function () {