Skip to content

Commit d25dc9f

Browse files
committed
refactor(gov): remove usage of v1.ValidatorGovInfo
This type was used to hold the validator vote and its delegation deductions. Now that vote inheritance is disabled, we don't need to hold these values any more, we can just use the type returned by the staking keeper.
1 parent 57cef19 commit d25dc9f

File tree

1 file changed

+4
-24
lines changed

1 file changed

+4
-24
lines changed

x/gov/keeper/tally.go

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,43 +20,23 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal v1.Proposal) (passes bool,
2020
results[v1.OptionNoWithVeto] = math.LegacyZeroDec()
2121

2222
totalVotingPower := math.LegacyZeroDec()
23-
currValidators := make(map[string]v1.ValidatorGovInfo)
23+
currValidators := make(map[string]stakingtypes.ValidatorI)
2424

2525
// fetch all the bonded validators, insert them into currValidators
2626
keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
27-
currValidators[validator.GetOperator().String()] = v1.NewValidatorGovInfo(
28-
validator.GetOperator(),
29-
validator.GetBondedTokens(),
30-
validator.GetDelegatorShares(),
31-
math.LegacyZeroDec(),
32-
v1.WeightedVoteOptions{},
33-
)
34-
27+
currValidators[validator.GetOperator().String()] = validator
3528
return false
3629
})
3730

3831
keeper.IterateVotes(ctx, proposal.Id, func(vote v1.Vote) bool {
39-
// if validator, just record it in the map
4032
voter := sdk.MustAccAddressFromBech32(vote.Voter)
41-
42-
valAddrStr := sdk.ValAddress(voter.Bytes()).String()
43-
if val, ok := currValidators[valAddrStr]; ok {
44-
val.Vote = vote.Options
45-
currValidators[valAddrStr] = val
46-
}
47-
48-
// iterate over all delegations from voter, deduct from any delegated-to validators
33+
// iterate over all delegations from voter
4934
keeper.sk.IterateDelegations(ctx, voter, func(index int64, delegation stakingtypes.DelegationI) (stop bool) {
5035
valAddrStr := delegation.GetValidatorAddr().String()
5136

5237
if val, ok := currValidators[valAddrStr]; ok {
53-
// There is no need to handle the special case that validator address equal to voter address.
54-
// Because voter's voting power will tally again even if there will be deduction of voter's voting power from validator.
55-
val.DelegatorDeductions = val.DelegatorDeductions.Add(delegation.GetShares())
56-
currValidators[valAddrStr] = val
57-
5838
// delegation shares * bonded / total shares
59-
votingPower := delegation.GetShares().MulInt(val.BondedTokens).Quo(val.DelegatorShares)
39+
votingPower := delegation.GetShares().MulInt(val.GetBondedTokens()).Quo(val.GetDelegatorShares())
6040

6141
for _, option := range vote.Options {
6242
weight, _ := sdk.NewDecFromStr(option.Weight)

0 commit comments

Comments
 (0)