[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();
}
function proofStart(SlotId slotId) public view override returns (uint256) {
return requestStart(_slot(slotId).requestId);
}
function proofEnd(SlotId slotId) public view override returns (uint256) {
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) {
uint256 end = _context(requestId).endsAt;
if (_requestAcceptsProofs(requestId)) {

View File

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

View File

@ -5,6 +5,7 @@ import "./Proofs.sol";
// exposes internal functions of Proofs for testing
contract TestProofs is Proofs {
mapping(SlotId => uint256) private starts;
mapping(SlotId => uint256) private ends;
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) {
return ends[slotId];
}
@ -58,6 +63,10 @@ contract TestProofs is Proofs {
_markProofAsMissing(id, _period);
}
function setProofStart(SlotId id, uint256 start) public {
starts[id] = start;
}
function setProofEnd(SlotId id, uint256 end) public {
ends[id] = end;
}

View File

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