Reward validator when marking missing proof (#209)

This commit is contained in:
Arnaud 2025-01-27 11:33:23 +01:00 committed by GitHub
parent 6753d20b17
commit 51bae145fc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 44 additions and 4 deletions

View File

@ -7,6 +7,7 @@ const DEFAULT_CONFIGURATION = {
repairRewardPercentage: 10,
maxNumberOfSlashes: 2,
slashPercentage: 20,
validatorRewardPercentage: 20, // percentage of the slashed amount going to the validators
},
proofs: {
// period has to be less than downtime * blocktime

View File

@ -14,6 +14,7 @@ struct CollateralConfig {
uint8 repairRewardPercentage;
uint8 maxNumberOfSlashes; // frees slot when the number of slashing reaches this value
uint8 slashPercentage; // percentage of the collateral that is slashed
uint8 validatorRewardPercentage; // percentage of the slashed amount going to the validators
}
struct ProofConfig {

View File

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

View File

@ -334,10 +334,14 @@ contract Marketplace is SlotReservations, Proofs, StateRetrieval, Endian {
Slot storage slot = _slots[slotId];
Request storage request = _requests[slot.requestId];
// TODO: Reward for validator that calls this function
uint256 slashedAmount = (request.ask.collateralPerSlot() *
_config.collateral.slashPercentage) / 100;
uint256 validatorRewardAmount = (slashedAmount *
_config.collateral.validatorRewardPercentage) / 100;
_marketplaceTotals.sent += validatorRewardAmount;
assert(_token.transfer(msg.sender, validatorRewardAmount));
slot.currentCollateral -= slashedAmount;
if (missingProofs(slotId) >= _config.collateral.maxNumberOfSlashes) {
// When the number of slashings is at or above the allowed amount,

View File

@ -106,7 +106,8 @@ describe("Marketplace", function () {
host2,
host3,
hostRewardRecipient,
hostCollateralRecipient
hostCollateralRecipient,
validatorRecipient
let request
let slot
@ -123,6 +124,7 @@ describe("Marketplace", function () {
host3,
hostRewardRecipient,
hostCollateralRecipient,
validatorRecipient,
] = await ethers.getSigners()
host = host1
@ -136,6 +138,7 @@ describe("Marketplace", function () {
host3,
hostRewardRecipient,
hostCollateralRecipient,
validatorRecipient,
]) {
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 () {

View File

@ -7,6 +7,7 @@ const exampleConfiguration = () => ({
repairRewardPercentage: 10,
maxNumberOfSlashes: 5,
slashPercentage: 10,
validatorRewardPercentage: 20,
},
proofs: {
period: 10,