Skip to content

Commit

Permalink
Merge pull request #228 from binance-chain/rewards_calcu_fix
Browse files Browse the repository at this point in the history
Distribution calculation fix
  • Loading branch information
fletcher142 authored Jul 10, 2020
2 parents f430a26 + 61ee35a commit 8ece951
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
9 changes: 4 additions & 5 deletions x/stake/keeper/distribute_sidechain.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,15 @@ func (k Keeper) Distribute(ctx sdk.Context) {
}
totalRewardDec := sdk.NewDec(totalReward)
commission := totalRewardDec.Mul(validator.Commission.Rate)
remainReward := totalRewardDec.Sub(commission).RawInt()
remainReward := totalRewardDec.Sub(commission)
// remove all balance of bondDenom from Distribution account
distAccCoins = distAccCoins.Minus(sdk.Coins{sdk.NewCoin(bondDenom, totalReward)})
if err := k.bankKeeper.SetCoins(ctx, validator.DistributionAddr, distAccCoins); err != nil {
panic(err)
}
//shouldCarry, shouldNotCarry, remainInt := allocateReward(delegations, commission, validator.DelegatorShares.RawInt(), remainInt)
rewards := allocate(simDelsToSharers(delegations), commission, validator.DelegatorShares)
if remainReward > 0 { // assign rewards to self-delegator
if _, _, err := k.bankKeeper.AddCoins(ctx, validator.GetFeeAddr(), sdk.Coins{sdk.NewCoin(bondDenom, remainReward)}); err != nil {
rewards := allocate(simDelsToSharers(delegations), remainReward, validator.DelegatorShares)
if commission.RawInt() > 0 { // assign rewards to self-delegator
if _, _, err := k.bankKeeper.AddCoins(ctx, validator.GetFeeAddr(), sdk.Coins{sdk.NewCoin(bondDenom, commission.RawInt())}); err != nil {
panic(err)
}
}
Expand Down
2 changes: 1 addition & 1 deletion x/stake/keeper/distribute_sidechain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func TestDistribute(t *testing.T) {
validator.DelegatorShares = sdk.NewDec(totalShares)
validator.Tokens = sdk.NewDec(totalShares)
validator.DistributionAddr = Addrs[499-i]
validator, setCommErr := validator.SetInitialCommission(types.Commission{Rate: sdk.NewDecWithPrec(60, 2), MaxRate: sdk.NewDecWithPrec(90, 2)})
validator, setCommErr := validator.SetInitialCommission(types.Commission{Rate: sdk.NewDecWithPrec(40, 2), MaxRate: sdk.NewDecWithPrec(90, 2)})
require.NoError(t, setCommErr)
validators[i] = validator

Expand Down

0 comments on commit 8ece951

Please sign in to comment.