Skip to content

Commit 3dd64be

Browse files
amaury1093blushialexanderbez
authored
backport: Use enum instead of int32 for BondStatus (#7499) (#7516)
* Use enum instead of int32 for BondStatus (#7499) * Migrate staking module * Add gov legacy * Add comments * Add x/distrib * x/crisis * x/mint * Fix test * migrate x/genutil * Fix lint * Fix staking constants * Fix test * Update x/genutil/legacy/v040/migrate.go Co-authored-by: Marie Gauthier <[email protected]> * Add migrate script instead of change BondStatus constants * Change staking bondStatus to enum * Fix test * Fix another test * Remove staking exported * fix references * Better constants * Fix build * Fix lint * Remove buf version * Fix tests * Fix test Co-authored-by: Marie Gauthier <[email protected]> Co-authored-by: Aleksandr Bezobchuk <[email protected]> * Update CHANGELOG Co-authored-by: Marie Gauthier <[email protected]> Co-authored-by: Aleksandr Bezobchuk <[email protected]>
1 parent 1532492 commit 3dd64be

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+1036
-1000
lines changed

CHANGELOG.md

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ Ref: https://keepachangelog.com/en/1.0.0/
3434

3535
# Changelog
3636

37+
## v0.40.0-rc1 - [Unreleased]
38+
39+
### Client Breaking Changes
40+
41+
* __General__
42+
* (x/staking) [\#7499](https://github.com/cosmos/cosmos-sdk/pull/7499) `BondStatus` is now a protobuf `enum` instead of an `int32`, and JSON serialized using its protobuf name, so expect names like `BOND_STATUS_UNBONDING` as opposed to `Unbonding`.
43+
3744
## v0.40.0-rc0 - 2020-10-13
3845

3946
v0.40.0, known as the Stargate release of the Cosmos SDK, is one of the largest releases

proto/cosmos/staking/v1beta1/staking.proto

+15-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ message Validator {
7575
string operator_address = 1 [(gogoproto.moretags) = "yaml:\"operator_address\""];
7676
string consensus_pubkey = 2 [(gogoproto.moretags) = "yaml:\"consensus_pubkey\""];
7777
bool jailed = 3;
78-
int32 status = 4 [(gogoproto.casttype) = "github.com/cosmos/cosmos-sdk/types.BondStatus"];
78+
BondStatus status = 4;
7979
string tokens = 5 [(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int", (gogoproto.nullable) = false];
8080
string delegator_shares = 6 [
8181
(gogoproto.moretags) = "yaml:\"delegator_shares\"",
@@ -94,6 +94,20 @@ message Validator {
9494
];
9595
}
9696

97+
// BondStatus is the status of a validator.
98+
enum BondStatus {
99+
option (gogoproto.goproto_enum_prefix) = false;
100+
101+
// UNSPECIFIED defines an invalid validator status.
102+
BOND_STATUS_UNSPECIFIED = 0 [(gogoproto.enumvalue_customname) = "Unspecified"];
103+
// UNBONDED defines a validator that is not bonded.
104+
BOND_STATUS_UNBONDED = 1 [(gogoproto.enumvalue_customname) = "Unbonded"];
105+
// UNBONDING defines a validator that is unbonding.
106+
BOND_STATUS_UNBONDING = 2 [(gogoproto.enumvalue_customname) = "Unbonding"];
107+
// BONDED defines a validator that is bonded.
108+
BOND_STATUS_BONDED = 3 [(gogoproto.enumvalue_customname) = "Bonded"];
109+
}
110+
97111
// ValAddresses defines a repeated set of validator addresses.
98112
message ValAddresses {
99113
option (gogoproto.goproto_stringer) = false;

simapp/export.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
sdk "github.com/cosmos/cosmos-sdk/types"
1111
slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types"
1212
"github.com/cosmos/cosmos-sdk/x/staking"
13-
"github.com/cosmos/cosmos-sdk/x/staking/exported"
1413
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
1514
)
1615

@@ -72,7 +71,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
7271
/* Handle fee distribution state. */
7372

7473
// withdraw all validator commission
75-
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
74+
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
7675
_, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
7776
return false
7877
})
@@ -103,7 +102,7 @@ func (app *SimApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []
103102
ctx = ctx.WithBlockHeight(0)
104103

105104
// reinitialize all validators
106-
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
105+
app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
107106
// donate any unwithdrawn outstanding reward fraction tokens to the community pool
108107
scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
109108
feePool := app.DistrKeeper.GetFeePool(ctx)

simapp/test_helpers.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func SetupWithGenesisValSet(t *testing.T, valSet *tmtypes.ValidatorSet, genAccs
9696
OperatorAddress: sdk.ValAddress(val.Address).String(),
9797
ConsensusPubkey: sdk.MustBech32ifyPubKey(sdk.Bech32PubKeyTypeConsPub, val.PubKey),
9898
Jailed: false,
99-
Status: sdk.Bonded,
99+
Status: stakingtypes.Bonded,
100100
Tokens: bondAmt,
101101
DelegatorShares: sdk.OneDec(),
102102
Description: stakingtypes.Description{},

types/staking.go

-36
Original file line numberDiff line numberDiff line change
@@ -34,39 +34,3 @@ func TokensToConsensusPower(tokens Int) int64 {
3434
func TokensFromConsensusPower(power int64) Int {
3535
return NewInt(power).Mul(PowerReduction)
3636
}
37-
38-
// BondStatus is the status of a validator
39-
type BondStatus int32
40-
41-
// staking constants
42-
const (
43-
Unbonded BondStatus = 1
44-
Unbonding BondStatus = 2
45-
Bonded BondStatus = 3
46-
47-
BondStatusUnbonded = "Unbonded"
48-
BondStatusUnbonding = "Unbonding"
49-
BondStatusBonded = "Bonded"
50-
)
51-
52-
// Equal compares two BondStatus instances
53-
func (b BondStatus) Equal(b2 BondStatus) bool {
54-
return byte(b) == byte(b2)
55-
}
56-
57-
// String implements the Stringer interface for BondStatus.
58-
func (b BondStatus) String() string {
59-
switch b {
60-
case Unbonded:
61-
return BondStatusUnbonded
62-
63-
case Unbonding:
64-
return BondStatusUnbonding
65-
66-
case Bonded:
67-
return BondStatusBonded
68-
69-
default:
70-
panic("invalid bond status")
71-
}
72-
}

types/staking_test.go

-10
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ func (s *stakingTestSuite) SetupSuite() {
2020
s.T().Parallel()
2121
}
2222

23-
func (s *stakingTestSuite) TestBondStatus() {
24-
s.Require().False(sdk.Unbonded.Equal(sdk.Bonded))
25-
s.Require().False(sdk.Unbonded.Equal(sdk.Unbonding))
26-
s.Require().False(sdk.Bonded.Equal(sdk.Unbonding))
27-
s.Require().Panicsf(func() { sdk.BondStatus(0).String() }, "invalid bond status") // nolint:govet
28-
s.Require().Equal(sdk.BondStatusUnbonded, sdk.Unbonded.String())
29-
s.Require().Equal(sdk.BondStatusBonded, sdk.Bonded.String())
30-
s.Require().Equal(sdk.BondStatusUnbonding, sdk.Unbonding.String())
31-
}
32-
3323
func (s *stakingTestSuite) TestTokensToConsensusPower() {
3424
s.Require().Equal(int64(0), sdk.TokensToConsensusPower(sdk.NewInt(999_999)))
3525
s.Require().Equal(int64(1), sdk.TokensToConsensusPower(sdk.NewInt(1_000_000)))

x/distribution/keeper/allocation.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import (
77

88
sdk "github.com/cosmos/cosmos-sdk/types"
99
"github.com/cosmos/cosmos-sdk/x/distribution/types"
10-
"github.com/cosmos/cosmos-sdk/x/staking/exported"
10+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
1111
)
1212

1313
// AllocateTokens handles distribution of the collected fees
@@ -100,7 +100,7 @@ func (k Keeper) AllocateTokens(
100100
}
101101

102102
// AllocateTokensToValidator allocate tokens to a particular validator, splitting according to commission
103-
func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val exported.ValidatorI, tokens sdk.DecCoins) {
103+
func (k Keeper) AllocateTokensToValidator(ctx sdk.Context, val stakingtypes.ValidatorI, tokens sdk.DecCoins) {
104104
// split tokens between validator and delegators according to commission
105105
commission := tokens.MulDec(val.GetCommission())
106106
shared := tokens.Sub(commission)

x/distribution/keeper/delegation.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
sdk "github.com/cosmos/cosmos-sdk/types"
77

88
"github.com/cosmos/cosmos-sdk/x/distribution/types"
9-
"github.com/cosmos/cosmos-sdk/x/staking/exported"
9+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
1010
)
1111

1212
// initialize starting info for a new delegation
@@ -28,7 +28,7 @@ func (k Keeper) initializeDelegation(ctx sdk.Context, val sdk.ValAddress, del sd
2828
}
2929

3030
// calculate the rewards accrued by a delegation between two periods
31-
func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val exported.ValidatorI,
31+
func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val stakingtypes.ValidatorI,
3232
startingPeriod, endingPeriod uint64, stake sdk.Dec) (rewards sdk.DecCoins) {
3333
// sanity check
3434
if startingPeriod > endingPeriod {
@@ -53,7 +53,7 @@ func (k Keeper) calculateDelegationRewardsBetween(ctx sdk.Context, val exported.
5353
}
5454

5555
// calculate the total rewards accrued by a delegation
56-
func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val exported.ValidatorI, del exported.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins) {
56+
func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI, endingPeriod uint64) (rewards sdk.DecCoins) {
5757
// fetch starting info for delegation
5858
startingInfo := k.GetDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr())
5959

@@ -136,7 +136,7 @@ func (k Keeper) CalculateDelegationRewards(ctx sdk.Context, val exported.Validat
136136
return rewards
137137
}
138138

139-
func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val exported.ValidatorI, del exported.DelegationI) (sdk.Coins, error) {
139+
func (k Keeper) withdrawDelegationRewards(ctx sdk.Context, val stakingtypes.ValidatorI, del stakingtypes.DelegationI) (sdk.Coins, error) {
140140
// check existence of delegator starting info
141141
if !k.HasDelegatorStartingInfo(ctx, del.GetValidatorAddr(), del.GetDelegatorAddr()) {
142142
return nil, types.ErrEmptyDelegationDistInfo

x/distribution/keeper/grpc_query.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1212
"github.com/cosmos/cosmos-sdk/types/query"
1313
"github.com/cosmos/cosmos-sdk/x/distribution/types"
14-
"github.com/cosmos/cosmos-sdk/x/staking/exported"
14+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
1515
)
1616

1717
var _ types.QueryServer = Keeper{}
@@ -178,7 +178,7 @@ func (k Keeper) DelegationTotalRewards(c context.Context, req *types.QueryDelega
178178

179179
k.stakingKeeper.IterateDelegations(
180180
ctx, delAdr,
181-
func(_ int64, del exported.DelegationI) (stop bool) {
181+
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
182182
valAddr := del.GetValidatorAddr()
183183
val := k.stakingKeeper.Validator(ctx, valAddr)
184184
endingPeriod := k.IncrementValidatorPeriod(ctx, val)
@@ -212,7 +212,7 @@ func (k Keeper) DelegatorValidators(c context.Context, req *types.QueryDelegator
212212

213213
k.stakingKeeper.IterateDelegations(
214214
ctx, delAdr,
215-
func(_ int64, del exported.DelegationI) (stop bool) {
215+
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
216216
validators = append(validators, del.GetValidatorAddr().String())
217217
return false
218218
},

x/distribution/keeper/invariants.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55

66
sdk "github.com/cosmos/cosmos-sdk/types"
77
"github.com/cosmos/cosmos-sdk/x/distribution/types"
8-
"github.com/cosmos/cosmos-sdk/x/staking/exported"
8+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
99
)
1010

1111
// register all distribution invariants
@@ -77,7 +77,7 @@ func CanWithdrawInvariant(k Keeper) sdk.Invariant {
7777
}
7878

7979
// iterate over all validators
80-
k.stakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
80+
k.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
8181
_, _ = k.WithdrawValidatorCommission(ctx, val.GetOperator())
8282

8383
delegationAddrs, ok := valDelegationAddrs[val.GetOperator().String()]
@@ -108,7 +108,7 @@ func ReferenceCountInvariant(k Keeper) sdk.Invariant {
108108
return func(ctx sdk.Context) (string, bool) {
109109

110110
valCount := uint64(0)
111-
k.stakingKeeper.IterateValidators(ctx, func(_ int64, val exported.ValidatorI) (stop bool) {
111+
k.stakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
112112
valCount++
113113
return false
114114
})

x/distribution/keeper/querier.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
sdk "github.com/cosmos/cosmos-sdk/types"
1010
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
1111
"github.com/cosmos/cosmos-sdk/x/distribution/types"
12-
"github.com/cosmos/cosmos-sdk/x/staking/exported"
12+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
1313
)
1414

1515
func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
@@ -172,7 +172,7 @@ func queryDelegatorTotalRewards(ctx sdk.Context, _ []string, req abci.RequestQue
172172

173173
k.stakingKeeper.IterateDelegations(
174174
ctx, params.DelegatorAddress,
175-
func(_ int64, del exported.DelegationI) (stop bool) {
175+
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
176176
valAddr := del.GetValidatorAddr()
177177
val := k.stakingKeeper.Validator(ctx, valAddr)
178178
endingPeriod := k.IncrementValidatorPeriod(ctx, val)
@@ -208,7 +208,7 @@ func queryDelegatorValidators(ctx sdk.Context, _ []string, req abci.RequestQuery
208208

209209
k.stakingKeeper.IterateDelegations(
210210
ctx, params.DelegatorAddress,
211-
func(_ int64, del exported.DelegationI) (stop bool) {
211+
func(_ int64, del stakingtypes.DelegationI) (stop bool) {
212212
validators = append(validators, del.GetValidatorAddr())
213213
return false
214214
},

x/distribution/keeper/validator.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import (
66
sdk "github.com/cosmos/cosmos-sdk/types"
77

88
"github.com/cosmos/cosmos-sdk/x/distribution/types"
9-
"github.com/cosmos/cosmos-sdk/x/staking/exported"
9+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
1010
)
1111

1212
// initialize rewards for a new validator
13-
func (k Keeper) initializeValidator(ctx sdk.Context, val exported.ValidatorI) {
13+
func (k Keeper) initializeValidator(ctx sdk.Context, val stakingtypes.ValidatorI) {
1414
// set initial historical rewards (period 0) with reference count of 1
1515
k.SetValidatorHistoricalRewards(ctx, val.GetOperator(), 0, types.NewValidatorHistoricalRewards(sdk.DecCoins{}, 1))
1616

@@ -25,7 +25,7 @@ func (k Keeper) initializeValidator(ctx sdk.Context, val exported.ValidatorI) {
2525
}
2626

2727
// increment validator period, returning the period just ended
28-
func (k Keeper) IncrementValidatorPeriod(ctx sdk.Context, val exported.ValidatorI) uint64 {
28+
func (k Keeper) IncrementValidatorPeriod(ctx sdk.Context, val stakingtypes.ValidatorI) uint64 {
2929
// fetch current rewards
3030
rewards := k.GetValidatorCurrentRewards(ctx, val.GetOperator())
3131

x/distribution/types/expected_keepers.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package types
33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55
"github.com/cosmos/cosmos-sdk/x/auth/types"
6-
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
76
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
87
)
98

@@ -35,18 +34,18 @@ type BankKeeper interface {
3534
type StakingKeeper interface {
3635
// iterate through validators by operator address, execute func for each validator
3736
IterateValidators(sdk.Context,
38-
func(index int64, validator stakingexported.ValidatorI) (stop bool))
37+
func(index int64, validator stakingtypes.ValidatorI) (stop bool))
3938

4039
// iterate through bonded validators by operator address, execute func for each validator
4140
IterateBondedValidatorsByPower(sdk.Context,
42-
func(index int64, validator stakingexported.ValidatorI) (stop bool))
41+
func(index int64, validator stakingtypes.ValidatorI) (stop bool))
4342

4443
// iterate through the consensus validator set of the last block by operator address, execute func for each validator
4544
IterateLastValidators(sdk.Context,
46-
func(index int64, validator stakingexported.ValidatorI) (stop bool))
45+
func(index int64, validator stakingtypes.ValidatorI) (stop bool))
4746

48-
Validator(sdk.Context, sdk.ValAddress) stakingexported.ValidatorI // get a particular validator by operator address
49-
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingexported.ValidatorI // get a particular validator by consensus address
47+
Validator(sdk.Context, sdk.ValAddress) stakingtypes.ValidatorI // get a particular validator by operator address
48+
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI // get a particular validator by consensus address
5049

5150
// slash the validator and delegators of the validator, specifying offence height, offence power, and slash fraction
5251
Slash(sdk.Context, sdk.ConsAddress, int64, int64, sdk.Dec)
@@ -55,13 +54,13 @@ type StakingKeeper interface {
5554

5655
// Delegation allows for getting a particular delegation for a given validator
5756
// and delegator outside the scope of the staking module.
58-
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingexported.DelegationI
57+
Delegation(sdk.Context, sdk.AccAddress, sdk.ValAddress) stakingtypes.DelegationI
5958

6059
// MaxValidators returns the maximum amount of bonded validators
6160
MaxValidators(sdk.Context) uint32
6261

6362
IterateDelegations(ctx sdk.Context, delegator sdk.AccAddress,
64-
fn func(index int64, delegation stakingexported.DelegationI) (stop bool))
63+
fn func(index int64, delegation stakingtypes.DelegationI) (stop bool))
6564

6665
GetLastTotalPower(ctx sdk.Context) sdk.Int
6766
GetLastValidatorPower(ctx sdk.Context, valAddr sdk.ValAddress) int64

x/evidence/types/expected_keepers.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@ import (
66
"github.com/tendermint/tendermint/crypto"
77

88
sdk "github.com/cosmos/cosmos-sdk/types"
9-
stakingexported "github.com/cosmos/cosmos-sdk/x/staking/exported"
9+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
1010
)
1111

1212
type (
1313
// StakingKeeper defines the staking module interface contract needed by the
1414
// evidence module.
1515
StakingKeeper interface {
16-
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingexported.ValidatorI
16+
ValidatorByConsAddr(sdk.Context, sdk.ConsAddress) stakingtypes.ValidatorI
1717
}
1818

1919
// SlashingKeeper defines the slashing module interface contract needed by the

x/gov/keeper/common_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ func createValidators(ctx sdk.Context, app *simapp.SimApp, powers []int64) ([]sd
4141
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val2)
4242
app.StakingKeeper.SetNewValidatorByPowerIndex(ctx, val3)
4343

44-
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), sdk.Unbonded, val1, true)
45-
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), sdk.Unbonded, val2, true)
46-
_, _ = app.StakingKeeper.Delegate(ctx, addrs[2], sdk.TokensFromConsensusPower(powers[2]), sdk.Unbonded, val3, true)
44+
_, _ = app.StakingKeeper.Delegate(ctx, addrs[0], sdk.TokensFromConsensusPower(powers[0]), stakingtypes.Unbonded, val1, true)
45+
_, _ = app.StakingKeeper.Delegate(ctx, addrs[1], sdk.TokensFromConsensusPower(powers[1]), stakingtypes.Unbonded, val2, true)
46+
_, _ = app.StakingKeeper.Delegate(ctx, addrs[2], sdk.TokensFromConsensusPower(powers[2]), stakingtypes.Unbonded, val3, true)
4747

4848
_ = staking.EndBlocker(ctx, app.StakingKeeper)
4949

x/gov/keeper/tally.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package keeper
33
import (
44
sdk "github.com/cosmos/cosmos-sdk/types"
55
"github.com/cosmos/cosmos-sdk/x/gov/types"
6-
"github.com/cosmos/cosmos-sdk/x/staking/exported"
6+
stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types"
77
)
88

99
// TODO: Break into several smaller functions for clarity
@@ -21,7 +21,7 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo
2121
currValidators := make(map[string]types.ValidatorGovInfo)
2222

2323
// fetch all the bonded validators, insert them into currValidators
24-
keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator exported.ValidatorI) (stop bool) {
24+
keeper.sk.IterateBondedValidatorsByPower(ctx, func(index int64, validator stakingtypes.ValidatorI) (stop bool) {
2525
currValidators[validator.GetOperator().String()] = types.NewValidatorGovInfo(
2626
validator.GetOperator(),
2727
validator.GetBondedTokens(),
@@ -48,7 +48,7 @@ func (keeper Keeper) Tally(ctx sdk.Context, proposal types.Proposal) (passes boo
4848
}
4949

5050
// iterate over all delegations from voter, deduct from any delegated-to validators
51-
keeper.sk.IterateDelegations(ctx, voter, func(index int64, delegation exported.DelegationI) (stop bool) {
51+
keeper.sk.IterateDelegations(ctx, voter, func(index int64, delegation stakingtypes.DelegationI) (stop bool) {
5252
valAddrStr := delegation.GetValidatorAddr().String()
5353

5454
if val, ok := currValidators[valAddrStr]; ok {

0 commit comments

Comments
 (0)