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_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;
}

View File

@ -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
}

View File

@ -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 () {

View File

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