From 2478e36abaccbe4cfed3a635b6ad854683d23674 Mon Sep 17 00:00:00 2001 From: Eric Mastro Date: Thu, 29 Sep 2022 20:31:57 +1000 Subject: [PATCH] add back proof end mappings --- contracts/Marketplace.sol | 10 ++++++---- contracts/Proofs.sol | 7 ++++--- contracts/TestProofs.sol | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 169ad16..ce27027 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -75,7 +75,7 @@ contract Marketplace is Collateral, Proofs { ProofId proofId = _toProofId(slotId); _expectProofs( proofId, - requestId, + _toEndId(requestId), request.ask.proofProbability); _submitProof(proofId, proof); @@ -117,7 +117,7 @@ contract Marketplace is Collateral, Proofs { context.state == RequestState.Started) { context.state = RequestState.Failed; - _setProofEnd(requestId, block.timestamp - 1); + _setProofEnd(_toEndId(requestId), block.timestamp - 1); context.endsAt = block.timestamp - 1; emit RequestFailed(requestId); @@ -254,7 +254,7 @@ contract Marketplace is Collateral, Proofs { return _timeout(); } - function proofEnd(bytes32 slotId) public view returns (uint256) { + function proofEnd(SlotId slotId) public view returns (uint256) { Slot memory slot = _slot(slotId); uint256 end = _end(_toEndId(slot.requestId)); if (_slotAcceptsProofs(slotId)) { @@ -337,12 +337,14 @@ contract Marketplace is Collateral, Proofs { return ProofId.wrap(SlotId.unwrap(slotId)); } + function _toEndId(RequestId requestId) internal pure returns (EndId) { + return EndId.wrap(RequestId.unwrap(requestId)); + } function _notEqual(RequestId a, uint256 b) internal pure returns (bool) { return RequestId.unwrap(a) != bytes32(b); } - struct Request { address client; Ask ask; diff --git a/contracts/Proofs.sol b/contracts/Proofs.sol index 21e1265..0b18e71 100644 --- a/contracts/Proofs.sol +++ b/contracts/Proofs.sol @@ -3,6 +3,7 @@ pragma solidity ^0.8.8; contract Proofs { type ProofId is bytes32; + type EndId is bytes32; uint256 private immutable period; uint256 private immutable timeout; @@ -37,7 +38,7 @@ contract Proofs { return timeout; } - function _end(ProofId id) internal view returns (uint256) { + function _end(EndId endId) internal view returns (uint256) { uint256 end = ends[endId]; require(end > 0, "Proof ending doesn't exist"); return ends[endId]; @@ -45,7 +46,7 @@ contract Proofs { function _endId(ProofId id) internal view returns (EndId) { EndId endId = idEnds[id]; - require(endId > 0, "endId for given id doesn't exist"); + require(EndId.unwrap(endId) > 0, "endId for given id doesn't exist"); return endId; } @@ -187,7 +188,7 @@ contract Proofs { /// @dev Can only be set once /// @param endId the endId of the proofs to extend (typically a request id). /// @param ending the new end time (in seconds) - function _setProofEnd(bytes32 endId, uint256 ending) internal { + function _setProofEnd(EndId endId, uint256 ending) internal { // TODO: create type aliases for id and endId so that _end() can return // EndId storage and we don't need to replicate the below require here require (ends[endId] == 0 || ending < block.timestamp, "End exists or must be past"); diff --git a/contracts/TestProofs.sol b/contracts/TestProofs.sol index 9f5b0ff..ef87f44 100644 --- a/contracts/TestProofs.sol +++ b/contracts/TestProofs.sol @@ -24,7 +24,7 @@ contract TestProofs is Proofs { return _timeout(); } - function end(ProofId id) public view returns (uint256) { + function end(EndId id) public view returns (uint256) { return _end(id); } @@ -68,7 +68,7 @@ contract TestProofs is Proofs { _markProofAsMissing(id, _period); } - function setProofEnd(bytes32 id, uint256 ending) public { + function setProofEnd(EndId id, uint256 ending) public { _setProofEnd(id, ending); } }