MCPcopy Create free account
hub / github.com/Sifchain/sifnode / prepForZeroHeightGenesis

Method prepForZeroHeightGenesis

app/export.go:53–192  ·  view source on GitHub ↗

prepare for fresh start at zero height NOTE zero height genesis is a temporary feature which will be deprecated in favour of export at a block height

(ctx sdk.Context, jailWhiteList []string)

Source from the content-addressed store, hash-verified

51// NOTE zero height genesis is a temporary feature which will be deprecated
52// in favour of export at a block height
53func (app *SifchainApp) prepForZeroHeightGenesis(ctx sdk.Context, jailWhiteList []string) {
54 applyWhiteList := false
55
56 //Check if there is a whitelist
57 if len(jailWhiteList) > 0 {
58 applyWhiteList = true
59 }
60
61 whiteListMap := make(map[string]bool)
62
63 for _, addr := range jailWhiteList {
64 _, err := sdk.ValAddressFromBech32(addr)
65 if err != nil {
66 log.Fatal(err)
67 }
68 whiteListMap[addr] = true
69 }
70
71 /* Handle fee distribution state. */
72
73 // withdraw all validator commission
74 app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
75 _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator())
76 return false
77 })
78
79 // withdraw all delegator rewards
80 dels := app.StakingKeeper.GetAllDelegations(ctx)
81 for _, delegation := range dels {
82 valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress)
83 if err != nil {
84 panic(err)
85 }
86
87 delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress)
88 if err != nil {
89 panic(err)
90 }
91
92 _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr)
93 }
94
95 // clear validator slash events
96 app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx)
97
98 // clear validator historical rewards
99 app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx)
100
101 // set context height to zero
102 height := ctx.BlockHeight()
103 ctx = ctx.WithBlockHeight(0)
104
105 // reinitialize all validators
106 app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) {
107
108 // donate any unwithdrawn outstanding reward fraction tokens to the community pool
109 scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator())
110 feePool := app.DistrKeeper.GetFeePool(ctx)

Callers 1

Calls 6

AddMethod · 0.80
HooksMethod · 0.80
GetValidatorMethod · 0.65
CloseMethod · 0.65
NextMethod · 0.45
StringMethod · 0.45

Tested by

no test coverage detected