From 468bc2e8333e4104830004f7d0060da88fa2cb80 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Thu, 27 Feb 2025 10:45:39 +0100 Subject: [PATCH] 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. --- contracts/Marketplace.sol | 8 -------- contracts/Requests.sol | 1 - test/Marketplace.test.js | 19 ++++++------------- test/requests.js | 5 ++--- 4 files changed, 8 insertions(+), 25 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 8300814..cee8247 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -30,7 +30,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { error Marketplace_InvalidCid(); error Marketplace_SlotNotFree(); error Marketplace_InvalidSlotHost(); - error Marketplace_AlreadyPaid(); error Marketplace_UnknownRequest(); error Marketplace_InvalidState(); error Marketplace_StartNotBeforeExpiry(); @@ -257,8 +256,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { if (slot.host != msg.sender) revert Marketplace_InvalidSlotHost(); SlotState state = slotState(slotId); - if (state == SlotState.Paid) revert Marketplace_AlreadyPaid(); - if (state == SlotState.Finished) { _payoutSlot(slot.requestId, slotId); } else if (state == SlotState.Cancelled) { @@ -394,7 +391,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { _removeFromMyRequests(request.client, requestId); _removeFromMySlots(slot.host, slotId); - slot.state = SlotState.Paid; FundId fund = requestId.asFundId(); AccountId account = _vault.hostAccount(slot.host, slot.slotIndex); _vault.withdraw(fund, account); @@ -413,7 +409,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { ) private requestIsKnown(requestId) { Slot storage slot = _slots[slotId]; _removeFromMySlots(slot.host, slotId); - slot.state = SlotState.Paid; FundId fund = requestId.asFundId(); AccountId account = _vault.hostAccount(slot.host, slot.slotIndex); _vault.withdraw(fund, account); @@ -525,9 +520,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { return SlotState.Free; } RequestState reqState = requestState(slot.requestId); - if (slot.state == SlotState.Paid) { - return SlotState.Paid; - } if (reqState == RequestState.Cancelled) { return SlotState.Cancelled; } diff --git a/contracts/Requests.sol b/contracts/Requests.sol index da13d6e..0895b1f 100644 --- a/contracts/Requests.sol +++ b/contracts/Requests.sol @@ -43,7 +43,6 @@ enum SlotState { Filled, // host has filled slot Finished, // successfully completed Failed, // the request has failed - Paid, // host has been paid Cancelled, // when request was cancelled then slot is cancelled as well 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 } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index 7592285..21fc08d 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -669,13 +669,14 @@ describe("Marketplace", function () { expect(endBalance).to.equal(startBalance) }) - it("can only be done once", async function () { + it("pays only once", async function () { await waitUntilStarted(marketplace, request, proof, token) await waitUntilFinished(marketplace, requestId(request)) await marketplace.freeSlot(slotId(slot)) - await expect(marketplace.freeSlot(slotId(slot))).to.be.revertedWith( - "Marketplace_AlreadyPaid" - ) + const startBalance = await token.balanceOf(host.address) + await marketplace.freeSlot(slotId(slot)) + const endBalance = await token.balanceOf(host.address) + expect(endBalance).to.equal(startBalance) }) it("cannot be filled again", async function () { @@ -968,8 +969,7 @@ describe("Marketplace", function () { }) describe("slot state", function () { - const { Free, Filled, Finished, Failed, Paid, Cancelled, Repair } = - SlotState + const { Free, Filled, Finished, Failed, Cancelled, Repair } = SlotState let period, periodEnd beforeEach(async function () { @@ -1042,13 +1042,6 @@ describe("Marketplace", function () { await waitUntilSlotFailed(marketplace, request, slot) expect(await marketplace.slotState(slotId(slot))).to.equal(Failed) }) - - it("changes to 'Paid' when host has been paid", async function () { - await waitUntilStarted(marketplace, request, proof, token) - await waitUntilFinished(marketplace, slot.request) - await marketplace.freeSlot(slotId(slot)) - expect(await marketplace.slotState(slotId(slot))).to.equal(Paid) - }) }) describe("slot probability", function () { diff --git a/test/requests.js b/test/requests.js index 16ad7a3..0088c9f 100644 --- a/test/requests.js +++ b/test/requests.js @@ -13,9 +13,8 @@ const SlotState = { Filled: 1, Finished: 2, Failed: 3, - Paid: 4, - Cancelled: 5, - Repair: 6, + Cancelled: 4, + Repair: 5, } function enableRequestAssertions() {