Fix: use slot start instead of request start

Proofs should be required from the moment a slot is filled,
not from the moment a request is submitted.

This reverts commit f224cb8eda.
This commit is contained in:
Mark Spanbroek 2023-01-11 14:24:26 +01:00 committed by markspanbroek
parent ad155be5a1
commit af08a72d7d
4 changed files with 3 additions and 26 deletions

View File

@ -320,18 +320,10 @@ contract Marketplace is Collateral, Proofs {
return _timeout(); return _timeout();
} }
function proofStart(SlotId slotId) public view override returns (uint256) {
return requestStart(_slot(slotId).requestId);
}
function proofEnd(SlotId slotId) public view override returns (uint256) { function proofEnd(SlotId slotId) public view override returns (uint256) {
return requestEnd(_slot(slotId).requestId); return requestEnd(_slot(slotId).requestId);
} }
function requestStart(RequestId requestId) public view returns (uint256) {
return _context(requestId).startedAt;
}
function requestEnd(RequestId requestId) public view returns (uint256) { function requestEnd(RequestId requestId) public view returns (uint256) {
uint256 end = _context(requestId).endsAt; uint256 end = _context(requestId).endsAt;
if (_requestAcceptsProofs(requestId)) { if (_requestAcceptsProofs(requestId)) {

View File

@ -19,6 +19,7 @@ abstract contract Proofs is Periods {
} }
mapping(SlotId => bool) private slotIds; mapping(SlotId => bool) private slotIds;
mapping(SlotId => uint256) private slotStarts;
mapping(SlotId => uint256) private probabilities; mapping(SlotId => uint256) private probabilities;
mapping(SlotId => uint256) private missed; mapping(SlotId => uint256) private missed;
mapping(SlotId => mapping(Period => bool)) private received; mapping(SlotId => mapping(Period => bool)) private received;
@ -28,10 +29,6 @@ abstract contract Proofs is Periods {
return timeout; return timeout;
} }
// Override this to let the proving system know when proofs for a
// slot are required.
function proofStart(SlotId id) public view virtual returns (uint256);
// Override this to let the proving system know when proofs for a // Override this to let the proving system know when proofs for a
// slot are no longer required. // slot are no longer required.
function proofEnd(SlotId id) public view virtual returns (uint256); function proofEnd(SlotId id) public view virtual returns (uint256);
@ -46,6 +43,7 @@ abstract contract Proofs is Periods {
function _startRequiringProofs(SlotId id, uint256 probability) internal { function _startRequiringProofs(SlotId id, uint256 probability) internal {
require(!slotIds[id], "Proofs already required for slot"); require(!slotIds[id], "Proofs already required for slot");
slotIds[id] = true; slotIds[id] = true;
slotStarts[id] = block.timestamp;
probabilities[id] = probability; probabilities[id] = probability;
} }
@ -90,7 +88,7 @@ abstract contract Proofs is Periods {
SlotId id, SlotId id,
Period proofPeriod Period proofPeriod
) internal view returns (bool isRequired, uint8 pointer) { ) internal view returns (bool isRequired, uint8 pointer) {
Period start = periodOf(proofStart(id)); Period start = periodOf(slotStarts[id]);
Period end = periodOf(proofEnd(id)); Period end = periodOf(proofEnd(id));
if (!isAfter(proofPeriod, start) || !isBefore(proofPeriod, end)) { if (!isAfter(proofPeriod, start) || !isBefore(proofPeriod, end)) {
return (false, 0); return (false, 0);

View File

@ -5,7 +5,6 @@ import "./Proofs.sol";
// exposes internal functions of Proofs for testing // exposes internal functions of Proofs for testing
contract TestProofs is Proofs { contract TestProofs is Proofs {
mapping(SlotId => uint256) private starts;
mapping(SlotId => uint256) private ends; mapping(SlotId => uint256) private ends;
constructor( constructor(
@ -19,10 +18,6 @@ contract TestProofs is Proofs {
} }
function proofStart(SlotId slotId) public view override returns (uint256) {
return starts[slotId];
}
function proofEnd(SlotId slotId) public view override returns (uint256) { function proofEnd(SlotId slotId) public view override returns (uint256) {
return ends[slotId]; return ends[slotId];
} }
@ -59,10 +54,6 @@ contract TestProofs is Proofs {
_markProofAsMissing(id, _period); _markProofAsMissing(id, _period);
} }
function setProofStart(SlotId id, uint256 start) public {
starts[id] = start;
}
function setProofEnd(SlotId id, uint256 end) public { function setProofEnd(SlotId id, uint256 end) public {
ends[id] = end; ends[id] = end;
} }

View File

@ -37,7 +37,6 @@ describe("Proofs", function () {
describe("general", function () { describe("general", function () {
beforeEach(async function () { beforeEach(async function () {
await proofs.setProofStart(slotId, await currentTime())
await proofs.setProofEnd(slotId, (await currentTime()) + duration) await proofs.setProofEnd(slotId, (await currentTime()) + duration)
}) })
@ -90,7 +89,6 @@ describe("Proofs", function () {
let id2 = hexlify(randomBytes(32)) let id2 = hexlify(randomBytes(32))
let id3 = hexlify(randomBytes(32)) let id3 = hexlify(randomBytes(32))
for (let slotId of [id1, id2, id3]) { for (let slotId of [id1, id2, id3]) {
await proofs.setProofStart(slotId, await currentTime())
await proofs.setProofEnd(slotId, (await currentTime()) + duration) await proofs.setProofEnd(slotId, (await currentTime()) + duration)
await proofs.startRequiringProofs(slotId, probability) await proofs.startRequiringProofs(slotId, probability)
} }
@ -122,7 +120,6 @@ describe("Proofs", function () {
} }
beforeEach(async function () { beforeEach(async function () {
await proofs.setProofStart(slotId, await currentTime())
await proofs.setProofEnd(slotId, (await currentTime()) + duration) await proofs.setProofEnd(slotId, (await currentTime()) + duration)
await proofs.startRequiringProofs(slotId, probability) await proofs.startRequiringProofs(slotId, probability)
await advanceTimeTo(periodEnd(periodOf(await currentTime()))) await advanceTimeTo(periodEnd(periodOf(await currentTime())))
@ -157,7 +154,6 @@ describe("Proofs", function () {
const proof = hexlify(randomBytes(42)) const proof = hexlify(randomBytes(42))
beforeEach(async function () { beforeEach(async function () {
await proofs.setProofStart(slotId, await currentTime())
await proofs.setProofEnd(slotId, (await currentTime()) + duration) await proofs.setProofEnd(slotId, (await currentTime()) + duration)
await proofs.startRequiringProofs(slotId, probability) await proofs.startRequiringProofs(slotId, probability)
}) })