Skip to content

Commit

Permalink
Export for zero height fixes (#3183)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes authored and jackzampolin committed Dec 20, 2018
1 parent 131ad37 commit feff014
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ BUG FIXES

* Gaia
* \#3148 Fix `gaiad export` by adding a boolean to `NewGaiaApp` determining whether or not to load the latest version
* \#3181 Correctly reset total accum update height and jailed-validator bond height / unbonding height on export-for-zero-height
* [\#3172](https://github.com/cosmos/cosmos-sdk/pull/3172) Fix parsing `gaiad.toml`
when it already exists.

Expand Down
19 changes: 17 additions & 2 deletions cmd/gaia/app/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {
})
app.distrKeeper.IterateValidatorDistInfos(ctx, func(_ int64, valInfo distr.ValidatorDistInfo) (stop bool) {
valInfo.FeePoolWithdrawalHeight = 0
valInfo.DelAccum.UpdateHeight = 0
app.distrKeeper.SetValidatorDistInfo(ctx, valInfo)
return false
})
Expand All @@ -113,12 +114,26 @@ func (app *GaiaApp) prepForZeroHeightGenesis(ctx sdk.Context) {

/* Handle stake state. */

// iterate through redelegations, reset creation height
app.stakeKeeper.IterateRedelegations(ctx, func(_ int64, red stake.Redelegation) (stop bool) {
red.CreationHeight = 0
app.stakeKeeper.SetRedelegation(ctx, red)
return false
})

// iterate through unbonding delegations, reset creation height
app.stakeKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stake.UnbondingDelegation) (stop bool) {
ubd.CreationHeight = 0
app.stakeKeeper.SetUnbondingDelegation(ctx, ubd)
return false
})

// iterate through validators by power descending, reset bond height, update bond intra-tx counter
store := ctx.KVStore(app.keyStake)
iter := sdk.KVStoreReversePrefixIterator(store, stake.ValidatorsByPowerIndexKey)
iter := sdk.KVStoreReversePrefixIterator(store, stake.ValidatorsKey)
counter := int16(0)
for ; iter.Valid(); iter.Next() {
addr := sdk.ValAddress(iter.Value())
addr := sdk.ValAddress(iter.Key()[1:])
validator, found := app.stakeKeeper.GetValidator(ctx, addr)
if !found {
panic("expected validator, not found")
Expand Down

0 comments on commit feff014

Please sign in to comment.