reorder fillSlot and freeSlot to be chronological

This commit is contained in:
Eric Mastro 2022-09-16 15:00:54 +10:00 committed by Eric Mastro
parent 1b216f6655
commit cce70b44a1
1 changed files with 32 additions and 32 deletions

View File

@ -47,38 +47,6 @@ contract Marketplace is Collateral, Proofs {
emit StorageRequested(id, request.ask); emit StorageRequested(id, request.ask);
} }
function _freeSlot(
bytes32 slotId
) internal marketplaceInvariant {
Slot storage slot = _slot(slotId);
bytes32 requestId = slot.requestId;
RequestContext storage context = requestContexts[requestId];
require(context.state == RequestState.Started, "Invalid state");
// TODO: burn host's slot collateral except for repair costs + mark proof
// missing reward
// Slot collateral is not yet implemented as the design decision was
// not finalised.
_unexpectProofs(slotId);
slot.host = address(0);
slot.requestId = 0;
context.slotsFilled -= 1;
emit SlotFreed(requestId, slotId);
Request memory request = _request(requestId);
uint256 slotsLost = request.ask.slots - context.slotsFilled;
if (slotsLost > request.ask.maxSlotLoss) {
context.state = RequestState.Failed;
emit RequestFailed(requestId);
// TODO: burn all remaining slot collateral (note: slot collateral not
// yet implemented)
// TODO: send client remaining funds
}
}
function fillSlot( function fillSlot(
bytes32 requestId, bytes32 requestId,
uint256 slotIndex, uint256 slotIndex,
@ -113,6 +81,38 @@ contract Marketplace is Collateral, Proofs {
} }
} }
function _freeSlot(
bytes32 slotId
) internal marketplaceInvariant {
Slot storage slot = _slot(slotId);
bytes32 requestId = slot.requestId;
RequestContext storage context = requestContexts[requestId];
require(context.state == RequestState.Started, "Invalid state");
// TODO: burn host's slot collateral except for repair costs + mark proof
// missing reward
// Slot collateral is not yet implemented as the design decision was
// not finalised.
_unexpectProofs(slotId);
slot.host = address(0);
slot.requestId = 0;
context.slotsFilled -= 1;
emit SlotFreed(requestId, slotId);
Request memory request = _request(requestId);
uint256 slotsLost = request.ask.slots - context.slotsFilled;
if (slotsLost > request.ask.maxSlotLoss) {
context.state = RequestState.Failed;
emit RequestFailed(requestId);
// TODO: burn all remaining slot collateral (note: slot collateral not
// yet implemented)
// TODO: send client remaining funds
}
}
function payoutSlot(bytes32 requestId, uint256 slotIndex) function payoutSlot(bytes32 requestId, uint256 slotIndex)
public public
marketplaceInvariant marketplaceInvariant