diff --git a/configuration/configuration.js b/configuration/configuration.js index 22541be..4381aa6 100644 --- a/configuration/configuration.js +++ b/configuration/configuration.js @@ -6,7 +6,6 @@ const DEFAULT_CONFIGURATION = { collateral: { repairRewardPercentage: 10, maxNumberOfSlashes: 2, - slashCriterion: 2, slashPercentage: 20, }, proofs: { @@ -14,16 +13,16 @@ const DEFAULT_CONFIGURATION = { period: 120, // seconds timeout: 30, // seconds downtime: 64, // number of blocks - downtimeProduct: 67 // number of blocks + downtimeProduct: 67, // number of blocks }, reservations: { - maxReservations: 3 - } + maxReservations: 3, + }, } function loadConfiguration(name) { const path = `${BASE_PATH}/${name}/configuration.js` - if(fs.existsSync(path)) { + if (fs.existsSync(path)) { return require(path) } else { return DEFAULT_CONFIGURATION diff --git a/configuration/networks/hardhat/configuration.js b/configuration/networks/hardhat/configuration.js index c5386c9..8064363 100644 --- a/configuration/networks/hardhat/configuration.js +++ b/configuration/networks/hardhat/configuration.js @@ -2,7 +2,6 @@ module.exports = { collateral: { repairRewardPercentage: 10, maxNumberOfSlashes: 2, - slashCriterion: 2, slashPercentage: 20, }, proofs: { @@ -11,9 +10,9 @@ module.exports = { period: 90, // seconds timeout: 30, // seconds downtime: 96, // number of blocks - downtimeProduct: 97 // number of blocks + downtimeProduct: 97, // number of blocks }, reservations: { - maxReservations: 3 - } + maxReservations: 3, + }, } diff --git a/contracts/Configuration.sol b/contracts/Configuration.sol index 5d7feed..2b1fd88 100644 --- a/contracts/Configuration.sol +++ b/contracts/Configuration.sol @@ -13,7 +13,6 @@ struct CollateralConfig { /// @dev percentage of collateral that is used as repair reward uint8 repairRewardPercentage; 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 } diff --git a/contracts/FuzzMarketplace.sol b/contracts/FuzzMarketplace.sol index d7c20a3..6a810a7 100644 --- a/contracts/FuzzMarketplace.sol +++ b/contracts/FuzzMarketplace.sol @@ -9,7 +9,7 @@ contract FuzzMarketplace is Marketplace { constructor() Marketplace( MarketplaceConfig( - CollateralConfig(10, 5, 3, 10), + CollateralConfig(10, 5, 10), ProofConfig(10, 5, 64, "", 67), SlotReservationsConfig(20) ), diff --git a/contracts/Marketplace.sol b/contracts/Marketplace.sol index 4271617..9b10ba8 100644 --- a/contracts/Marketplace.sol +++ b/contracts/Marketplace.sol @@ -336,18 +336,13 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian { // TODO: Reward for validator that calls this function - if (missingProofs(slotId) % _config.collateral.slashCriterion == 0) { - uint256 slashedAmount = (request.ask.collateralPerSlot() * - _config.collateral.slashPercentage) / 100; - slot.currentCollateral -= slashedAmount; - if ( - missingProofs(slotId) / _config.collateral.slashCriterion >= - _config.collateral.maxNumberOfSlashes - ) { - // When the number of slashings is at or above the allowed amount, - // free the slot. - _forciblyFreeSlot(slotId); - } + uint256 slashedAmount = (request.ask.collateralPerSlot() * + _config.collateral.slashPercentage) / 100; + slot.currentCollateral -= slashedAmount; + if (missingProofs(slotId) >= _config.collateral.maxNumberOfSlashes) { + // When the number of slashings is at or above the allowed amount, + // free the slot. + _forciblyFreeSlot(slotId); } } diff --git a/test/Marketplace.test.js b/test/Marketplace.test.js index f8fd6f2..da87a4c 100644 --- a/test/Marketplace.test.js +++ b/test/Marketplace.test.js @@ -1362,17 +1362,17 @@ describe("Marketplace", 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 { slashCriterion, slashPercentage } = config.collateral + const { slashPercentage } = config.collateral await marketplace.reserveSlot(slot.request, slot.index) await marketplace.fillSlot(slot.request, slot.index, proof) - for (let i = 0; i < slashCriterion; i++) { - await waitUntilProofIsRequired(id) - let missedPeriod = periodOf(await currentTime()) - await advanceTimeForNextBlock(period + 1) - await marketplace.markProofAsMissing(id, missedPeriod) - } + + await waitUntilProofIsRequired(id) + let missedPeriod = periodOf(await currentTime()) + await advanceTimeForNextBlock(period + 1) + await marketplace.markProofAsMissing(id, missedPeriod) + const collateral = collateralPerSlot(request) const expectedBalance = Math.round( (collateral * (100 - slashPercentage)) / 100 diff --git a/test/examples.js b/test/examples.js index ae5a955..df379ca 100644 --- a/test/examples.js +++ b/test/examples.js @@ -6,7 +6,6 @@ const exampleConfiguration = () => ({ collateral: { repairRewardPercentage: 10, maxNumberOfSlashes: 5, - slashCriterion: 3, slashPercentage: 10, }, proofs: {