From 7cb314ec0197a9b23a2330745ebeb00a0dfe84a8 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 13 Nov 2018 15:55:22 +0100 Subject: [PATCH 1/5] Update PENDING.md --- PENDING.md | 1 + 1 file changed, 1 insertion(+) diff --git a/PENDING.md b/PENDING.md index 11179d170a..8c002af058 100644 --- a/PENDING.md +++ b/PENDING.md @@ -23,6 +23,7 @@ FEATURES * Gaia CLI (`gaiacli`) * Gaia + * [app] \#2791 Support export at a specific height, with `gaiad export --height=HEIGHT`. * SDK * [simulator] \#2682 MsgEditValidator now looks at the validator's max rate, thus it now succeeds a significant portion of the time From fa5622e0721c178060803a8340372e1c279bf389 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 13 Nov 2018 16:14:09 +0100 Subject: [PATCH 2/5] Export specific height --- cmd/gaia/app/app.go | 5 +++++ cmd/gaia/cmd/gaiad/main.go | 5 ++++- examples/basecoin/cmd/basecoind/main.go | 2 +- examples/democoin/cmd/democoind/main.go | 2 +- server/constructors.go | 2 +- server/export.go | 11 +++++++++-- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 918bfc67d1..45c99a9567 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -322,6 +322,11 @@ func (app *GaiaApp) ExportAppStateAndValidators() (appState json.RawMessage, val return appState, validators, nil } +// load a particular height +func (app *GaiaApp) LoadHeight(height int64) { + app.LoadVersion(height, app.keyMain) +} + //______________________________________________________________________________________________ // Combined Staking Hooks diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index ef7b39d111..7a0fca31b2 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -64,8 +64,11 @@ func newApp(logger log.Logger, db dbm.DB, traceStore io.Writer) abci.Application } func exportAppStateAndTMValidators( - logger log.Logger, db dbm.DB, traceStore io.Writer, + logger log.Logger, db dbm.DB, traceStore io.Writer, height int64, ) (json.RawMessage, []tmtypes.GenesisValidator, error) { gApp := app.NewGaiaApp(logger, db, traceStore) + if height != -1 { + gApp.LoadHeight(height) + } return gApp.ExportAppStateAndValidators() } diff --git a/examples/basecoin/cmd/basecoind/main.go b/examples/basecoin/cmd/basecoind/main.go index f07fbd3ff2..1b47fe1f6d 100644 --- a/examples/basecoin/cmd/basecoind/main.go +++ b/examples/basecoin/cmd/basecoind/main.go @@ -126,7 +126,7 @@ func newApp(logger log.Logger, db dbm.DB, storeTracer io.Writer) abci.Applicatio return app.NewBasecoinApp(logger, db, baseapp.SetPruning(viper.GetString("pruning"))) } -func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, storeTracer io.Writer) ( +func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, storeTracer io.Writer, _ int64) ( json.RawMessage, []tmtypes.GenesisValidator, error) { bapp := app.NewBasecoinApp(logger, db) return bapp.ExportAppStateAndValidators() diff --git a/examples/democoin/cmd/democoind/main.go b/examples/democoin/cmd/democoind/main.go index d095b4c790..912f69f0cb 100644 --- a/examples/democoin/cmd/democoind/main.go +++ b/examples/democoin/cmd/democoind/main.go @@ -133,7 +133,7 @@ func newApp(logger log.Logger, db dbm.DB, _ io.Writer) abci.Application { return app.NewDemocoinApp(logger, db) } -func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, _ io.Writer) ( +func exportAppStateAndTMValidators(logger log.Logger, db dbm.DB, _ io.Writer, _ int64) ( json.RawMessage, []tmtypes.GenesisValidator, error) { dapp := app.NewDemocoinApp(logger, db) return dapp.ExportAppStateAndValidators() diff --git a/server/constructors.go b/server/constructors.go index 57282e43b1..9039d8a81d 100644 --- a/server/constructors.go +++ b/server/constructors.go @@ -19,7 +19,7 @@ type ( // AppExporter is a function that dumps all app state to // JSON-serializable structure and returns the current validator set. - AppExporter func(log.Logger, dbm.DB, io.Writer) (json.RawMessage, []tmtypes.GenesisValidator, error) + AppExporter func(log.Logger, dbm.DB, io.Writer, int64) (json.RawMessage, []tmtypes.GenesisValidator, error) ) func openDB(rootDir string) (dbm.DB, error) { diff --git a/server/export.go b/server/export.go index 43ea10866e..fbe52eef6d 100644 --- a/server/export.go +++ b/server/export.go @@ -13,9 +13,13 @@ import ( "path" ) +const ( + flagHeight = "height" +) + // ExportCmd dumps app state to JSON. func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.Command { - return &cobra.Command{ + cmd := &cobra.Command{ Use: "export", Short: "Export state to JSON", RunE: func(cmd *cobra.Command, args []string) error { @@ -45,7 +49,8 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C if err != nil { return err } - appState, validators, err := appExporter(ctx.Logger, db, traceWriter) + height := viper.GetInt64(flagHeight) + appState, validators, err := appExporter(ctx.Logger, db, traceWriter, height) if err != nil { return errors.Errorf("error exporting state: %v\n", err) } @@ -67,6 +72,8 @@ func ExportCmd(ctx *Context, cdc *codec.Codec, appExporter AppExporter) *cobra.C return nil }, } + cmd.Flags().Int64(flagHeight, -1, "Export state from a particular height (-1 means latest height)") + return cmd } func isEmptyState(home string) (bool, error) { From 737d0247774c9255d718a5aa7e9f14cc6ece0653 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 13 Nov 2018 16:17:40 +0100 Subject: [PATCH 3/5] Check error --- cmd/gaia/app/app.go | 4 ++-- cmd/gaia/cmd/gaiad/main.go | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cmd/gaia/app/app.go b/cmd/gaia/app/app.go index 45c99a9567..19a58bdb26 100644 --- a/cmd/gaia/app/app.go +++ b/cmd/gaia/app/app.go @@ -323,8 +323,8 @@ func (app *GaiaApp) ExportAppStateAndValidators() (appState json.RawMessage, val } // load a particular height -func (app *GaiaApp) LoadHeight(height int64) { - app.LoadVersion(height, app.keyMain) +func (app *GaiaApp) LoadHeight(height int64) error { + return app.LoadVersion(height, app.keyMain) } //______________________________________________________________________________________________ diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index 7a0fca31b2..d2385fe938 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -68,7 +68,10 @@ func exportAppStateAndTMValidators( ) (json.RawMessage, []tmtypes.GenesisValidator, error) { gApp := app.NewGaiaApp(logger, db, traceStore) if height != -1 { - gApp.LoadHeight(height) + err := gApp.LoadHeight(height) + if err != nil { + return err + } } return gApp.ExportAppStateAndValidators() } From 4a9ce8a5dff38a14c3ef3a180e00ac03a6fa4036 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 13 Nov 2018 16:22:06 +0100 Subject: [PATCH 4/5] Update docs --- docs/getting-started/join-testnet.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/getting-started/join-testnet.md b/docs/getting-started/join-testnet.md index ce070c4fe9..1e32846555 100644 --- a/docs/getting-started/join-testnet.md +++ b/docs/getting-started/join-testnet.md @@ -127,6 +127,21 @@ gaiacli status View the status of the network with the [Cosmos Explorer](https://explorecosmos.network). Once your full node syncs up to the current block height, you should see it appear on the [list of full nodes](https://explorecosmos.network/validators). If it doesn't show up, that's ok--the Explorer does not connect to every node. +## Export State + +Gaia can dump the entire application state to a JSON file, which could be useful for manual analysis and can also be used as the genesis file of a new network. + +Export state with: + +```bash +gaiad export > [filename].json +``` + +You can also export state from a particular height (at the end of processing the block of that height): + +```bash +gaiad export --height=[height] > [filename].json +``` ## Upgrade to Validator Node From cb40646bc8f52d8a817bd1f87c021a588324dab7 Mon Sep 17 00:00:00 2001 From: Christopher Goes Date: Tue, 13 Nov 2018 16:23:01 +0100 Subject: [PATCH 5/5] Bugfix --- cmd/gaia/cmd/gaiad/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/gaia/cmd/gaiad/main.go b/cmd/gaia/cmd/gaiad/main.go index d2385fe938..2a72b42cc6 100644 --- a/cmd/gaia/cmd/gaiad/main.go +++ b/cmd/gaia/cmd/gaiad/main.go @@ -70,7 +70,7 @@ func exportAppStateAndTMValidators( if height != -1 { err := gApp.LoadHeight(height) if err != nil { - return err + return nil, nil, err } } return gApp.ExportAppStateAndValidators()