From feff014df1504a8bc320719749bc9a29823b616c Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Thu, 20 Dec 2018 21:40:27 +0100 Subject: [PATCH] Export for zero height fixes (#3183) --- PENDING.md | 1 + cmd/gaia/app/export.go | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/PENDING.md b/PENDING.md index c3674bdfce..623dba04f1 100644 --- a/PENDING.md +++ b/PENDING.md @@ -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. diff --git a/cmd/gaia/app/export.go b/cmd/gaia/app/export.go index f2f751b528..9be094a75f 100644 --- a/cmd/gaia/app/export.go +++ b/cmd/gaia/app/export.go @@ -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 }) @@ -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")