mirror of
https://github.com/logos-storage/logos-storage-contracts-eth.git
synced 2026-01-05 23:03:12 +00:00
Reward validator when marking missing proof (#209)
This commit is contained in:
parent
6753d20b17
commit
51bae145fc
@ -7,6 +7,7 @@ const DEFAULT_CONFIGURATION = {
|
|||||||
repairRewardPercentage: 10,
|
repairRewardPercentage: 10,
|
||||||
maxNumberOfSlashes: 2,
|
maxNumberOfSlashes: 2,
|
||||||
slashPercentage: 20,
|
slashPercentage: 20,
|
||||||
|
validatorRewardPercentage: 20, // percentage of the slashed amount going to the validators
|
||||||
},
|
},
|
||||||
proofs: {
|
proofs: {
|
||||||
// period has to be less than downtime * blocktime
|
// period has to be less than downtime * blocktime
|
||||||
|
|||||||
@ -14,6 +14,7 @@ struct CollateralConfig {
|
|||||||
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
|
||||||
uint8 slashPercentage; // percentage of the collateral that is slashed
|
uint8 slashPercentage; // percentage of the collateral that is slashed
|
||||||
|
uint8 validatorRewardPercentage; // percentage of the slashed amount going to the validators
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ProofConfig {
|
struct ProofConfig {
|
||||||
|
|||||||
@ -9,7 +9,7 @@ contract FuzzMarketplace is Marketplace {
|
|||||||
constructor()
|
constructor()
|
||||||
Marketplace(
|
Marketplace(
|
||||||
MarketplaceConfig(
|
MarketplaceConfig(
|
||||||
CollateralConfig(10, 5, 10),
|
CollateralConfig(10, 5, 10, 20),
|
||||||
ProofConfig(10, 5, 64, "", 67),
|
ProofConfig(10, 5, 64, "", 67),
|
||||||
SlotReservationsConfig(20)
|
SlotReservationsConfig(20)
|
||||||
),
|
),
|
||||||
|
|||||||
@ -334,10 +334,14 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
|
|||||||
Slot storage slot = _slots[slotId];
|
Slot storage slot = _slots[slotId];
|
||||||
Request storage request = _requests[slot.requestId];
|
Request storage request = _requests[slot.requestId];
|
||||||
|
|
||||||
// TODO: Reward for validator that calls this function
|
|
||||||
|
|
||||||
uint256 slashedAmount = (request.ask.collateralPerSlot() *
|
uint256 slashedAmount = (request.ask.collateralPerSlot() *
|
||||||
_config.collateral.slashPercentage) / 100;
|
_config.collateral.slashPercentage) / 100;
|
||||||
|
|
||||||
|
uint256 validatorRewardAmount = (slashedAmount *
|
||||||
|
_config.collateral.validatorRewardPercentage) / 100;
|
||||||
|
_marketplaceTotals.sent += validatorRewardAmount;
|
||||||
|
assert(_token.transfer(msg.sender, validatorRewardAmount));
|
||||||
|
|
||||||
slot.currentCollateral -= slashedAmount;
|
slot.currentCollateral -= slashedAmount;
|
||||||
if (missingProofs(slotId) >= _config.collateral.maxNumberOfSlashes) {
|
if (missingProofs(slotId) >= _config.collateral.maxNumberOfSlashes) {
|
||||||
// When the number of slashings is at or above the allowed amount,
|
// When the number of slashings is at or above the allowed amount,
|
||||||
|
|||||||
@ -106,7 +106,8 @@ describe("Marketplace", function () {
|
|||||||
host2,
|
host2,
|
||||||
host3,
|
host3,
|
||||||
hostRewardRecipient,
|
hostRewardRecipient,
|
||||||
hostCollateralRecipient
|
hostCollateralRecipient,
|
||||||
|
validatorRecipient
|
||||||
let request
|
let request
|
||||||
let slot
|
let slot
|
||||||
|
|
||||||
@ -123,6 +124,7 @@ describe("Marketplace", function () {
|
|||||||
host3,
|
host3,
|
||||||
hostRewardRecipient,
|
hostRewardRecipient,
|
||||||
hostCollateralRecipient,
|
hostCollateralRecipient,
|
||||||
|
validatorRecipient,
|
||||||
] = await ethers.getSigners()
|
] = await ethers.getSigners()
|
||||||
host = host1
|
host = host1
|
||||||
|
|
||||||
@ -136,6 +138,7 @@ describe("Marketplace", function () {
|
|||||||
host3,
|
host3,
|
||||||
hostRewardRecipient,
|
hostRewardRecipient,
|
||||||
hostCollateralRecipient,
|
hostCollateralRecipient,
|
||||||
|
validatorRecipient,
|
||||||
]) {
|
]) {
|
||||||
await token.mint(account.address, ACCOUNT_STARTING_BALANCE)
|
await token.mint(account.address, ACCOUNT_STARTING_BALANCE)
|
||||||
}
|
}
|
||||||
@ -1384,6 +1387,36 @@ describe("Marketplace", function () {
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("rewards validator when marking proof as missing", async function () {
|
||||||
|
const id = slotId(slot)
|
||||||
|
const { slashCriterion, slashPercentage, validatorRewardPercentage } =
|
||||||
|
config.collateral
|
||||||
|
await marketplace.reserveSlot(slot.request, slot.index)
|
||||||
|
await marketplace.fillSlot(slot.request, slot.index, proof)
|
||||||
|
|
||||||
|
switchAccount(validatorRecipient)
|
||||||
|
|
||||||
|
const startBalance = await token.balanceOf(validatorRecipient.address)
|
||||||
|
|
||||||
|
await waitUntilProofIsRequired(id)
|
||||||
|
let missedPeriod = periodOf(await currentTime())
|
||||||
|
await advanceTimeForNextBlock(period + 1)
|
||||||
|
await marketplace.markProofAsMissing(id, missedPeriod)
|
||||||
|
|
||||||
|
const endBalance = await token.balanceOf(validatorRecipient.address)
|
||||||
|
|
||||||
|
const collateral = collateralPerSlot(request)
|
||||||
|
const slashedAmount = (collateral * slashPercentage) / 100
|
||||||
|
|
||||||
|
const expectedReward = Math.round(
|
||||||
|
(slashedAmount * validatorRewardPercentage) / 100
|
||||||
|
)
|
||||||
|
|
||||||
|
expect(endBalance.toNumber()).to.equal(
|
||||||
|
startBalance.toNumber() + expectedReward
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
it("frees slot when collateral slashed below minimum threshold", async function () {
|
it("frees slot when collateral slashed below minimum threshold", async function () {
|
||||||
|
|||||||
@ -7,6 +7,7 @@ const exampleConfiguration = () => ({
|
|||||||
repairRewardPercentage: 10,
|
repairRewardPercentage: 10,
|
||||||
maxNumberOfSlashes: 5,
|
maxNumberOfSlashes: 5,
|
||||||
slashPercentage: 10,
|
slashPercentage: 10,
|
||||||
|
validatorRewardPercentage: 20,
|
||||||
},
|
},
|
||||||
proofs: {
|
proofs: {
|
||||||
period: 10,
|
period: 10,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user