Skip to content

Commit

Permalink
Export specific height
Browse files Browse the repository at this point in the history
  • Loading branch information
cwgoes committed Nov 13, 2018
1 parent 7cb314e commit fa5622e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 6 deletions.
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) {
app.LoadVersion(height, app.keyMain)
}

//______________________________________________________________________________________________

// Combined Staking Hooks
Expand Down
5 changes: 4 additions & 1 deletion cmd/gaia/cmd/gaiad/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
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"
)

// 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

0 comments on commit fa5622e

Please sign in to comment.