diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 7a76cd7..a6127e9 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -72,6 +72,7 @@ contract Marketplace is Collateral, Proofs { _submitProof(slotId, proof); slot.host = msg.sender; + slot.requestId = requestId; context.slotsFilled += 1; emit SlotFilled(requestId, slotIndex, slotId); if (context.slotsFilled == request.ask.slots) { @@ -119,12 +120,12 @@ contract Marketplace is Collateral, Proofs { emit RequestCancelled(requestId); } - /// @notice Rseturn true if the request state is RequestState.Cancelled or if the request expiry time has elapsed and the request was never started. + /// @notice Return true if the request state is RequestState.Cancelled or if the request expiry time has elapsed and the request was never started. /// @dev Handles the case when a request may have been cancelled, but the client has not withdrawn its funds yet, and therefore the state has not yet been updated. /// @param requestId the id of the request /// @return true if request is cancelled function isCancelled(bytes32 requestId) public view returns (bool) { - RequestContext storage context = requestContexts[requestId]; + RequestContext memory context = requestContexts[requestId]; return context.state == RequestState.Cancelled || ( @@ -133,6 +134,17 @@ contract Marketplace is Collateral, Proofs { ); } + /// @notice Return true if the request state the slot belongs to is RequestState.Cancelled or if the request expiry time has elapsed and the request was never started. + /// @dev Handles the case when a request may have been cancelled, but the client has not withdrawn its funds yet, and therefore the state has not yet been updated. + /// @param slotId the id of the slot + /// @return true if request is cancelled + function isSlotCancelled(bytes32 slotId) public view returns (bool) { + Slot memory slot = slots[slotId]; + require(slot.host != address(0), "Slot empty"); + require(slot.requestId != 0, "Missing request id"); + return isCancelled(slot.requestId); + } + function _host(bytes32 slotId) internal view returns (address) { return slots[slotId].host; } @@ -225,6 +237,7 @@ contract Marketplace is Collateral, Proofs { struct Slot { address host; bool hostPaid; + bytes32 requestId; } event StorageRequested(bytes32 requestId, Ask ask); diff --git a/contracts/Storage.sol b/contracts/Storage.sol index fdffae3..4757f08 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -65,7 +65,7 @@ contract Storage is Collateral, Marketplace { } function markProofAsMissing(bytes32 slotId, uint256 period) public { - require(!isCancelled(slotId), "Request was cancelled"); + require(!isSlotCancelled(slotId), "Request was cancelled"); _markProofAsMissing(slotId, period); if (_missed(slotId) % slashMisses == 0) { _slash(_host(slotId), slashPercentage);