Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R4R: Support export at specific height #2792

Merged
merged 39 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7031bc8
Update PENDING.md
cwgoes Nov 9, 2018
d761eb7
Address remaining comments from #2690
cwgoes Nov 9, 2018
f9c7281
Linter fix
cwgoes Nov 9, 2018
241f636
Merge branch 'develop' into cwgoes/fix-gov-sim-more-import-export
cwgoes Nov 9, 2018
338b49b
Slight distribution spec cleanup
Nov 11, 2018
795a76d
More cleanup
Nov 11, 2018
183c7b2
use defer
jaekwon Nov 12, 2018
81ae35c
Merge branch 'develop' into cwgoes/fix-gov-sim-more-import-export
cwgoes Nov 12, 2018
2b32268
Correctly set return code
cwgoes Nov 12, 2018
d2a5353
Merge branch 'develop' into cwgoes/fix-gov-sim-more-import-export
cwgoes Nov 13, 2018
0e56ed9
Fix DiffKVStore
cwgoes Nov 13, 2018
46b331d
Address PR review
Nov 13, 2018
10713e3
Working on stake import/export
cwgoes Nov 13, 2018
3686a3f
Only apply validator set updates on initial genesis
cwgoes Nov 13, 2018
267728f
Clarify comment
cwgoes Nov 13, 2018
7cb314e
Update PENDING.md
cwgoes Nov 13, 2018
fa5622e
Export specific height
cwgoes Nov 13, 2018
737d024
Check error
cwgoes Nov 13, 2018
4a9ce8a
Update docs
cwgoes Nov 13, 2018
cb40646
Bugfix
cwgoes Nov 13, 2018
1f632e3
Merge branch 'develop' into cwgoes/export-at-height
cwgoes Nov 14, 2018
6e9c3f8
Merge PR #2744: Fix Makefile targets dependencies
alessio Nov 14, 2018
9118cd7
Update docs/spec/distribution/overview.md
rigelrozanski Nov 14, 2018
4b5be08
Update docs/spec/distribution/overview.md
rigelrozanski Nov 14, 2018
b1a1f19
Update docs/spec/distribution/overview.md
rigelrozanski Nov 14, 2018
2bff5c2
Merge PR #2748: Fix governance simulation, more import/export work
cwgoes Nov 14, 2018
bba7a30
Update overview.md
alexanderbez Nov 14, 2018
6feab55
Merge PR #2765: Slight cleanup of distribution specification
rigelrozanski Nov 14, 2018
addcfbf
Documentation Structure Change and Cleanup (#2808)
gamarin2 Nov 14, 2018
7f07e93
Bring back banner (#2814)
gamarin2 Nov 14, 2018
45b0e3a
Build docs in CircleCI (#2810)
Nov 14, 2018
0453992
Update contributing.md with new merge policy (#2789)
jackzampolin Nov 14, 2018
555b61e
deleted obsolete file (#2817)
zramsay Nov 14, 2018
2179567
Update PENDING.md
cwgoes Nov 13, 2018
17b9afa
Export specific height
cwgoes Nov 13, 2018
42402d3
Check error
cwgoes Nov 13, 2018
ac0319f
Update docs
cwgoes Nov 13, 2018
f1d5b80
Bugfix
cwgoes Nov 13, 2018
554bdfb
Merge branch 'cwgoes/export-at-height' of github.com:cosmos/cosmos-sd…
jackzampolin Nov 15, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ FEATURES
* [stake][cli] [\#2027] Add CLI query command for getting all delegations to a specific validator.

* Gaia
* [app] \#2791 Support export at a specific height, with `gaiad export --height=HEIGHT`.
* [x/gov] [#2479](https://github.com/cosmos/cosmos-sdk/issues/2479) Implemented querier
for getting governance parameters.

Expand Down
5 changes: 5 additions & 0 deletions cmd/gaia/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) error {
return app.LoadVersion(height, app.keyMain)
}

//______________________________________________________________________________________________

// Combined Staking Hooks
Expand Down
8 changes: 7 additions & 1 deletion cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,14 @@ 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 {
err := gApp.LoadHeight(height)
if err != nil {
return nil, nil, err
}
}
return gApp.ExportAppStateAndValidators()
}
15 changes: 15 additions & 0 deletions docs/getting-started/join-testnet.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely going to run to a merge conflict here (docs PR)


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

Expand Down
2 changes: 1 addition & 1 deletion examples/basecoin/cmd/basecoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/democoin/cmd/democoind/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion server/constructors.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 9 additions & 2 deletions server/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ import (
"path"
)

const (
flagHeight = "height"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed - I don't know if we want to import the client package from the server package though.

Maybe we should have a common "flags" package.

)

// 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 {
Expand Down Expand Up @@ -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)
}
Expand All @@ -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) {
Expand Down