[Proofs] Improved naming

Co-authored-by: Eric Mastro <eric.mastro@gmail.com>
This commit is contained in:
Mark Spanbroek 2023-01-10 11:14:07 +01:00 committed by markspanbroek
parent afad73d588
commit ce335d0568
1 changed files with 11 additions and 11 deletions

View File

@ -15,10 +15,10 @@ contract Proofs {
downtime = __downtime; downtime = __downtime;
} }
mapping(SlotId => bool) private ids; mapping(SlotId => bool) private slotIds;
mapping(SlotId => uint256) private starts; mapping(SlotId => uint256) private starts;
mapping(RequestId => uint256) private ends; mapping(RequestId => uint256) private ends;
mapping(SlotId => RequestId) private requestIds; mapping(SlotId => RequestId) private requestForSlot;
mapping(SlotId => uint256) private probabilities; mapping(SlotId => uint256) private probabilities;
mapping(SlotId => uint256) private markers; mapping(SlotId => uint256) private markers;
mapping(SlotId => uint256) private missed; mapping(SlotId => uint256) private missed;
@ -33,14 +33,14 @@ contract Proofs {
return timeout; return timeout;
} }
function _end(RequestId request) internal view returns (uint256) { function _end(RequestId requestId) internal view returns (uint256) {
uint256 end = ends[request]; uint256 end = ends[requestId];
require(end > 0, "Proof ending doesn't exist"); require(end > 0, "Proof ending doesn't exist");
return end; return end;
} }
function _requestId(SlotId id) internal view returns (RequestId) { function _requestId(SlotId id) internal view returns (RequestId) {
RequestId requestId = requestIds[id]; RequestId requestId = requestForSlot[id];
require(RequestId.unwrap(requestId) > 0, "request for slot doesn't exist"); require(RequestId.unwrap(requestId) > 0, "request for slot doesn't exist");
return requestId; return requestId;
} }
@ -70,17 +70,17 @@ contract Proofs {
RequestId request, // typically request id, used so that the ending is global for all slots RequestId request, // typically request id, used so that the ending is global for all slots
uint256 probability uint256 probability
) internal { ) internal {
require(!ids[id], "Slot id already in use"); require(!slotIds[id], "Slot id already in use");
ids[id] = true; slotIds[id] = true;
starts[id] = block.timestamp; starts[id] = block.timestamp;
probabilities[id] = probability; probabilities[id] = probability;
markers[id] = uint256(blockhash(block.number - 1)) % period; markers[id] = uint256(blockhash(block.number - 1)) % period;
requestIds[id] = request; requestForSlot[id] = request;
} }
function _unexpectProofs(SlotId id) internal { function _unexpectProofs(SlotId id) internal {
require(ids[id], "Proof id not in use"); require(slotIds[id], "Proof id not in use");
ids[id] = false; slotIds[id] = false;
} }
function _getPointer( function _getPointer(
@ -129,7 +129,7 @@ contract Proofs {
pointer = _getPointer(id, proofPeriod); pointer = _getPointer(id, proofPeriod);
bytes32 challenge = _getChallenge(pointer); bytes32 challenge = _getChallenge(pointer);
uint256 probability = (probabilities[id] * (256 - downtime)) / 256; uint256 probability = (probabilities[id] * (256 - downtime)) / 256;
isRequired = ids[id] && uint256(challenge) % probability == 0; isRequired = slotIds[id] && uint256(challenge) % probability == 0;
} }
function _isProofRequired( function _isProofRequired(