Remove missing proof leniency

This commit is contained in:
Arnaud 2025-01-14 12:16:47 +01:00
parent dfab6102e7
commit 917ad50837
No known key found for this signature in database
GPG Key ID: 69D6CE281FCAE663
7 changed files with 23 additions and 32 deletions

View File

@ -6,7 +6,6 @@ const DEFAULT_CONFIGURATION = {
collateral: { collateral: {
repairRewardPercentage: 10, repairRewardPercentage: 10,
maxNumberOfSlashes: 2, maxNumberOfSlashes: 2,
slashCriterion: 2,
slashPercentage: 20, slashPercentage: 20,
}, },
proofs: { proofs: {
@ -14,16 +13,16 @@ const DEFAULT_CONFIGURATION = {
period: 120, // seconds period: 120, // seconds
timeout: 30, // seconds timeout: 30, // seconds
downtime: 64, // number of blocks downtime: 64, // number of blocks
downtimeProduct: 67 // number of blocks downtimeProduct: 67, // number of blocks
}, },
reservations: { reservations: {
maxReservations: 3 maxReservations: 3,
} },
} }
function loadConfiguration(name) { function loadConfiguration(name) {
const path = `${BASE_PATH}/${name}/configuration.js` const path = `${BASE_PATH}/${name}/configuration.js`
if(fs.existsSync(path)) { if (fs.existsSync(path)) {
return require(path) return require(path)
} else { } else {
return DEFAULT_CONFIGURATION return DEFAULT_CONFIGURATION

View File

@ -2,7 +2,6 @@ module.exports = {
collateral: { collateral: {
repairRewardPercentage: 10, repairRewardPercentage: 10,
maxNumberOfSlashes: 2, maxNumberOfSlashes: 2,
slashCriterion: 2,
slashPercentage: 20, slashPercentage: 20,
}, },
proofs: { proofs: {
@ -11,9 +10,9 @@ module.exports = {
period: 90, // seconds period: 90, // seconds
timeout: 30, // seconds timeout: 30, // seconds
downtime: 96, // number of blocks downtime: 96, // number of blocks
downtimeProduct: 97 // number of blocks downtimeProduct: 97, // number of blocks
}, },
reservations: { reservations: {
maxReservations: 3 maxReservations: 3,
} },
} }

View File

@ -13,7 +13,6 @@ struct CollateralConfig {
/// @dev percentage of collateral that is used as repair reward /// @dev percentage of collateral that is used as repair reward
uint8 repairRewardPercentage; uint8 repairRewardPercentage;
uint8 maxNumberOfSlashes; // frees slot when the number of slashing reaches this value uint8 maxNumberOfSlashes; // frees slot when the number of slashing reaches this value
uint16 slashCriterion; // amount of proofs missed that lead to slashing
uint8 slashPercentage; // percentage of the collateral that is slashed uint8 slashPercentage; // percentage of the collateral that is slashed
} }

View File

@ -9,7 +9,7 @@ contract FuzzMarketplace is Marketplace {
constructor() constructor()
Marketplace( Marketplace(
MarketplaceConfig( MarketplaceConfig(
CollateralConfig(10, 5, 3, 10), CollateralConfig(10, 5, 10),
ProofConfig(10, 5, 64, "", 67), ProofConfig(10, 5, 64, "", 67),
SlotReservationsConfig(20) SlotReservationsConfig(20)
), ),

View File

@ -283,18 +283,13 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
// TODO: Reward for validator that calls this function // TODO: Reward for validator that calls this function
if (missingProofs(slotId) % _config.collateral.slashCriterion == 0) { uint256 slashedAmount = (request.ask.collateral *
uint256 slashedAmount = (request.ask.collateral * _config.collateral.slashPercentage) / 100;
_config.collateral.slashPercentage) / 100; slot.currentCollateral -= slashedAmount;
slot.currentCollateral -= slashedAmount; if (missingProofs(slotId) >= _config.collateral.maxNumberOfSlashes) {
if ( // When the number of slashings is at or above the allowed amount,
missingProofs(slotId) / _config.collateral.slashCriterion >= // free the slot.
_config.collateral.maxNumberOfSlashes _forciblyFreeSlot(slotId);
) {
// When the number of slashings is at or above the allowed amount,
// free the slot.
_forciblyFreeSlot(slotId);
}
} }
} }

View File

@ -1260,17 +1260,17 @@ describe("Marketplace", function () {
}) })
describe("slashing when missing proofs", function () { describe("slashing when missing proofs", function () {
it("reduces collateral when too many proofs are missing", async function () { it("reduces collateral when a proof is missing", async function () {
const id = slotId(slot) const id = slotId(slot)
const { slashCriterion, slashPercentage } = config.collateral const { slashPercentage } = config.collateral
await marketplace.reserveSlot(slot.request, slot.index) await marketplace.reserveSlot(slot.request, slot.index)
await marketplace.fillSlot(slot.request, slot.index, proof) await marketplace.fillSlot(slot.request, slot.index, proof)
for (let i = 0; i < slashCriterion; i++) {
await waitUntilProofIsRequired(id) await waitUntilProofIsRequired(id)
let missedPeriod = periodOf(await currentTime()) let missedPeriod = periodOf(await currentTime())
await advanceTimeForNextBlock(period + 1) await advanceTimeForNextBlock(period + 1)
await marketplace.markProofAsMissing(id, missedPeriod) await marketplace.markProofAsMissing(id, missedPeriod)
}
const expectedBalance = const expectedBalance =
(request.ask.collateral * (100 - slashPercentage)) / 100 (request.ask.collateral * (100 - slashPercentage)) / 100

View File

@ -6,7 +6,6 @@ const exampleConfiguration = () => ({
collateral: { collateral: {
repairRewardPercentage: 10, repairRewardPercentage: 10,
maxNumberOfSlashes: 5, maxNumberOfSlashes: 5,
slashCriterion: 3,
slashPercentage: 10, slashPercentage: 10,
}, },
proofs: { proofs: {