feat(slot-reservations): Add expansion parameter

Add "expansion" parameter, that indicates the percentage of addresses eligible to reserve a slot halfway between request creation and when all network addresses are eligible to participate. Valid range = [1-100].
This commit is contained in:
Eric 2024-09-19 16:48:16 +10:00
parent d2ba8693e7
commit 3d5fa4708b
No known key found for this signature in database
5 changed files with 20 additions and 1 deletions

View File

@ -101,6 +101,10 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
request.ask.maxSlotLoss <= request.ask.slots,
"maxSlotLoss exceeds slots"
);
require(
request.ask.expansion > 0 && request.ask.expansion <= 100,
"expansion must be [1, 100]"
);
_requests[id] = request;
_requestContexts[id].endsAt = block.timestamp + request.ask.duration;

View File

@ -20,6 +20,7 @@ struct Ask {
uint256 reward; // amount of tokens paid per second per slot to hosts
uint256 collateral; // amount of tokens required to be deposited by the hosts in order to fill the slot
uint64 maxSlotLoss; // Max slots that can be lost without data considered to be lost
uint8 expansion; // Percentage of addresses eligible to reserve a slot halfway between request creation and when all network addresses are eligible to participate. [1-100].
}
struct Content {

View File

@ -225,6 +225,18 @@ describe("Marketplace", function () {
)
})
it("is rejected when expansion is out of bounds", async function () {
request.ask.expansion = 0
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
"expansion must be [1, 100]"
)
request.ask.expansion = 101
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
"expansion must be [1, 100]"
)
})
it("rejects resubmission of request", async function () {
await token.approve(marketplace.address, price(request) * 2)
await marketplace.requestStorage(request)

View File

@ -29,6 +29,7 @@ const exampleRequest = async () => {
reward: 84,
maxSlotLoss: 2,
collateral: 200,
expansion: 60,
},
content: {
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob",

View File

@ -2,7 +2,7 @@ const { ethers } = require("hardhat")
const { keccak256, defaultAbiCoder } = ethers.utils
function requestId(request) {
const Ask = "tuple(int64, uint256, uint256, uint256, uint256, uint256, int64)"
const Ask = "tuple(int64, uint256, uint256, uint256, uint256, uint256, uint64, uint8)"
const Content = "tuple(string, bytes32)"
const Request =
"tuple(address, " + Ask + ", " + Content + ", uint256, bytes32)"
@ -18,6 +18,7 @@ function askToArray(ask) {
ask.reward,
ask.collateral,
ask.maxSlotLoss,
ask.expansion,
]
}