marketplace: keep request in myRequests when freeing slot

Because a client might still need to call withdraw()
This commit is contained in:
Mark Spanbroek 2025-05-27 10:44:34 +02:00
parent 9603025202
commit 47f3c1e36d
2 changed files with 5 additions and 32 deletions

View File

@ -261,10 +261,11 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
if (slot.host != msg.sender) revert Marketplace_InvalidSlotHost(); if (slot.host != msg.sender) revert Marketplace_InvalidSlotHost();
SlotState state = slotState(slotId); SlotState state = slotState(slotId);
if (state == SlotState.Finished) { if (
state == SlotState.Finished ||
state == SlotState.Cancelled
) {
_payoutSlot(slot.requestId, slotId); _payoutSlot(slot.requestId, slotId);
} else if (state == SlotState.Cancelled) {
_payoutCancelledSlot(slot.requestId, slotId);
} else if (state == SlotState.Failed) { } else if (state == SlotState.Failed) {
_removeFromMySlots(msg.sender, slotId); _removeFromMySlots(msg.sender, slotId);
} else if (state == SlotState.Filled) { } else if (state == SlotState.Filled) {
@ -386,24 +387,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
} }
} }
function _payoutSlot(
RequestId requestId,
SlotId slotId
) private requestIsKnown(requestId) {
RequestContext storage context = _requestContexts[requestId];
Request storage request = _requests[requestId];
context.state = RequestState.Finished;
Slot storage slot = _slots[slotId];
slot.currentCollateral = 0;
_removeFromMyRequests(request.client, requestId);
_removeFromMySlots(slot.host, slotId);
FundId fund = requestId.asFundId();
AccountId account = _vault.hostAccount(slot.host, slot.slotIndex);
_vault.withdraw(fund, account);
}
/** /**
* @notice Pays out a host for duration of time that the slot was filled, and * @notice Pays out a host for duration of time that the slot was filled, and
returns the collateral. returns the collateral.
@ -411,7 +394,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
out. out.
* @param slotId SlotId of the slot to be paid out. * @param slotId SlotId of the slot to be paid out.
*/ */
function _payoutCancelledSlot( function _payoutSlot(
RequestId requestId, RequestId requestId,
SlotId slotId SlotId slotId
) private requestIsKnown(requestId) { ) private requestIsKnown(requestId) {

View File

@ -1314,16 +1314,6 @@ describe("Marketplace", function () {
switchAccount(client) switchAccount(client)
expect(await marketplace.myRequests()).to.deep.equal([requestId(request)]) expect(await marketplace.myRequests()).to.deep.equal([requestId(request)])
}) })
it("removes request from list when request finishes", async function () {
await marketplace.requestStorage(request)
switchAccount(host)
await waitUntilStarted(marketplace, request, proof, token)
await waitUntilFinished(marketplace, requestId(request))
await marketplace.freeSlot(slotId(slot))
switchAccount(client)
expect(await marketplace.myRequests()).to.deep.equal([])
})
}) })
describe("list of active slots", function () { describe("list of active slots", function () {