diff --git a/x/stake/fee_distribution.go b/x/stake/fee_distribution.go index 0924c5e8a9..5078285681 100644 --- a/x/stake/fee_distribution.go +++ b/x/stake/fee_distribution.go @@ -9,11 +9,12 @@ func (k Keeper) FeeHandler(ctx sdk.Context, collectedFees sdk.Coins) { pool := k.GetPool(ctx) params := k.GetParams(ctx) - // XXX calculate - sumOfVotingPowerOfPrecommitValidators := sdk.NewRat(67, 100) + // XXX determine candidate := NewCandidate(addrs[0], pks[0], Description{}) - toProposer := coinsMulRat(collectedFees, (sdk.NewRat(1, 100).Add(sdk.NewRat(4, 100).Mul(sumOfVotingPowerOfPrecommitValidators).Quo(pool.BondedShares)))) + // calculate the proposer reward + precommitPower := k.GetTotalPrecommitVotingPower(ctx) + toProposer := coinsMulRat(collectedFees, (sdk.NewRat(1, 100).Add(sdk.NewRat(4, 100).Mul(precommitPower).Quo(pool.BondedShares)))) candidate.ProposerRewardPool = candidate.ProposerRewardPool.Plus(toProposer) toReservePool := coinsMulRat(collectedFees, params.ReservePoolFee) diff --git a/x/stake/keeper.go b/x/stake/keeper.go index fc53f501a4..e62e5a3982 100644 --- a/x/stake/keeper.go +++ b/x/stake/keeper.go @@ -285,7 +285,7 @@ func (k Keeper) IsRecentValidator(ctx sdk.Context, pk crypto.PubKey) bool { return true } -// Is the power of non-absent prevotes +// cummulative power of the non-absent prevotes func (k Keeper) GetTotalPrecommitVotingPower(ctx sdk.Context) sdk.Rat { store := ctx.KVStore(k.storeKey) @@ -311,7 +311,7 @@ func (k Keeper) GetTotalPrecommitVotingPower(ctx sdk.Context) sdk.Rat { } } if skip { - break + continue } bz := iterator.Value() diff --git a/x/stake/keeper_test.go b/x/stake/keeper_test.go index 120450803e..16d04dd74b 100644 --- a/x/stake/keeper_test.go +++ b/x/stake/keeper_test.go @@ -638,10 +638,7 @@ func TestIsRecentValidator(t *testing.T) { func TestGetTotalPrecommitVotingPower(t *testing.T) { ctx, _, keeper := createTestInput(t, false, 0) - // set absent validators to be the 1st and 3rd record sorted by pubKey address - ctx = ctx.WithAbsentValidators([]int32{1, 3}) - - amts := []int64{9, 8, 7, 10, 6} + amts := []int64{10000, 1000, 100, 10, 1} var candidatesIn [5]Candidate for i, amt := range amts { candidatesIn[i] = NewCandidate(addrVals[i], pks[i], Description{}) @@ -653,6 +650,17 @@ func TestGetTotalPrecommitVotingPower(t *testing.T) { // test that an empty validator set doesn't have any validators validators := keeper.GetValidators(ctx) assert.Equal(t, 5, len(validators)) + + totPow := keeper.GetTotalPrecommitVotingPower(ctx) + exp := sdk.NewRat(11111) + assert.True(t, exp.Equal(totPow), "exp %v, got %v", exp, totPow) + + // set absent validators to be the 1st and 3rd record sorted by pubKey address + ctx = ctx.WithAbsentValidators([]int32{1, 3}) + totPow = keeper.GetTotalPrecommitVotingPower(ctx) + // XXX verify that this order should infact exclude these two records + exp = sdk.NewRat(11100) + assert.True(t, exp.Equal(totPow), "exp %v, got %v", exp, totPow) } func TestParams(t *testing.T) {