Skip to content

Commit

Permalink
remove iteration over map
Browse files Browse the repository at this point in the history
  • Loading branch information
giunatale committed Sep 25, 2024
1 parent b8eac36 commit 9bcbd0f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion x/gov/keeper/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package keeper

import (
"fmt"
"sort"

sdk "github.com/cosmos/cosmos-sdk/types"
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
Expand Down Expand Up @@ -139,7 +140,16 @@ func GovernorsDelegationsInvariant(keeper *Keeper, sk types.StakingKeeper) sdk.I
return false
})

for valAddrStr, shares := range valShares {
// Extract keys and sort them
// since the order of the keys in the map is not guaranteed
keys := make([]string, 0, len(valShares))
for key := range valShares {
keys = append(keys, key)
}
sort.Strings(keys)

for _, valAddrStr := range keys {
shares := valShares[valAddrStr]
validatorAddr, _ := sdk.ValAddressFromBech32(valAddrStr)
valShares, ok := keeper.GetGovernorValShares(ctx, governor.GetAddress(), validatorAddr)
if !ok {
Expand Down

0 comments on commit 9bcbd0f

Please sign in to comment.