prepForZeroHeightGenesis prepare for fresh start at zero height NOTE zero height genesis is a temporary feature that will be deprecated in favour of export at a block height
(ctx sdk.Context, jailAllowedAddrs []string)
| 72 | // |
| 73 | // in favour of export at a block height |
| 74 | func (app *AkashApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { |
| 75 | // Check if there is an allowed address list |
| 76 | applyAllowedAddrs := len(jailAllowedAddrs) > 0 |
| 77 | |
| 78 | allowedAddrsMap := make(map[string]bool) |
| 79 | |
| 80 | for _, addr := range jailAllowedAddrs { |
| 81 | _, err := sdk.ValAddressFromBech32(addr) |
| 82 | if err != nil { |
| 83 | panic(err) |
| 84 | } |
| 85 | allowedAddrsMap[addr] = true |
| 86 | } |
| 87 | |
| 88 | /* Handle fee distribution state. */ |
| 89 | |
| 90 | // withdraw all validator commission |
| 91 | err := app.Keepers.Cosmos.Staking.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { |
| 92 | valBz, err := app.Keepers.Cosmos.Staking.ValidatorAddressCodec().StringToBytes(val.GetOperator()) |
| 93 | if err != nil { |
| 94 | panic(err) |
| 95 | } |
| 96 | |
| 97 | _, err = app.Keepers.Cosmos.Distr.WithdrawValidatorCommission(ctx, valBz) |
| 98 | if err != nil { |
| 99 | if !errorsmod.IsOf(err, distrtypes.ErrNoValidatorCommission) { |
| 100 | panic(err) |
| 101 | } |
| 102 | } |
| 103 | return false |
| 104 | }) |
| 105 | if err != nil { |
| 106 | panic(err) |
| 107 | } |
| 108 | |
| 109 | // withdraw all delegator rewards |
| 110 | dels, err := app.Keepers.Cosmos.Staking.GetAllDelegations(ctx) |
| 111 | if err != nil { |
| 112 | panic(err) |
| 113 | } |
| 114 | |
| 115 | for _, delegation := range dels { |
| 116 | valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) |
| 117 | if err != nil { |
| 118 | panic(err) |
| 119 | } |
| 120 | |
| 121 | delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress) |
| 122 | if err != nil { |
| 123 | panic(err) |
| 124 | } |
| 125 | _, _ = app.Keepers.Cosmos.Distr.WithdrawDelegationRewards(ctx, delAddr, valAddr) |
| 126 | } |
| 127 | |
| 128 | // clear validator slash events |
| 129 | app.Keepers.Cosmos.Distr.DeleteAllValidatorSlashEvents(ctx) |
| 130 | |
| 131 | // clear validator historical rewards |