From c2756102838db665a2f4a3f269a85e193d0200ec Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Sun, 4 Dec 2022 12:05:28 -0800 Subject: [PATCH 1/2] Allow state exporting from any directory (#3608) * Allow exporting from any directory * Changelog (cherry picked from commit da4f503864ce427ab24dd58130164d299a75f4d3) # Conflicts: # CHANGELOG.md # app/export.go --- CHANGELOG.md | 17 +++++++++++++++++ app/export.go | 12 +++++++----- cmd/osmosisd/cmd/root.go | 9 ++++----- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f875ca6b63..ef71d1853fe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,7 +42,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## v12.3.0 +<<<<<<< HEAD * [#3325](https://github.com/osmosis-labs/osmosis/pull/3325) Use mainline iavl v0.19.4 instead of our iavl fork +======= +### Features + +* [#2788](https://github.com/osmosis-labs/osmosis/pull/2788) Add logarithm base 2 implementation. + +### Bug fixes + +* [#3608](https://github.com/osmosis-labs/osmosis/pull/3608) Make it possible to state export from any directory. + +### Misc Improvements + + +## v13.0.0 + +This release includes stableswap, and expands the IBC safety & composability functionality of Osmosis. The primary features are: +>>>>>>> da4f5038 (Allow state exporting from any directory (#3608)) ## v12.2.1 diff --git a/app/export.go b/app/export.go index 248ac0156b4..3848a422c6d 100644 --- a/app/export.go +++ b/app/export.go @@ -2,15 +2,13 @@ package app import ( "encoding/json" - "log" + "fmt" tmproto "github.com/tendermint/tendermint/proto/tendermint/types" servertypes "github.com/cosmos/cosmos-sdk/server/types" sdk "github.com/cosmos/cosmos-sdk/types" - slashingtypes "github.com/cosmos/cosmos-sdk/x/slashing/types" "github.com/cosmos/cosmos-sdk/x/staking" - stakingtypes "github.com/cosmos/cosmos-sdk/x/staking/types" ) // ExportAppStateAndValidators exports the state of the application for a genesis @@ -25,8 +23,7 @@ func (app *OsmosisApp) ExportAppStateAndValidators( // Tendermint will start InitChain. height := app.LastBlockHeight() + 1 if forZeroHeight { - height = 0 - app.prepForZeroHeightGenesis(ctx, jailAllowedAddrs) + return servertypes.ExportedApp{}, fmt.Errorf("forZeroHeight not supported") } genState := app.mm.ExportGenesis(ctx, app.AppCodec(), modulesToExport) @@ -44,6 +41,7 @@ func (app *OsmosisApp) ExportAppStateAndValidators( }, err } +<<<<<<< HEAD // prepare for fresh start at zero height // NOTE zero height genesis is a temporary feature which will be deprecated // @@ -194,4 +192,8 @@ func (app *OsmosisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddr return false }, ) +======= +func (app *OsmosisApp) ExportState(ctx sdk.Context) map[string]json.RawMessage { + return app.mm.ExportGenesis(ctx, app.AppCodec()) +>>>>>>> da4f5038 (Allow state exporting from any directory (#3608)) } diff --git a/cmd/osmosisd/cmd/root.go b/cmd/osmosisd/cmd/root.go index 112894f7bae..38d37e3e3a8 100644 --- a/cmd/osmosisd/cmd/root.go +++ b/cmd/osmosisd/cmd/root.go @@ -293,15 +293,14 @@ func createOsmosisAppAndExport( ) (servertypes.ExportedApp, error) { encCfg := osmosis.MakeEncodingConfig() // Ideally, we would reuse the one created by NewRootCmd. encCfg.Marshaler = codec.NewProtoCodec(encCfg.InterfaceRegistry) - var app *osmosis.OsmosisApp - if height != -1 { - app = osmosis.NewOsmosisApp(logger, db, traceStore, false, map[int64]bool{}, "", uint(1), appOpts, osmosis.GetWasmEnabledProposals(), osmosis.EmptyWasmOpts) + loadLatest := height == -1 + homeDir := cast.ToString(appOpts.Get(flags.FlagHome)) + app := osmosis.NewOsmosisApp(logger, db, traceStore, loadLatest, map[int64]bool{}, homeDir, 0, appOpts, osmosis.GetWasmEnabledProposals(), osmosis.EmptyWasmOpts) + if !loadLatest { if err := app.LoadHeight(height); err != nil { return servertypes.ExportedApp{}, err } - } else { - app = osmosis.NewOsmosisApp(logger, db, traceStore, true, map[int64]bool{}, "", uint(1), appOpts, osmosis.GetWasmEnabledProposals(), osmosis.EmptyWasmOpts) } return app.ExportAppStateAndValidators(forZeroHeight, jailWhiteList, modulesToExport) From 67449898271dd08da9fb578a38207ce0253f6722 Mon Sep 17 00:00:00 2001 From: Dev Ojha Date: Mon, 5 Dec 2022 17:23:00 -0600 Subject: [PATCH 2/2] Fix conflicts --- CHANGELOG.md | 19 +------ app/export.go | 155 +------------------------------------------------- 2 files changed, 4 insertions(+), 170 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ef71d1853fe..60f294d12bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,26 +40,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## v12.3.0 - -<<<<<<< HEAD -* [#3325](https://github.com/osmosis-labs/osmosis/pull/3325) Use mainline iavl v0.19.4 instead of our iavl fork -======= -### Features - -* [#2788](https://github.com/osmosis-labs/osmosis/pull/2788) Add logarithm base 2 implementation. - -### Bug fixes +## Bug Fixes * [#3608](https://github.com/osmosis-labs/osmosis/pull/3608) Make it possible to state export from any directory. -### Misc Improvements - - -## v13.0.0 +## v12.3.0 -This release includes stableswap, and expands the IBC safety & composability functionality of Osmosis. The primary features are: ->>>>>>> da4f5038 (Allow state exporting from any directory (#3608)) +* [#3325](https://github.com/osmosis-labs/osmosis/pull/3325) Use mainline iavl v0.19.4 instead of our iavl fork ## v12.2.1 diff --git a/app/export.go b/app/export.go index 3848a422c6d..4efb9b49321 100644 --- a/app/export.go +++ b/app/export.go @@ -41,159 +41,6 @@ func (app *OsmosisApp) ExportAppStateAndValidators( }, err } -<<<<<<< HEAD -// 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 -func (app *OsmosisApp) prepForZeroHeightGenesis(ctx sdk.Context, jailAllowedAddrs []string) { - applyAllowedAddrs := false - - // check if there is a allowed address list - if len(jailAllowedAddrs) > 0 { - applyAllowedAddrs = true - } - - allowedAddrsMap := make(map[string]bool) - - for _, addr := range jailAllowedAddrs { - _, err := sdk.ValAddressFromBech32(addr) - if err != nil { - log.Fatal(err) - } - allowedAddrsMap[addr] = true - } - - /* Just to be safe, assert the invariants on current state. */ - app.CrisisKeeper.AssertInvariants(ctx) - - /* Handle fee distribution state. */ - - // withdraw all validator commission - app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - _, _ = app.DistrKeeper.WithdrawValidatorCommission(ctx, val.GetOperator()) - return false - }) - - // withdraw all delegator rewards - dels := app.StakingKeeper.GetAllDelegations(ctx) - for _, delegation := range dels { - valAddr, err := sdk.ValAddressFromBech32(delegation.ValidatorAddress) - if err != nil { - panic(err) - } - - delAddr, err := sdk.AccAddressFromBech32(delegation.DelegatorAddress) - if err != nil { - panic(err) - } - _, _ = app.DistrKeeper.WithdrawDelegationRewards(ctx, delAddr, valAddr) - } - - // clear validator slash events - app.DistrKeeper.DeleteAllValidatorSlashEvents(ctx) - - // clear validator historical rewards - app.DistrKeeper.DeleteAllValidatorHistoricalRewards(ctx) - - // set context height to zero - height := ctx.BlockHeight() - ctx = ctx.WithBlockHeight(0) - - // reinitialize all validators - app.StakingKeeper.IterateValidators(ctx, func(_ int64, val stakingtypes.ValidatorI) (stop bool) { - // donate any unwithdrawn outstanding reward fraction tokens to the community pool - scraps := app.DistrKeeper.GetValidatorOutstandingRewardsCoins(ctx, val.GetOperator()) - feePool := app.DistrKeeper.GetFeePool(ctx) - feePool.CommunityPool = feePool.CommunityPool.Add(scraps...) - app.DistrKeeper.SetFeePool(ctx, feePool) - - app.DistrKeeper.Hooks().AfterValidatorCreated(ctx, val.GetOperator()) - return false - }) - - // reinitialize all delegations - for _, del := range dels { - valAddr, err := sdk.ValAddressFromBech32(del.ValidatorAddress) - if err != nil { - panic(err) - } - delAddr, err := sdk.AccAddressFromBech32(del.DelegatorAddress) - if err != nil { - panic(err) - } - app.DistrKeeper.Hooks().BeforeDelegationCreated(ctx, delAddr, valAddr) - app.DistrKeeper.Hooks().AfterDelegationModified(ctx, delAddr, valAddr) - } - - // reset context height - ctx = ctx.WithBlockHeight(height) - - /* Handle staking state. */ - - // iterate through redelegations, reset creation height - app.StakingKeeper.IterateRedelegations(ctx, func(_ int64, red stakingtypes.Redelegation) (stop bool) { - for i := range red.Entries { - red.Entries[i].CreationHeight = 0 - } - app.StakingKeeper.SetRedelegation(ctx, red) - return false - }) - - // iterate through unbonding delegations, reset creation height - app.StakingKeeper.IterateUnbondingDelegations(ctx, func(_ int64, ubd stakingtypes.UnbondingDelegation) (stop bool) { - for i := range ubd.Entries { - ubd.Entries[i].CreationHeight = 0 - } - app.StakingKeeper.SetUnbondingDelegation(ctx, ubd) - return false - }) - - // Iterate through validators by power descending, reset bond heights, and - // update bond intra-tx counters. - store := ctx.KVStore(app.GetKey(stakingtypes.StoreKey)) - iter := sdk.KVStoreReversePrefixIterator(store, stakingtypes.ValidatorsKey) - counter := int16(0) - - for ; iter.Valid(); iter.Next() { - addr := sdk.ValAddress(iter.Key()[1:]) - validator, found := app.StakingKeeper.GetValidator(ctx, addr) - if !found { - panic("expected validator, not found") - } - - validator.UnbondingHeight = 0 - if applyAllowedAddrs && !allowedAddrsMap[addr.String()] { - validator.Jailed = true - } - - app.StakingKeeper.SetValidator(ctx, validator) - counter++ - } - - err := iter.Close() - if err != nil { - log.Fatal(err) - } - - _, err = app.StakingKeeper.ApplyAndReturnValidatorSetUpdates(ctx) - if err != nil { - log.Fatal(err) - } - - /* Handle slashing state. */ - - // reset start height on signing infos - app.SlashingKeeper.IterateValidatorSigningInfos( - ctx, - func(addr sdk.ConsAddress, info slashingtypes.ValidatorSigningInfo) (stop bool) { - info.StartHeight = 0 - app.SlashingKeeper.SetValidatorSigningInfo(ctx, addr, info) - return false - }, - ) -======= func (app *OsmosisApp) ExportState(ctx sdk.Context) map[string]json.RawMessage { - return app.mm.ExportGenesis(ctx, app.AppCodec()) ->>>>>>> da4f5038 (Allow state exporting from any directory (#3608)) + return app.mm.ExportGenesis(ctx, app.AppCodec(), []string{}) }