[marketplace] add slot/request mapping, cancelled check
Add a requestId mapping to the Slot type. This allows the requestId to be obtained for a slot and the StorageRequest can be looked up from the id. Add `isSlotCancelled` to check if the request that a slot belongs to has been cancelled (not enough slots filled before expiry).
This commit is contained in:
parent
20938ab448
commit
34553ad7d9
|
@ -72,6 +72,7 @@ contract Marketplace is Collateral, Proofs {
|
||||||
_submitProof(slotId, proof);
|
_submitProof(slotId, proof);
|
||||||
|
|
||||||
slot.host = msg.sender;
|
slot.host = msg.sender;
|
||||||
|
slot.requestId = requestId;
|
||||||
context.slotsFilled += 1;
|
context.slotsFilled += 1;
|
||||||
emit SlotFilled(requestId, slotIndex, slotId);
|
emit SlotFilled(requestId, slotIndex, slotId);
|
||||||
if (context.slotsFilled == request.ask.slots) {
|
if (context.slotsFilled == request.ask.slots) {
|
||||||
|
@ -119,12 +120,12 @@ contract Marketplace is Collateral, Proofs {
|
||||||
emit RequestCancelled(requestId);
|
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.
|
/// @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
|
/// @param requestId the id of the request
|
||||||
/// @return true if request is cancelled
|
/// @return true if request is cancelled
|
||||||
function isCancelled(bytes32 requestId) public view returns (bool) {
|
function isCancelled(bytes32 requestId) public view returns (bool) {
|
||||||
RequestContext storage context = requestContexts[requestId];
|
RequestContext memory context = requestContexts[requestId];
|
||||||
return
|
return
|
||||||
context.state == RequestState.Cancelled ||
|
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) {
|
function _host(bytes32 slotId) internal view returns (address) {
|
||||||
return slots[slotId].host;
|
return slots[slotId].host;
|
||||||
}
|
}
|
||||||
|
@ -225,6 +237,7 @@ contract Marketplace is Collateral, Proofs {
|
||||||
struct Slot {
|
struct Slot {
|
||||||
address host;
|
address host;
|
||||||
bool hostPaid;
|
bool hostPaid;
|
||||||
|
bytes32 requestId;
|
||||||
}
|
}
|
||||||
|
|
||||||
event StorageRequested(bytes32 requestId, Ask ask);
|
event StorageRequested(bytes32 requestId, Ask ask);
|
||||||
|
|
|
@ -65,7 +65,7 @@ contract Storage is Collateral, Marketplace {
|
||||||
}
|
}
|
||||||
|
|
||||||
function markProofAsMissing(bytes32 slotId, uint256 period) public {
|
function markProofAsMissing(bytes32 slotId, uint256 period) public {
|
||||||
require(!isCancelled(slotId), "Request was cancelled");
|
require(!isSlotCancelled(slotId), "Request was cancelled");
|
||||||
_markProofAsMissing(slotId, period);
|
_markProofAsMissing(slotId, period);
|
||||||
if (_missed(slotId) % slashMisses == 0) {
|
if (_missed(slotId) % slashMisses == 0) {
|
||||||
_slash(_host(slotId), slashPercentage);
|
_slash(_host(slotId), slashPercentage);
|
||||||
|
|
Loading…
Reference in New Issue