Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #347 from maticnetwork/fix-proposer-bonus
Browse files Browse the repository at this point in the history
Fix proposer bonus
  • Loading branch information
jdkanani authored Feb 24, 2021
2 parents 8c48051 + f2da660 commit 357ae25
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 8 deletions.
7 changes: 1 addition & 6 deletions contracts/staking/stakeManager/StakeManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -876,12 +876,7 @@ contract StakeManager is
uint256 proposerId = signerToValidator[proposer];

Validator storage _proposer = validators[proposerId];
uint256 delegatedAmount = _proposer.delegatedAmount;
if (delegatedAmount > 0) {
_increaseValidatorRewardWithDelegation(proposerId, _proposer.amount, delegatedAmount, _proposerBonus);
} else {
_proposer.reward = _proposer.reward.add(_proposerBonus);
}
_proposer.reward = _proposer.reward.add(_proposerBonus);

// update stateMerkleTree root for accounts balance on heimdall chain
accountStateRoot = stateRoot;
Expand Down
40 changes: 38 additions & 2 deletions test/units/staking/stakeManager/StakeManager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ function prepareForTest(dynastyValue, validatorThreshold) {
}
}

function testCheckpointing(stakers, signers, blockInterval, checkpointsPassed, expectedRewards, order = true) {
function testCheckpointing(stakers, signers, blockInterval, checkpointsPassed, expectedRewards, order = true, proposer = null) {
it(`must checkpoint ${checkpointsPassed} time(s) with block interval ${blockInterval}`, async function() {
let _count = checkpointsPassed
while (_count-- > 0) {
await checkPoint(signers, this.rootChainOwner, this.stakeManager, { blockInterval, order })
await checkPoint(signers, proposer || this.rootChainOwner, this.stakeManager, { blockInterval, order, rootchainOwner: this.rootChainOwner })
}
})

Expand Down Expand Up @@ -451,6 +451,42 @@ contract('StakeManager', async function(accounts) {
})
}

describe('proposer bonus must be rewarded to the proposer without distribution to the delegators', function() {
const delegator = wallets[1].getChecksumAddressString()
const stakers = [
{ wallet: wallets[2], stake: new BN(web3.utils.toWei('100')) },
{ wallet: wallets[4], stake: new BN(web3.utils.toWei('100')) },
{ wallet: wallets[3], stake: new BN(web3.utils.toWei('100')) }
]

const signers = stakers.map(x => x.wallet)

prepareToTest(stakers, 1)

before(async function() {
await this.stakeManager.updateProposerBonus(10)

await this.stakeToken.mint(
delegator,
toWei('1000')
)
await this.stakeToken.approve(this.stakeManager.address, toWei('1000'), {
from: delegator
})

const validator = await this.stakeManager.validators('1')
const validatorContract = await ValidatorShare.at(validator.contractAddress)

await buyVoucher(validatorContract, toWei('100'), delegator)
})

testCheckpointing(stakers, signers, 1, 1, {
[stakers[0].wallet.getAddressString()]: toWei('3250'), // proposer fixed bonus + 50% of reward
[stakers[1].wallet.getAddressString()]: toWei('2250'),
[stakers[2].wallet.getAddressString()]: toWei('2250')
}, true, stakers[0].wallet)
})

describe('when 1st validator unstakes but 2nd do not sign a checkpoint', function() {
const validatorWallet = wallets[2]
const validatorId = '1'
Expand Down

0 comments on commit 357ae25

Please sign in to comment.