fix: reset missed counter when slot is freed (#48)

This commit is contained in:
Adam Uhlíř 2023-03-08 17:19:49 +01:00 committed by GitHub
parent dfdbd16d5b
commit 8b39ef8f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -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;

View File

@ -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;

View File

@ -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 () {