[Proofs] Remove double administration of request start

The timestamp when proofs start to be required was
stored in both the Marketplace and Proofs. It is now
only stored in the Marketplace.
This commit is contained in:
Mark Spanbroek 2023-01-10 12:34:18 +01:00 committed by markspanbroek
parent 527c21e103
commit f224cb8eda
4 changed files with 26 additions and 3 deletions

View File

@ -320,10 +320,18 @@ 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

@ -16,7 +16,6 @@ abstract contract Proofs {
} }
mapping(SlotId => bool) private slotIds; mapping(SlotId => bool) private slotIds;
mapping(SlotId => uint256) private starts;
mapping(SlotId => uint256) private probabilities; mapping(SlotId => uint256) private probabilities;
mapping(SlotId => uint256) private missed; mapping(SlotId => uint256) private missed;
mapping(SlotId => mapping(uint256 => bool)) private received; mapping(SlotId => mapping(uint256 => bool)) private received;
@ -30,6 +29,10 @@ abstract contract Proofs {
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);
@ -52,7 +55,6 @@ abstract contract Proofs {
function _expectProofs(SlotId id, uint256 probability) internal { function _expectProofs(SlotId id, uint256 probability) internal {
require(!slotIds[id], "Slot id already in use"); require(!slotIds[id], "Slot id already in use");
slotIds[id] = true; slotIds[id] = true;
starts[id] = block.timestamp;
probabilities[id] = probability; probabilities[id] = probability;
} }
@ -97,7 +99,7 @@ abstract contract Proofs {
SlotId id, SlotId id,
uint256 proofPeriod uint256 proofPeriod
) internal view returns (bool isRequired, uint8 pointer) { ) internal view returns (bool isRequired, uint8 pointer) {
if (proofPeriod <= periodOf(starts[id])) { if (proofPeriod <= periodOf(proofStart(id))) {
return (false, 0); return (false, 0);
} }
uint256 end = proofEnd(id); uint256 end = proofEnd(id);

View File

@ -5,6 +5,7 @@ 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(
@ -18,6 +19,10 @@ 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];
} }
@ -58,6 +63,10 @@ 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,6 +37,7 @@ 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)
}) })
@ -89,6 +90,7 @@ 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.expectProofs(slotId, probability) await proofs.expectProofs(slotId, probability)
} }
@ -120,6 +122,7 @@ 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.expectProofs(slotId, probability) await proofs.expectProofs(slotId, probability)
await advanceTimeTo(periodEnd(periodOf(await currentTime()))) await advanceTimeTo(periodEnd(periodOf(await currentTime())))
@ -154,6 +157,7 @@ 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.expectProofs(slotId, probability) await proofs.expectProofs(slotId, probability)
}) })