From 8b909f55d2e736dd2525f8f6650a7c057b0020ef Mon Sep 17 00:00:00 2001 From: Eric <5089238+emizzle@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:57:14 +1000 Subject: [PATCH] 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. --- contracts/Configuration.sol | 8 -------- contracts/FuzzMarketplace.sol | 3 +-- contracts/Marketplace.sol | 9 +++------ contracts/Requests.sol | 10 ++++++---- contracts/SlotReservations.sol | 6 ------ contracts/TestSlotReservations.sol | 3 --- test/Marketplace.test.js | 11 +++-------- test/SlotReservations.test.js | 3 +-- test/examples.js | 4 +++- test/ids.js | 2 +- 10 files changed, 18 insertions(+), 41 deletions(-) diff --git a/contracts/Configuration.sol b/contracts/Configuration.sol index b1c539d..861a144 100644 --- a/contracts/Configuration.sol +++ b/contracts/Configuration.sol @@ -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; -} diff --git a/contracts/FuzzMarketplace.sol b/contracts/FuzzMarketplace.sol index d7c20a3..efdd902 100644 --- a/contracts/FuzzMarketplace.sol +++ b/contracts/FuzzMarketplace.sol @@ -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() diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index e5eebdc..65becdc 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -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; diff --git a/contracts/Requests.sol b/contracts/Requests.sol index c8033d9..4cff6de 100644 --- a/contracts/Requests.sol +++ b/contracts/Requests.sol @@ -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 { diff --git a/contracts/SlotReservations.sol b/contracts/SlotReservations.sol index 641bf6d..67b0708 100644 --- a/contracts/SlotReservations.sol +++ b/contracts/SlotReservations.sol @@ -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"); diff --git a/contracts/TestSlotReservations.sol b/contracts/TestSlotReservations.sol index 31d19d6..edc751e 100644 --- a/contracts/TestSlotReservations.sol +++ b/contracts/TestSlotReservations.sol @@ -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); } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index f45511d..681fdd4 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -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]" ) }) diff --git a/test/SlotReservations.test.js b/test/SlotReservations.test.js index ecab002..a45700c 100644 --- a/test/SlotReservations.test.js +++ b/test/SlotReservations.test.js @@ -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() diff --git a/test/examples.js b/test/examples.js index d30d6b5..8ca6e44 100644 --- a/test/examples.js +++ b/test/examples.js @@ -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, } } diff --git a/test/ids.js b/test/ids.js index 142c4ea..403f753 100644 --- a/test/ids.js +++ b/test/ids.js @@ -34,7 +34,7 @@ function requestToArray(request) { contentToArray(request.content), request.expiry, request.nonce, - request.expansion, + request.expansionRate, ], ] }