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.
This commit is contained in:
Mark Spanbroek 2025-02-27 10:45:39 +01:00
parent 5fb63c4939
commit 468bc2e833
4 changed files with 8 additions and 25 deletions

View File

@ -30,7 +30,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
error Marketplace_InvalidCid(); error Marketplace_InvalidCid();
error Marketplace_SlotNotFree(); error Marketplace_SlotNotFree();
error Marketplace_InvalidSlotHost(); error Marketplace_InvalidSlotHost();
error Marketplace_AlreadyPaid();
error Marketplace_UnknownRequest(); error Marketplace_UnknownRequest();
error Marketplace_InvalidState(); error Marketplace_InvalidState();
error Marketplace_StartNotBeforeExpiry(); error Marketplace_StartNotBeforeExpiry();
@ -257,8 +256,6 @@ 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.Paid) revert Marketplace_AlreadyPaid();
if (state == SlotState.Finished) { if (state == SlotState.Finished) {
_payoutSlot(slot.requestId, slotId); _payoutSlot(slot.requestId, slotId);
} else if (state == SlotState.Cancelled) { } else if (state == SlotState.Cancelled) {
@ -394,7 +391,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
_removeFromMyRequests(request.client, requestId); _removeFromMyRequests(request.client, requestId);
_removeFromMySlots(slot.host, slotId); _removeFromMySlots(slot.host, slotId);
slot.state = SlotState.Paid;
FundId fund = requestId.asFundId(); FundId fund = requestId.asFundId();
AccountId account = _vault.hostAccount(slot.host, slot.slotIndex); AccountId account = _vault.hostAccount(slot.host, slot.slotIndex);
_vault.withdraw(fund, account); _vault.withdraw(fund, account);
@ -413,7 +409,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
) private requestIsKnown(requestId) { ) private requestIsKnown(requestId) {
Slot storage slot = _slots[slotId]; Slot storage slot = _slots[slotId];
_removeFromMySlots(slot.host, slotId); _removeFromMySlots(slot.host, slotId);
slot.state = SlotState.Paid;
FundId fund = requestId.asFundId(); FundId fund = requestId.asFundId();
AccountId account = _vault.hostAccount(slot.host, slot.slotIndex); AccountId account = _vault.hostAccount(slot.host, slot.slotIndex);
_vault.withdraw(fund, account); _vault.withdraw(fund, account);
@ -525,9 +520,6 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
return SlotState.Free; return SlotState.Free;
} }
RequestState reqState = requestState(slot.requestId); RequestState reqState = requestState(slot.requestId);
if (slot.state == SlotState.Paid) {
return SlotState.Paid;
}
if (reqState == RequestState.Cancelled) { if (reqState == RequestState.Cancelled) {
return SlotState.Cancelled; return SlotState.Cancelled;
} }

View File

@ -43,7 +43,6 @@ enum SlotState {
Filled, // host has filled slot Filled, // host has filled slot
Finished, // successfully completed Finished, // successfully completed
Failed, // the request has failed Failed, // the request has failed
Paid, // host has been paid
Cancelled, // when request was cancelled then slot is cancelled as well 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 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
} }

View File

@ -669,13 +669,14 @@ describe("Marketplace", function () {
expect(endBalance).to.equal(startBalance) 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 waitUntilStarted(marketplace, request, proof, token)
await waitUntilFinished(marketplace, requestId(request)) await waitUntilFinished(marketplace, requestId(request))
await marketplace.freeSlot(slotId(slot)) await marketplace.freeSlot(slotId(slot))
await expect(marketplace.freeSlot(slotId(slot))).to.be.revertedWith( const startBalance = await token.balanceOf(host.address)
"Marketplace_AlreadyPaid" await marketplace.freeSlot(slotId(slot))
) const endBalance = await token.balanceOf(host.address)
expect(endBalance).to.equal(startBalance)
}) })
it("cannot be filled again", async function () { it("cannot be filled again", async function () {
@ -968,8 +969,7 @@ describe("Marketplace", function () {
}) })
describe("slot state", function () { describe("slot state", function () {
const { Free, Filled, Finished, Failed, Paid, Cancelled, Repair } = const { Free, Filled, Finished, Failed, Cancelled, Repair } = SlotState
SlotState
let period, periodEnd let period, periodEnd
beforeEach(async function () { beforeEach(async function () {
@ -1042,13 +1042,6 @@ describe("Marketplace", function () {
await waitUntilSlotFailed(marketplace, request, slot) await waitUntilSlotFailed(marketplace, request, slot)
expect(await marketplace.slotState(slotId(slot))).to.equal(Failed) 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 () { describe("slot probability", function () {

View File

@ -13,9 +13,8 @@ const SlotState = {
Filled: 1, Filled: 1,
Finished: 2, Finished: 2,
Failed: 3, Failed: 3,
Paid: 4, Cancelled: 4,
Cancelled: 5, Repair: 5,
Repair: 6,
} }
function enableRequestAssertions() { function enableRequestAssertions() {