@@ -45,9 +45,18 @@ func CreateUpgradeHandler(
45
45
return vm , err
46
46
}
47
47
48
- UpgradeMinCommissionRate (ctx , * keepers .StakingKeeper )
49
- UpgradeSigningInfos (ctx , keepers .SlashingKeeper )
50
- ClawbackVestingFunds (ctx , sdk .MustAccAddressFromBech32 ("cosmos145hytrc49m0hn6fphp8d5h4xspwkawcuzmx498" ), keepers )
48
+ if err := UpgradeMinCommissionRate (ctx , * keepers .StakingKeeper ); err != nil {
49
+ return nil , fmt .Errorf ("failed migrating min commission rates: %s" , err )
50
+ }
51
+ if err := UpgradeSigningInfos (ctx , keepers .SlashingKeeper ); err != nil {
52
+ return nil , fmt .Errorf ("failed migrating signing infos: %s" , err )
53
+ }
54
+ if err := ClawbackVestingFunds (
55
+ ctx ,
56
+ sdk .MustAccAddressFromBech32 ("cosmos145hytrc49m0hn6fphp8d5h4xspwkawcuzmx498" ),
57
+ keepers ); err != nil {
58
+ return nil , fmt .Errorf ("failed migrating vesting funds: %s" , err )
59
+ }
51
60
52
61
ctx .Logger ().Info ("Upgrade v15 complete" )
53
62
return vm , err
@@ -58,14 +67,13 @@ func CreateUpgradeHandler(
58
67
// and updates the commission rate for all validators that have a commission rate less than 5%
59
68
// adhere to prop 826 which sets the minimum commission rate to 5% for all validators
60
69
// https://www.mintscan.io/cosmos/proposals/826
61
- func UpgradeMinCommissionRate (ctx sdk.Context , sk stakingkeeper.Keeper ) {
70
+ func UpgradeMinCommissionRate (ctx sdk.Context , sk stakingkeeper.Keeper ) error {
62
71
ctx .Logger ().Info ("Migrating min commission rate..." )
63
72
64
73
params := sk .GetParams (ctx )
65
74
params .MinCommissionRate = sdk .NewDecWithPrec (5 , 2 )
66
- err := sk .SetParams (ctx , params )
67
- if err != nil {
68
- panic (err )
75
+ if err := sk .SetParams (ctx , params ); err != nil {
76
+ return err
69
77
}
70
78
71
79
for _ , val := range sk .GetAllValidators (ctx ) {
@@ -82,11 +90,12 @@ func UpgradeMinCommissionRate(ctx sdk.Context, sk stakingkeeper.Keeper) {
82
90
}
83
91
84
92
ctx .Logger ().Info ("Finished migrating min commission rate" )
93
+ return nil
85
94
}
86
95
87
96
// UpgradeSigningInfos updates the signing infos of validators for which
88
97
// the consensus address is missing
89
- func UpgradeSigningInfos (ctx sdk.Context , sk slashingkeeper.Keeper ) {
98
+ func UpgradeSigningInfos (ctx sdk.Context , sk slashingkeeper.Keeper ) error {
90
99
ctx .Logger ().Info ("Migrating signing infos..." )
91
100
92
101
signingInfos := []slashingtypes.ValidatorSigningInfo {}
@@ -112,11 +121,12 @@ func UpgradeSigningInfos(ctx sdk.Context, sk slashingkeeper.Keeper) {
112
121
}
113
122
114
123
ctx .Logger ().Info ("Finished migrating signing infos" )
124
+ return nil
115
125
}
116
126
117
127
// ClawbackVestingFunds transfers the vesting tokens from the given vesting account
118
128
// to the community pool
119
- func ClawbackVestingFunds (ctx sdk.Context , address sdk.AccAddress , keepers * keepers.AppKeepers ) {
129
+ func ClawbackVestingFunds (ctx sdk.Context , address sdk.AccAddress , keepers * keepers.AppKeepers ) error {
120
130
ctx .Logger ().Info ("Migrating vesting funds..." )
121
131
122
132
ak := keepers .AccountKeeper
@@ -130,45 +140,55 @@ func ClawbackVestingFunds(ctx sdk.Context, address sdk.AccAddress, keepers *keep
130
140
// verify that it's a vesting account type
131
141
vestAccount , ok := account .(* vesting.ContinuousVestingAccount )
132
142
if ! ok {
133
- panic (
134
- fmt .Errorf ("%s:%s" ,
135
- sdkerrors .ErrInvalidType ,
136
- "account with address %s isn't a vesting account" ,
137
- ),
143
+ ctx .Logger ().Error (
144
+ "failed migrating vesting funds: %s: %s" ,
145
+ "provided account address isn't a vesting account: " ,
146
+ address .String (),
138
147
)
148
+
149
+ return nil
150
+ }
151
+
152
+ // returns if no coins are vesting
153
+ _ , vestingCoins := vestAccount .GetVestingCoins (ctx .BlockTime ()).Find (sk .BondDenom (ctx ))
154
+ if vestingCoins .IsNil () {
155
+ ctx .Logger ().Info (
156
+ "%s: %s" ,
157
+ "no vesting coins to migrate" ,
158
+ "Finished migrating vesting funds" ,
159
+ )
160
+
161
+ return nil
139
162
}
140
163
141
164
// unbond all delegations from vesting account
142
- err := forceUnbondAllDelegations (sk , bk , ctx , address )
143
- if err != nil {
144
- panic (err )
165
+ if err := forceUnbondAllDelegations (sk , bk , ctx , address ); err != nil {
166
+ return err
145
167
}
146
168
147
169
// transfers still vesting tokens of BondDenom to community pool
148
- _ , vestingCoins := vestAccount .GetVestingCoins (ctx .BlockTime ()).Find (sk .BondDenom (ctx ))
149
- err = forceFundCommunityPool (
170
+ if err := forceFundCommunityPool (
150
171
ak ,
151
172
dk ,
152
173
bk ,
153
174
ctx ,
154
175
vestingCoins ,
155
176
address ,
156
177
keepers .GetKey (banktypes .StoreKey ),
157
- )
158
- if err != nil {
159
- panic (err )
178
+ ); err != nil {
179
+ return err
160
180
}
161
181
162
182
// overwrite vesting account using its embedded base account
163
183
ak .SetAccount (ctx , vestAccount .BaseAccount )
164
184
165
185
// validate account balance
166
- err = bk .ValidateBalance (ctx , address )
167
- if err != nil {
168
- panic (err )
186
+ if err := bk .ValidateBalance (ctx , address ); err != nil {
187
+ return err
169
188
}
170
189
171
190
ctx .Logger ().Info ("Finished migrating vesting funds" )
191
+ return nil
172
192
}
173
193
174
194
// forceUnbondAllDelegations unbonds all the delegations from the given account address,
@@ -194,20 +214,18 @@ func forceUnbondAllDelegations(
194
214
return err
195
215
}
196
216
217
+ coins := sdk .NewCoins (sdk .NewCoin (sk .BondDenom (ctx ), returnAmount ))
218
+
197
219
// transfer the validator tokens to the not bonded pool
198
220
if validator .IsBonded () {
199
221
// doing stakingKeeper.bondedTokensToNotBonded
200
- coins := sdk .NewCoins (sdk .NewCoin (sk .BondDenom (ctx ), returnAmount ))
201
222
err = bk .SendCoinsFromModuleToModule (ctx , stakingtypes .BondedPoolName , stakingtypes .NotBondedPoolName , coins )
202
223
if err != nil {
203
224
return err
204
225
}
205
226
}
206
227
207
- bondDenom := sk .GetParams (ctx ).BondDenom
208
- amt := sdk .NewCoin (bondDenom , returnAmount )
209
-
210
- err = bk .UndelegateCoinsFromModuleToAccount (ctx , stakingtypes .NotBondedPoolName , delegator , sdk .NewCoins (amt ))
228
+ err = bk .UndelegateCoinsFromModuleToAccount (ctx , stakingtypes .NotBondedPoolName , delegator , coins )
211
229
if err != nil {
212
230
return err
213
231
}
0 commit comments