From 5a082584c936e8c032def5e60fde9c010ee4c94e Mon Sep 17 00:00:00 2001 From: antstalepresh Date: Fri, 30 Oct 2020 23:28:34 +1000 Subject: [PATCH] Remove Div operation on tally() considering sum(Weight)=1 --- x/gov/keeper/tally.go | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) diff --git a/x/gov/keeper/tally.go b/x/gov/keeper/tally.go index 2598293a8..cc87d68ed 100644 --- a/x/gov/keeper/tally.go +++ b/x/gov/keeper/tally.go @@ -60,17 +60,11 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo delegatorShare := delegation.GetShares().Quo(val.DelegatorShares) votingPower := delegatorShare.MulInt(val.BondedTokens) - totalRates := sdk.NewDec(0) for _, option := range vote.Options { - totalRates = totalRates.Add(option.Weight) - } - for _, option := range vote.Options { - subPower := sdk.NewDecFromBigInt(votingPower.BigInt().Div(votingPower.Mul(option.Weight).BigInt(), totalRates.BigInt())) + subPower := votingPower.Mul(option.Weight) results[option.Option] = results[option.Option].Add(subPower) - totalVotingPower = totalVotingPower.Add(subPower) } - // TODO how should handle remainder? - // TODO how should handle when totalRates == 0 + totalVotingPower = totalVotingPower.Add(votingPower) } return false @@ -90,17 +84,11 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo fractionAfterDeductions := sharesAfterDeductions.Quo(val.DelegatorShares) votingPower := fractionAfterDeductions.MulInt(val.BondedTokens) - totalRates := sdk.NewDec(0) for _, option := range val.Vote { - totalRates = totalRates.Add(option.Weight) - } - for _, option := range val.Vote { - subPower := sdk.NewDecFromBigInt(votingPower.BigInt().Div(votingPower.Mul(option.Weight).BigInt(), totalRates.BigInt())) + subPower := votingPower.Mul(option.Weight) results[option.Option] = results[option.Option].Add(subPower) - totalVotingPower = totalVotingPower.Add(subPower) - // TODO how should handle remainder? - // TODO how should handle when totalRates == 0 } + totalVotingPower = totalVotingPower.Add(votingPower) } tallyParams := keeper.GetTallyParams(ctx)