mirror of
https://github.com/status-im/dagger-contracts.git
synced 2025-01-09 13:55:57 +00:00
33010bd20c
* feat(slot-reservations): Allow slots to be reserved Closes #175. Allows reservation of slots, without an implementation of the expanding window. - Add a function called `reserveSlot(address, SlotId)`, that allows three unique addresses per slot to be reserved, that returns bool if successful. - Use `mapping(SlotId => EnumerableSet.AddressSet)` - Return false if the address could not be added to the set (if `EnumerableSet.add` returns false) - Add `canReserveSlot(address, SlotId)` - Return `true` if set of reservations is less than 3 and the set doesn't already contain the address - Return `true` otherwise (for now, later add in logic for checking the address is inside the expanding window) - Call `canReserveSlot` from `reserveSlot` as a `require` or invariant - Add `SlotReservations` configuration struct to the network-level config, with `maxReservations`
63 lines
1.3 KiB
JavaScript
63 lines
1.3 KiB
JavaScript
const { ethers } = require("hardhat")
|
|
const { hours } = require("./time")
|
|
const { hexlify, randomBytes } = ethers.utils
|
|
|
|
const exampleConfiguration = () => ({
|
|
collateral: {
|
|
repairRewardPercentage: 10,
|
|
maxNumberOfSlashes: 5,
|
|
slashCriterion: 3,
|
|
slashPercentage: 10,
|
|
},
|
|
proofs: {
|
|
period: 10,
|
|
timeout: 5,
|
|
downtime: 64,
|
|
zkeyHash: "",
|
|
downtimeProduct: 67,
|
|
},
|
|
reservations: {
|
|
maxReservations: 3,
|
|
},
|
|
})
|
|
|
|
const exampleRequest = async () => {
|
|
return {
|
|
client: hexlify(randomBytes(20)),
|
|
ask: {
|
|
slots: 4,
|
|
slotSize: 1 * 1024 * 1024 * 1024, // 1 Gigabyte
|
|
duration: hours(10),
|
|
proofProbability: 4, // require a proof roughly once every 4 periods
|
|
reward: 84,
|
|
maxSlotLoss: 2,
|
|
collateral: 200,
|
|
},
|
|
content: {
|
|
cid: "zb2rhheVmk3bLks5MgzTqyznLu1zqGH5jrfTA1eAZXrjx7Vob",
|
|
merkleRoot: Array.from(randomBytes(32)),
|
|
},
|
|
expiry: hours(1),
|
|
nonce: hexlify(randomBytes(32)),
|
|
}
|
|
}
|
|
|
|
const exampleProof = () => ({
|
|
a: { x: 1, y: 2 },
|
|
b: { x: [3, 4], y: [5, 6] },
|
|
c: { x: 7, y: 8 },
|
|
})
|
|
|
|
const invalidProof = () => ({
|
|
a: { x: 0, y: 0 },
|
|
b: { x: [0, 0], y: [0, 0] },
|
|
c: { x: 0, y: 0 },
|
|
})
|
|
|
|
module.exports = {
|
|
exampleConfiguration,
|
|
exampleRequest,
|
|
exampleProof,
|
|
invalidProof,
|
|
}
|