From 1316682a6f7237f76e44f6c2d6da5d87d2fefc05 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Mon, 16 Jan 2023 17:35:20 +0100 Subject: [PATCH] [marketplace] remove slotMustAcceptProofs modifier Replaced by checks on slot state --- contracts/Marketplace.sol | 26 ++++-------------------- contracts/TestMarketplace.sol | 11 ----------- test/Marketplace.test.js | 37 ----------------------------------- 3 files changed, 4 insertions(+), 70 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index d4e4a18..bb658fd 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -113,15 +113,13 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { payoutSlot(slot.requestId, slotId); } else if (state == SlotState.Failed) { removeFromMySlots(msg.sender, slotId); - } else { + } else if (state == SlotState.Filled) { _forciblyFreeSlot(slotId); } } - function markProofAsMissing( - SlotId slotId, - Period period - ) public slotMustAcceptProofs(slotId) { + function markProofAsMissing(SlotId slotId, Period period) public { + require(slotState(slotId) == SlotState.Filled, "Slot not accepting proofs"); _markProofAsMissing(slotId, period); address host = getHost(slotId); if (missingProofs(slotId) % slashMisses == 0) { @@ -136,14 +134,7 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { } } - function _forciblyFreeSlot( - SlotId slotId - ) - internal - slotMustAcceptProofs(slotId) - marketplaceInvariant - // TODO: restrict senders that can call this function - { + function _forciblyFreeSlot(SlotId slotId) internal marketplaceInvariant { Slot storage slot = _slot(slotId); RequestId requestId = slot.requestId; RequestContext storage context = requestContexts[requestId]; @@ -402,15 +393,6 @@ contract Marketplace is Collateral, Proofs, StateRetrieval { assert(funds.received == funds.balance + funds.sent); } - /// @notice Modifier that requires the request state to be that which is accepting proof submissions from hosts occupying slots. - /// @dev Request state must be new or started, and must not be cancelled, finished, or failed. - /// @param slotId id of the slot, that is mapped to a request, for which to obtain state info - modifier slotMustAcceptProofs(SlotId slotId) { - RequestId requestId = _getRequestIdForSlot(slotId); - require(_requestAcceptsProofs(requestId), "Slot not accepting proofs"); - _; - } - struct MarketplaceFunds { uint256 balance; uint256 received; diff --git a/contracts/TestMarketplace.sol b/contracts/TestMarketplace.sol index ec825df..3815386 100644 --- a/contracts/TestMarketplace.sol +++ b/contracts/TestMarketplace.sol @@ -37,15 +37,4 @@ contract TestMarketplace is Marketplace { function slot(SlotId slotId) public view returns (Slot memory) { return _slot(slotId); } - - function testAcceptsProofs( - SlotId slotId - ) - public - view - slotMustAcceptProofs(slotId) - // solhint-disable-next-line no-empty-blocks - { - - } } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index f7070fb..18043a6 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -734,43 +734,6 @@ describe("Marketplace", function () { }) }) - describe("modifiers", function () { - beforeEach(async function () { - switchAccount(client) - await token.approve(marketplace.address, price(request)) - await marketplace.requestStorage(request) - switchAccount(host) - await token.approve(marketplace.address, collateral) - await marketplace.deposit(collateral) - }) - - describe("accepting proofs", function () { - it("fails when request Cancelled", async function () { - await marketplace.fillSlot(slot.request, slot.index, proof) - await waitUntilCancelled(request) - await expect( - marketplace.testAcceptsProofs(slotId(slot)) - ).to.be.revertedWith("Slot not accepting proofs") - }) - - it("fails when request Finished", async function () { - await waitUntilStarted(marketplace, request, proof) - await waitUntilFinished(marketplace, requestId(request)) - await expect( - marketplace.testAcceptsProofs(slotId(slot)) - ).to.be.revertedWith("Slot not accepting proofs") - }) - - it("fails when request Failed", async function () { - await waitUntilStarted(marketplace, request, proof) - await waitUntilFailed(marketplace, request) - await expect( - marketplace.testAcceptsProofs(slotId(slot)) - ).to.be.revertedWith("Slot empty") - }) - }) - }) - describe("list of active requests", function () { beforeEach(async function () { switchAccount(host)