mirror of
https://github.com/logos-storage/logos-storage-contracts-eth.git
synced 2026-01-03 13:53:10 +00:00
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:
parent
5fb63c4939
commit
468bc2e833
@ -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;
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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 () {
|
||||
|
||||
@ -13,9 +13,8 @@ const SlotState = {
|
||||
Filled: 1,
|
||||
Finished: 2,
|
||||
Failed: 3,
|
||||
Paid: 4,
|
||||
Cancelled: 5,
|
||||
Repair: 6,
|
||||
Cancelled: 4,
|
||||
Repair: 5,
|
||||
}
|
||||
|
||||
function enableRequestAssertions() {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user