Remove saturation parameter
Remove saturation parameter, delta, and instead use expansionRate as part of the storage request, in preparation for a linear curve of the expanding window definition.
This commit is contained in:
parent
7fb19f1586
commit
8b909f55d2
|
@ -6,7 +6,6 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
|||
struct MarketplaceConfig {
|
||||
CollateralConfig collateral;
|
||||
ProofConfig proofs;
|
||||
SlotReservationsConfig reservations;
|
||||
}
|
||||
|
||||
struct CollateralConfig {
|
||||
|
@ -30,10 +29,3 @@ struct ProofConfig {
|
|||
// blocks. Should be a prime number to ensure there are no cycles.
|
||||
uint8 downtimeProduct;
|
||||
}
|
||||
|
||||
struct SlotReservationsConfig {
|
||||
// Percentage of total time before expiry that all addresses are eligible to
|
||||
// reserve a slot. Total time is the duration between request creation and
|
||||
// expiry. Valid range is [0, 99].
|
||||
uint8 saturation;
|
||||
}
|
||||
|
|
|
@ -10,8 +10,7 @@ contract FuzzMarketplace is Marketplace {
|
|||
Marketplace(
|
||||
MarketplaceConfig(
|
||||
CollateralConfig(10, 5, 3, 10),
|
||||
ProofConfig(10, 5, 64, "", 67),
|
||||
SlotReservationsConfig(20)
|
||||
ProofConfig(10, 5, 64, "", 67)
|
||||
),
|
||||
new TestToken(),
|
||||
new TestVerifier()
|
||||
|
|
|
@ -59,10 +59,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
|
|||
MarketplaceConfig memory configuration,
|
||||
IERC20 token_,
|
||||
IGroth16Verifier verifier
|
||||
)
|
||||
SlotReservations(configuration.reservations)
|
||||
Proofs(configuration.proofs, verifier)
|
||||
{
|
||||
) Proofs(configuration.proofs, verifier) {
|
||||
_token = token_;
|
||||
|
||||
require(
|
||||
|
@ -105,8 +102,8 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
|
|||
"maxSlotLoss exceeds slots"
|
||||
);
|
||||
require(
|
||||
request.expansion > 0 && request.expansion <= 100,
|
||||
"expansion must be [1, 100]"
|
||||
request.expansionRate >= 0 && request.expansionRate <= 100,
|
||||
"expansionRate must be [0, 100]"
|
||||
);
|
||||
|
||||
_requests[id] = request;
|
||||
|
|
|
@ -10,10 +10,12 @@ struct Request {
|
|||
Content content;
|
||||
uint256 expiry; // amount of seconds since start of the request at which this request expires
|
||||
bytes32 nonce; // random nonce to differentiate between similar requests
|
||||
// Percentage of addresses eligible to reserve a slot halfway between request
|
||||
// creation and when all network addresses are eligible to participate
|
||||
// (saturation). Acceptable range is [1-100].
|
||||
uint8 expansion;
|
||||
// Percentage of total time before expiry that all addresses are eligible to
|
||||
// reserve a slot. Total time is the duration between request creation and
|
||||
// expiry. Higher number means faster expansion. Valid range is [0, 100],
|
||||
// where 100 means all addresses will be eligible at request creation, and 0
|
||||
// indicates that all addresses will be eligible at the time of expiry.
|
||||
uint8 expansionRate;
|
||||
}
|
||||
|
||||
struct Ask {
|
||||
|
|
|
@ -9,15 +9,9 @@ contract SlotReservations {
|
|||
using EnumerableSet for EnumerableSet.AddressSet;
|
||||
|
||||
mapping(SlotId => EnumerableSet.AddressSet) internal _reservations;
|
||||
SlotReservationsConfig private _config;
|
||||
|
||||
uint8 private constant _MAX_RESERVATIONS = 3;
|
||||
|
||||
constructor(SlotReservationsConfig memory config) {
|
||||
require(config.saturation <= 100, "saturation must be [0, 100]");
|
||||
_config = config;
|
||||
}
|
||||
|
||||
function reserveSlot(SlotId slotId) public {
|
||||
address host = msg.sender;
|
||||
require(canReserveSlot(slotId), "Reservation not allowed");
|
||||
|
|
|
@ -6,9 +6,6 @@ import "./SlotReservations.sol";
|
|||
contract TestSlotReservations is SlotReservations {
|
||||
using EnumerableSet for EnumerableSet.AddressSet;
|
||||
|
||||
// solhint-disable-next-line no-empty-blocks
|
||||
constructor(SlotReservationsConfig memory config) SlotReservations(config) {}
|
||||
|
||||
function contains(SlotId slotId, address host) public view returns (bool) {
|
||||
return _reservations[slotId].contains(host);
|
||||
}
|
||||
|
|
|
@ -225,15 +225,10 @@ describe("Marketplace", function () {
|
|||
)
|
||||
})
|
||||
|
||||
it("is rejected when expansion is out of bounds", async function () {
|
||||
request.expansion = 0
|
||||
it("is rejected when expansionRate is out of bounds", async function () {
|
||||
request.expansionRate = 101
|
||||
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
|
||||
"expansion must be [1, 100]"
|
||||
)
|
||||
|
||||
request.expansion = 101
|
||||
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
|
||||
"expansion must be [1, 100]"
|
||||
"expansionRate must be [0, 100]"
|
||||
)
|
||||
})
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ const { exampleRequest } = require("./examples")
|
|||
const { requestId, slotId } = require("./ids")
|
||||
|
||||
describe("SlotReservations", function () {
|
||||
const saturation = 20
|
||||
let reservations
|
||||
let provider, address1, address2, address3
|
||||
let request
|
||||
|
@ -15,7 +14,7 @@ describe("SlotReservations", function () {
|
|||
let SlotReservations = await ethers.getContractFactory(
|
||||
"TestSlotReservations"
|
||||
)
|
||||
reservations = await SlotReservations.deploy({ saturation })
|
||||
reservations = await SlotReservations.deploy()
|
||||
;[provider, address1, address2, address3] = await ethers.getSigners()
|
||||
|
||||
request = await exampleRequest()
|
||||
|
|
|
@ -39,7 +39,9 @@ const exampleRequest = async () => {
|
|||
},
|
||||
expiry: hours(1),
|
||||
nonce: hexlify(randomBytes(32)),
|
||||
expansion: 60, // 60% of nodes are eligible halfway to when all addresses eligible
|
||||
// 60% of the time before expiry, all addresses will be eligible to reserve
|
||||
// slots
|
||||
expansionRate: 60,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ function requestToArray(request) {
|
|||
contentToArray(request.content),
|
||||
request.expiry,
|
||||
request.nonce,
|
||||
request.expansion,
|
||||
request.expansionRate,
|
||||
],
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue