@@ -20,10 +20,11 @@ func (a *App) ExportAppStateAndValidators(
2020 height := a .LastBlockHeight () + 1
2121 if forZeroHeight {
2222 height = 0
23+
2324 a .prepForZeroHeightGenesis (ctx , jailAllowedAddrs )
2425 }
2526
26- consensusParams := a .BaseApp . GetConsensusParams (ctx )
27+ consensusParams := a .GetConsensusParams (ctx )
2728 genState := a .mm .ExportGenesis (ctx , a .Codec )
2829
2930 validators , err := staking .WriteValidators (ctx , a .StakingKeeper )
@@ -45,11 +46,7 @@ func (a *App) ExportAppStateAndValidators(
4546}
4647
4748func (a * App ) prepForZeroHeightGenesis (ctx sdk.Context , jailAllowedAddrs []string ) {
48- applyAllowedAddrs := false
49-
50- if len (jailAllowedAddrs ) > 0 {
51- applyAllowedAddrs = true
52- }
49+ applyAllowedAddrs := len (jailAllowedAddrs ) > 0
5350
5451 allowedAddrsMap := make (map [string ]bool )
5552
@@ -58,13 +55,15 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
5855 if err != nil {
5956 log .Fatal (err )
6057 }
58+
6159 allowedAddrsMap [addr ] = true
6260 }
6361
6462 a .CrisisKeeper .AssertInvariants (ctx )
6563
6664 a .StakingKeeper .IterateValidators (ctx , func (_ int64 , val stakingtypes.ValidatorI ) (stop bool ) {
6765 _ , _ = a .DistributionKeeper .WithdrawValidatorCommission (ctx , val .GetOperator ())
66+
6867 return false
6968 })
7069
@@ -79,6 +78,7 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
7978 if err != nil {
8079 panic (err )
8180 }
81+
8282 _ , _ = a .DistributionKeeper .WithdrawDelegationRewards (ctx , delAddr , valAddr )
8383 }
8484
@@ -96,6 +96,7 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
9696 a .DistributionKeeper .SetFeePool (ctx , feePool )
9797
9898 a .DistributionKeeper .Hooks ().AfterValidatorCreated (ctx , val .GetOperator ())
99+
99100 return false
100101 })
101102
@@ -104,10 +105,12 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
104105 if err != nil {
105106 panic (err )
106107 }
108+
107109 delAddr , err := sdk .AccAddressFromBech32 (del .DelegatorAddress )
108110 if err != nil {
109111 panic (err )
110112 }
113+
111114 a .DistributionKeeper .Hooks ().BeforeDelegationCreated (ctx , delAddr , valAddr )
112115 a .DistributionKeeper .Hooks ().AfterDelegationModified (ctx , delAddr , valAddr )
113116 }
@@ -118,15 +121,19 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
118121 for i := range red .Entries {
119122 red .Entries [i ].CreationHeight = 0
120123 }
124+
121125 a .StakingKeeper .SetRedelegation (ctx , red )
126+
122127 return false
123128 })
124129
125130 a .StakingKeeper .IterateUnbondingDelegations (ctx , func (_ int64 , ubd stakingtypes.UnbondingDelegation ) (stop bool ) {
126131 for i := range ubd .Entries {
127132 ubd .Entries [i ].CreationHeight = 0
128133 }
134+
129135 a .StakingKeeper .SetUnbondingDelegation (ctx , ubd )
136+
130137 return false
131138 })
132139
@@ -136,6 +143,7 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
136143
137144 for ; iterator .Valid (); iterator .Next () {
138145 addr := sdk .ValAddress (iterator .Key ()[1 :])
146+
139147 validator , found := a .StakingKeeper .GetValidator (ctx , addr )
140148 if ! found {
141149 panic ("expected validator, not found" )
@@ -147,6 +155,7 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
147155 }
148156
149157 a .StakingKeeper .SetValidator (ctx , validator )
158+
150159 counter ++
151160 }
152161
@@ -162,6 +171,7 @@ func (a *App) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []strin
162171 func (addr sdk.ConsAddress , info slashingtypes.ValidatorSigningInfo ) (stop bool ) {
163172 info .StartHeight = 0
164173 a .SlashingKeeper .SetValidatorSigningInfo (ctx , addr , info )
174+
165175 return false
166176 },
167177 )
0 commit comments