Skip to content

Commit b9689f1

Browse files
committed
marketplace: remove 'Paid' state
This state is no longer necessary, vault ensures that payouts happen only once. Hosts could bypass this state anyway by withdrawing from the vault directly.
1 parent 4f85f19 commit b9689f1

File tree

4 files changed

+8
-24
lines changed

4 files changed

+8
-24
lines changed

contracts/Marketplace.sol

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
3030
error Marketplace_InvalidCid();
3131
error Marketplace_SlotNotFree();
3232
error Marketplace_InvalidSlotHost();
33-
error Marketplace_AlreadyPaid();
3433
error Marketplace_UnknownRequest();
3534
error Marketplace_InvalidState();
3635
error Marketplace_StartNotBeforeExpiry();
@@ -256,8 +255,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
256255
if (slot.host != msg.sender) revert Marketplace_InvalidSlotHost();
257256

258257
SlotState state = slotState(slotId);
259-
if (state == SlotState.Paid) revert Marketplace_AlreadyPaid();
260-
261258
if (state == SlotState.Finished) {
262259
_payoutSlot(slot.requestId, slotId);
263260
} else if (state == SlotState.Cancelled) {
@@ -380,7 +377,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
380377
_removeFromMyRequests(request.client, requestId);
381378
_removeFromMySlots(slot.host, slotId);
382379

383-
slot.state = SlotState.Paid;
384380
Fund fund = requestId.asFund();
385381
AccountId account = _vault.hostAccount(slot.host, slot.slotIndex);
386382
_vault.withdraw(fund, account);
@@ -399,7 +395,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
399395
) private requestIsKnown(requestId) {
400396
Slot storage slot = _slots[slotId];
401397
_removeFromMySlots(slot.host, slotId);
402-
slot.state = SlotState.Paid;
403398
Fund fund = requestId.asFund();
404399
AccountId account = _vault.hostAccount(slot.host, slot.slotIndex);
405400
_vault.withdraw(fund, account);
@@ -503,9 +498,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
503498
return SlotState.Free;
504499
}
505500
RequestState reqState = requestState(slot.requestId);
506-
if (slot.state == SlotState.Paid) {
507-
return SlotState.Paid;
508-
}
509501
if (reqState == RequestState.Cancelled) {
510502
return SlotState.Cancelled;
511503
}

contracts/Requests.sol

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ enum SlotState {
4343
Filled, // host has filled slot
4444
Finished, // successfully completed
4545
Failed, // the request has failed
46-
Paid, // host has been paid
4746
Cancelled, // when request was cancelled then slot is cancelled as well
4847
Repair // when slot slot was forcible freed (host was kicked out from hosting the slot because of too many missed proofs) and needs to be repaired
4948
}

test/Marketplace.test.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -635,13 +635,14 @@ describe("Marketplace", function () {
635635
expect(endBalance).to.equal(startBalance)
636636
})
637637

638-
it("can only be done once", async function () {
638+
it("pays only once", async function () {
639639
await waitUntilStarted(marketplace, request, proof, token)
640640
await waitUntilFinished(marketplace, requestId(request))
641641
await marketplace.freeSlot(slotId(slot))
642-
await expect(marketplace.freeSlot(slotId(slot))).to.be.revertedWith(
643-
"Marketplace_AlreadyPaid"
644-
)
642+
const startBalance = await token.balanceOf(host.address)
643+
await marketplace.freeSlot(slotId(slot))
644+
const endBalance = await token.balanceOf(host.address)
645+
expect(endBalance).to.equal(startBalance)
645646
})
646647

647648
it("cannot be filled again", async function () {
@@ -934,7 +935,7 @@ describe("Marketplace", function () {
934935
})
935936

936937
describe("slot state", function () {
937-
const { Free, Filled, Finished, Failed, Paid, Cancelled, Repair } =
938+
const { Free, Filled, Finished, Failed, Cancelled, Repair } =
938939
SlotState
939940
let period, periodEnd
940941

@@ -1008,13 +1009,6 @@ describe("Marketplace", function () {
10081009
await waitUntilSlotFailed(marketplace, request, slot)
10091010
expect(await marketplace.slotState(slotId(slot))).to.equal(Failed)
10101011
})
1011-
1012-
it("changes to 'Paid' when host has been paid", async function () {
1013-
await waitUntilStarted(marketplace, request, proof, token)
1014-
await waitUntilFinished(marketplace, slot.request)
1015-
await marketplace.freeSlot(slotId(slot))
1016-
expect(await marketplace.slotState(slotId(slot))).to.equal(Paid)
1017-
})
10181012
})
10191013

10201014
describe("slot probability", function () {

test/requests.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ const SlotState = {
1313
Filled: 1,
1414
Finished: 2,
1515
Failed: 3,
16-
Paid: 4,
17-
Cancelled: 5,
18-
Repair: 6,
16+
Cancelled: 4,
17+
Repair: 5,
1918
}
2019

2120
function enableRequestAssertions() {

0 commit comments

Comments
 (0)