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:
Eric 2024-09-20 15:57:14 +10:00
parent 7fb19f1586
commit 8b909f55d2
No known key found for this signature in database
10 changed files with 18 additions and 41 deletions

View File

@ -6,7 +6,6 @@ import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
struct MarketplaceConfig { struct MarketplaceConfig {
CollateralConfig collateral; CollateralConfig collateral;
ProofConfig proofs; ProofConfig proofs;
SlotReservationsConfig reservations;
} }
struct CollateralConfig { struct CollateralConfig {
@ -30,10 +29,3 @@ struct ProofConfig {
// blocks. Should be a prime number to ensure there are no cycles. // blocks. Should be a prime number to ensure there are no cycles.
uint8 downtimeProduct; 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;
}

View File

@ -10,8 +10,7 @@ contract FuzzMarketplace is Marketplace {
Marketplace( Marketplace(
MarketplaceConfig( MarketplaceConfig(
CollateralConfig(10, 5, 3, 10), CollateralConfig(10, 5, 3, 10),
ProofConfig(10, 5, 64, "", 67), ProofConfig(10, 5, 64, "", 67)
SlotReservationsConfig(20)
), ),
new TestToken(), new TestToken(),
new TestVerifier() new TestVerifier()

View File

@ -59,10 +59,7 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
MarketplaceConfig memory configuration, MarketplaceConfig memory configuration,
IERC20 token_, IERC20 token_,
IGroth16Verifier verifier IGroth16Verifier verifier
) ) Proofs(configuration.proofs, verifier) {
SlotReservations(configuration.reservations)
Proofs(configuration.proofs, verifier)
{
_token = token_; _token = token_;
require( require(
@ -105,8 +102,8 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
"maxSlotLoss exceeds slots" "maxSlotLoss exceeds slots"
); );
require( require(
request.expansion > 0 && request.expansion <= 100, request.expansionRate >= 0 && request.expansionRate <= 100,
"expansion must be [1, 100]" "expansionRate must be [0, 100]"
); );
_requests[id] = request; _requests[id] = request;

View File

@ -10,10 +10,12 @@ struct Request {
Content content; Content content;
uint256 expiry; // amount of seconds since start of the request at which this request expires uint256 expiry; // amount of seconds since start of the request at which this request expires
bytes32 nonce; // random nonce to differentiate between similar requests bytes32 nonce; // random nonce to differentiate between similar requests
// Percentage of addresses eligible to reserve a slot halfway between request // Percentage of total time before expiry that all addresses are eligible to
// creation and when all network addresses are eligible to participate // reserve a slot. Total time is the duration between request creation and
// (saturation). Acceptable range is [1-100]. // expiry. Higher number means faster expansion. Valid range is [0, 100],
uint8 expansion; // 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 { struct Ask {

View File

@ -9,15 +9,9 @@ contract SlotReservations {
using EnumerableSet for EnumerableSet.AddressSet; using EnumerableSet for EnumerableSet.AddressSet;
mapping(SlotId => EnumerableSet.AddressSet) internal _reservations; mapping(SlotId => EnumerableSet.AddressSet) internal _reservations;
SlotReservationsConfig private _config;
uint8 private constant _MAX_RESERVATIONS = 3; 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 { function reserveSlot(SlotId slotId) public {
address host = msg.sender; address host = msg.sender;
require(canReserveSlot(slotId), "Reservation not allowed"); require(canReserveSlot(slotId), "Reservation not allowed");

View File

@ -6,9 +6,6 @@ import "./SlotReservations.sol";
contract TestSlotReservations is SlotReservations { contract TestSlotReservations is SlotReservations {
using EnumerableSet for EnumerableSet.AddressSet; 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) { function contains(SlotId slotId, address host) public view returns (bool) {
return _reservations[slotId].contains(host); return _reservations[slotId].contains(host);
} }

View File

@ -225,15 +225,10 @@ describe("Marketplace", function () {
) )
}) })
it("is rejected when expansion is out of bounds", async function () { it("is rejected when expansionRate is out of bounds", async function () {
request.expansion = 0 request.expansionRate = 101
await expect(marketplace.requestStorage(request)).to.be.revertedWith( await expect(marketplace.requestStorage(request)).to.be.revertedWith(
"expansion must be [1, 100]" "expansionRate must be [0, 100]"
)
request.expansion = 101
await expect(marketplace.requestStorage(request)).to.be.revertedWith(
"expansion must be [1, 100]"
) )
}) })

View File

@ -4,7 +4,6 @@ const { exampleRequest } = require("./examples")
const { requestId, slotId } = require("./ids") const { requestId, slotId } = require("./ids")
describe("SlotReservations", function () { describe("SlotReservations", function () {
const saturation = 20
let reservations let reservations
let provider, address1, address2, address3 let provider, address1, address2, address3
let request let request
@ -15,7 +14,7 @@ describe("SlotReservations", function () {
let SlotReservations = await ethers.getContractFactory( let SlotReservations = await ethers.getContractFactory(
"TestSlotReservations" "TestSlotReservations"
) )
reservations = await SlotReservations.deploy({ saturation }) reservations = await SlotReservations.deploy()
;[provider, address1, address2, address3] = await ethers.getSigners() ;[provider, address1, address2, address3] = await ethers.getSigners()
request = await exampleRequest() request = await exampleRequest()

View File

@ -39,7 +39,9 @@ const exampleRequest = async () => {
}, },
expiry: hours(1), expiry: hours(1),
nonce: hexlify(randomBytes(32)), 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,
} }
} }

View File

@ -34,7 +34,7 @@ function requestToArray(request) {
contentToArray(request.content), contentToArray(request.content),
request.expiry, request.expiry,
request.nonce, request.nonce,
request.expansion, request.expansionRate,
], ],
] ]
} }