From 80f0cc6005afdaee34607cfbfb4dbe0ee48ebef4 Mon Sep 17 00:00:00 2001 From: Mark Spanbroek Date: Wed, 20 Jul 2022 10:10:22 +0200 Subject: [PATCH] [storage] Slash based on slots --- contracts/Marketplace.sol | 4 ++-- test/Storage.test.js | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index e1b3465..e4d570d 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -111,8 +111,8 @@ contract Marketplace is Collateral, Proofs { emit RequestFulfilled(requestId); } - function _host(bytes32 requestId) internal view returns (address) { - return requestState[requestId].host; + function _host(bytes32 slotId) internal view returns (address) { + return slots[slotId].host; } function _request(bytes32 id) internal view returns (Request storage) { diff --git a/test/Storage.test.js b/test/Storage.test.js index 062c82a..8eee723 100644 --- a/test/Storage.test.js +++ b/test/Storage.test.js @@ -16,7 +16,6 @@ describe("Storage", function () { let request let collateralAmount, slashMisses, slashPercentage let slot - let id function switchAccount(account) { token = token.connect(account) @@ -39,7 +38,6 @@ describe("Storage", function () { request = exampleRequest() request.client = client.address - id = requestId(request) slot = { request: requestId(request), index: request.content.erasure.totalNodes / 2, @@ -61,10 +59,10 @@ describe("Storage", function () { expect(retrieved.nonce).to.equal(request.nonce) }) - it("can retrieve host that fulfilled request", async function () { - expect(await storage.getHost(requestId(request))).to.equal(AddressZero) - await storage.fulfillRequest(requestId(request), proof) - expect(await storage.getHost(requestId(request))).to.equal(host.address) + it("can retrieve host that filled slot", async function () { + expect(await storage.getHost(slotId(slot))).to.equal(AddressZero) + await storage.fillSlot(slot.request, slot.index, proof) + expect(await storage.getHost(slotId(slot))).to.equal(host.address) }) describe("ending the contract", function () { @@ -88,7 +86,7 @@ describe("Storage", function () { ;({ periodOf, periodEnd } = periodic(period)) }) - async function waitUntilProofIsRequired() { + async function waitUntilProofIsRequired(id) { await advanceTimeTo(periodEnd(periodOf(await currentTime()))) while ( !( @@ -101,9 +99,10 @@ describe("Storage", function () { } it("reduces collateral when too many proofs are missing", async function () { - await storage.fulfillRequest(requestId(request), proof) + const id = slotId(slot) + await storage.fillSlot(slot.request, slot.index, proof) for (let i = 0; i < slashMisses; i++) { - await waitUntilProofIsRequired() + await waitUntilProofIsRequired(id) let missedPeriod = periodOf(await currentTime()) await advanceTime(period) await storage.markProofAsMissing(id, missedPeriod)