From 20938ab448b2052bcf257f2a35ee9769019092ec Mon Sep 17 00:00:00 2001 From: Eric Mastro Date: Wed, 17 Aug 2022 15:26:04 +1000 Subject: [PATCH] [marketplace] Add cancelled check for marking missing proofs Add check for cancelled requests when marking proofs as missing. Add NatSpec documentation for `withdrawFunds` and `isCancelled`. --- contracts/Marketplace.sol | 7 +++++++ contracts/Storage.sol | 1 + 2 files changed, 8 insertions(+) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 4b8da05..7a76cd7 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -97,6 +97,9 @@ contract Marketplace is Collateral, Proofs { require(token.transfer(slot.host, amount), "Payment failed"); } + /// @notice Withdraws storage request funds back to the client that deposited them. + /// @dev Request must be expired, must be in RequestState.New, and the transaction must originate from the depositer address. + /// @param requestId the id of the request function withdrawFunds(bytes32 requestId) public marketplaceInvariant { Request memory request = requests[requestId]; require(block.timestamp > request.expiry, "Request not yet timed out"); @@ -116,6 +119,10 @@ 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. + /// @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]; return diff --git a/contracts/Storage.sol b/contracts/Storage.sol index 65600da..fdffae3 100644 --- a/contracts/Storage.sol +++ b/contracts/Storage.sol @@ -65,6 +65,7 @@ contract Storage is Collateral, Marketplace { } function markProofAsMissing(bytes32 slotId, uint256 period) public { + require(!isCancelled(slotId), "Request was cancelled"); _markProofAsMissing(slotId, period); if (_missed(slotId) % slashMisses == 0) { _slash(_host(slotId), slashPercentage);