[storage] Slash based on slots

This commit is contained in:
Mark Spanbroek 2022-07-20 10:10:22 +02:00 committed by markspanbroek
parent e5ed3bd59d
commit 80f0cc6005
2 changed files with 10 additions and 11 deletions

View File

@ -111,8 +111,8 @@ contract Marketplace is Collateral, Proofs {
emit RequestFulfilled(requestId); emit RequestFulfilled(requestId);
} }
function _host(bytes32 requestId) internal view returns (address) { function _host(bytes32 slotId) internal view returns (address) {
return requestState[requestId].host; return slots[slotId].host;
} }
function _request(bytes32 id) internal view returns (Request storage) { function _request(bytes32 id) internal view returns (Request storage) {

View File

@ -16,7 +16,6 @@ describe("Storage", function () {
let request let request
let collateralAmount, slashMisses, slashPercentage let collateralAmount, slashMisses, slashPercentage
let slot let slot
let id
function switchAccount(account) { function switchAccount(account) {
token = token.connect(account) token = token.connect(account)
@ -39,7 +38,6 @@ describe("Storage", function () {
request = exampleRequest() request = exampleRequest()
request.client = client.address request.client = client.address
id = requestId(request)
slot = { slot = {
request: requestId(request), request: requestId(request),
index: request.content.erasure.totalNodes / 2, index: request.content.erasure.totalNodes / 2,
@ -61,10 +59,10 @@ describe("Storage", function () {
expect(retrieved.nonce).to.equal(request.nonce) expect(retrieved.nonce).to.equal(request.nonce)
}) })
it("can retrieve host that fulfilled request", async function () { it("can retrieve host that filled slot", async function () {
expect(await storage.getHost(requestId(request))).to.equal(AddressZero) expect(await storage.getHost(slotId(slot))).to.equal(AddressZero)
await storage.fulfillRequest(requestId(request), proof) await storage.fillSlot(slot.request, slot.index, proof)
expect(await storage.getHost(requestId(request))).to.equal(host.address) expect(await storage.getHost(slotId(slot))).to.equal(host.address)
}) })
describe("ending the contract", function () { describe("ending the contract", function () {
@ -88,7 +86,7 @@ describe("Storage", function () {
;({ periodOf, periodEnd } = periodic(period)) ;({ periodOf, periodEnd } = periodic(period))
}) })
async function waitUntilProofIsRequired() { async function waitUntilProofIsRequired(id) {
await advanceTimeTo(periodEnd(periodOf(await currentTime()))) await advanceTimeTo(periodEnd(periodOf(await currentTime())))
while ( while (
!( !(
@ -101,9 +99,10 @@ describe("Storage", function () {
} }
it("reduces collateral when too many proofs are missing", async 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++) { for (let i = 0; i < slashMisses; i++) {
await waitUntilProofIsRequired() await waitUntilProofIsRequired(id)
let missedPeriod = periodOf(await currentTime()) let missedPeriod = periodOf(await currentTime())
await advanceTime(period) await advanceTime(period)
await storage.markProofAsMissing(id, missedPeriod) await storage.markProofAsMissing(id, missedPeriod)