fix: reset missed counter when slot is freed (#48)
This commit is contained in:
parent
dfdbd16d5b
commit
8b39ef8f4a
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 () {
|
||||
|
|
Loading…
Reference in New Issue