[Storage] Remove Storage

Rationale: it was already a very thin wrapper
around Marketplace, and now that its remaining
functionality has been moved to Proofs and
Marketplace, we no longer need it.
This commit is contained in:
Mark Spanbroek 2023-01-09 16:01:43 +01:00 committed by markspanbroek
parent 6ea2b77a8f
commit afb89c9233
4 changed files with 9 additions and 113 deletions

View File

@ -31,7 +31,7 @@ certain amount of time.
When all goes well, the client and host perform the following steps: When all goes well, the client and host perform the following steps:
Client Host Storage Contract Client Host Marketplace Contract
| | | | | |
| | | |
| --------------- request (1) -------------> | | --------------- request (1) -------------> |

View File

@ -1,30 +0,0 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "./Marketplace.sol";
import "./Proofs.sol";
import "./Collateral.sol";
contract Storage is Marketplace {
constructor(
IERC20 token,
uint256 _proofPeriod,
uint256 _proofTimeout,
uint8 _proofDowntime,
uint256 _collateralAmount,
uint256 _slashMisses,
uint256 _slashPercentage,
uint256 _minCollateralThreshold
)
Marketplace(
token,
_collateralAmount,
_minCollateralThreshold,
_slashMisses,
_slashPercentage,
_proofPeriod,
_proofTimeout,
_proofDowntime
)
{}
}

View File

@ -1,4 +1,4 @@
async function deployStorage({ deployments, getNamedAccounts }) { async function deployMarketplace({ deployments, getNamedAccounts }) {
const token = await deployments.get("TestToken") const token = await deployments.get("TestToken")
const proofPeriod = 10 const proofPeriod = 10
const proofTimeout = 5 const proofTimeout = 5
@ -9,16 +9,16 @@ async function deployStorage({ deployments, getNamedAccounts }) {
const minCollateralThreshold = 40 const minCollateralThreshold = 40
const args = [ const args = [
token.address, token.address,
collateralAmount,
minCollateralThreshold,
slashMisses,
slashPercentage,
proofPeriod, proofPeriod,
proofTimeout, proofTimeout,
proofDowntime, proofDowntime,
collateralAmount,
slashMisses,
slashPercentage,
minCollateralThreshold,
] ]
const { deployer } = await getNamedAccounts() const { deployer } = await getNamedAccounts()
await deployments.deploy("Storage", { args, from: deployer }) await deployments.deploy("Marketplace", { args, from: deployer })
} }
async function mine256blocks({ network, ethers }) { async function mine256blocks({ network, ethers }) {
@ -29,8 +29,8 @@ async function mine256blocks({ network, ethers }) {
module.exports = async (environment) => { module.exports = async (environment) => {
await mine256blocks(environment) await mine256blocks(environment)
await deployStorage(environment) await deployMarketplace(environment)
} }
module.exports.tags = ["Storage"] module.exports.tags = ["Marketplace"]
module.exports.dependencies = ["TestToken"] module.exports.dependencies = ["TestToken"]

View File

@ -1,74 +0,0 @@
const { expect } = require("chai")
const { ethers, deployments } = require("hardhat")
const { hexlify, randomBytes } = ethers.utils
const { AddressZero } = ethers.constants
const { exampleRequest } = require("./examples")
const { advanceTime, advanceTimeTo, currentTime } = require("./evm")
const { requestId, slotId } = require("./ids")
const { periodic } = require("./time")
const { price } = require("./price")
const {
waitUntilCancelled,
waitUntilStarted,
waitUntilFinished,
} = require("./marketplace")
describe("Storage", function () {
const proof = hexlify(randomBytes(42))
let storage
let token
let client, host
let request
let collateralAmount, slashMisses, slashPercentage
let slot
function switchAccount(account) {
token = token.connect(account)
storage = storage.connect(account)
}
beforeEach(async function () {
;[client, host] = await ethers.getSigners()
await deployments.fixture(["TestToken", "Storage"])
token = await ethers.getContract("TestToken")
storage = await ethers.getContract("Storage")
await token.mint(client.address, 1_000_000_000)
await token.mint(host.address, 1_000_000_000)
collateralAmount = await storage.collateral()
slashMisses = await storage.slashMisses()
slashPercentage = await storage.slashPercentage()
minCollateralThreshold = await storage.minCollateralThreshold()
request = await exampleRequest()
request.client = client.address
slot = {
request: requestId(request),
index: request.ask.slots / 2,
}
switchAccount(client)
await token.approve(storage.address, price(request))
await storage.requestStorage(request)
switchAccount(host)
await token.approve(storage.address, collateralAmount)
await storage.deposit(collateralAmount)
})
describe("ending the contract", function () {
it("unlocks the host collateral", async function () {
await storage.fillSlot(slot.request, slot.index, proof)
await waitUntilFinished(storage, slot.request)
await storage.freeSlot(slotId(slot))
await expect(storage.withdraw()).not.to.be.reverted
})
})
})
// TODO: implement checking of actual proofs of storage, instead of dummy bool
// TODO: allow other host to take over contract when too many missed proofs
// TODO: small partial payouts when proofs are being submitted
// TODO: reward caller of markProofAsMissing