* [10948]: Add changelog entry. * [10948]: Deprecate the types.DBBackend variable and the NewLevelDB function. Create a NewDB function to replace them. * [10948]: Add a DBBackend string to the simulation config and a flag for setting it. Update the simulation setup to use that instead of the compile-time DBBackend variable. * [10948]: Update the mock app creator to use the NewDB function. Not sure what to do about the db backend in that case though. * [10948]: Update changelog to reflect new db-backend field name. * [10948]: Use the tendermint db-backend type for the snapshot db. * [10948]: Update the last use of NewLevelDB by adding a parameter to openDB and uppdating calls to that to provide the db type to use. * [10948]: Upddate the NewDB function to also have a default db backend type if an empty string is provided there. * [10948]: Remove the new TODO in mock.NewApp. After looking through it's uses, there doesn't seem to be any desire to change it, and there's no easy way to communicate it. * [10948]: Enhance the NewDB defer function to also add info to any err that is being returned. * [10948]: Add some unit tests for NewDB. * [10948]: Lint fixes. * [10948]: Add a changelog entry to the deprecated section. * [10948]: Update the makefile to no longer set the types.DBBackend value. * [10948]: Use memdb for the mock app instead of goleveldb. I know it was a goleveldb before, but for a mock app, a memdb feels like a better choice (assuming 'mock' and 'mem' mean what I assume they mean). * [10948]: Fix the store benchmark tests (had some index-out-of-range issues). * [10948]: Fix cachekv store bench test calling iter.Key() before checking iter.Valid(). * [10948]: Remove the panic recovery from types.NewDB since dbm.NewDB returns an error now (it didn't originally, when NewLevelDB was first written). * [10948]: Add changlog entry indicationg an API breaking change due to the DBBackend change. * [10948]: Get rid of the types.NewDB function in favor of just using the tm-db version of it. * [10948]: Fix Update the codeql-analysis github action to use go v1.17. * [10948]: Add config file option for the app db backend type. * [10948]: Adjust the comment on the app-db-backend config entry to clarify fallback behavior. * [10948]: Add a default of GoLevelDBBackend to GetAppDBBackend. The old DBBackend variable defaulted to that, and some unit tests assume that behavior still exists. * [10948]: Add the missing quotes around the app-db-backend value. * [10948]: Small tweak to the changelog's deprecated entry. * Add the go version declaration back into the codeql-analysis github action. * [10948]: Update new use of openDB. * [10948]: Put a brief delay after closing the test network. Hopefully that helps with address-in-use and non-empty directory errors. Co-authored-by: Marko <marbar3778@yahoo.com>
117 lines
3.4 KiB
Go
117 lines
3.4 KiB
Go
package server
|
|
|
|
// DONTCOVER
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
|
|
"github.com/spf13/cobra"
|
|
tmjson "github.com/tendermint/tendermint/libs/json"
|
|
tmtypes "github.com/tendermint/tendermint/types"
|
|
|
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
|
"github.com/cosmos/cosmos-sdk/server/types"
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
|
)
|
|
|
|
const (
|
|
FlagHeight = "height"
|
|
FlagForZeroHeight = "for-zero-height"
|
|
FlagJailAllowedAddrs = "jail-allowed-addrs"
|
|
)
|
|
|
|
// ExportCmd dumps app state to JSON.
|
|
func ExportCmd(appExporter types.AppExporter, defaultNodeHome string) *cobra.Command {
|
|
cmd := &cobra.Command{
|
|
Use: "export",
|
|
Short: "Export state to JSON",
|
|
RunE: func(cmd *cobra.Command, args []string) error {
|
|
serverCtx := GetServerContextFromCmd(cmd)
|
|
config := serverCtx.Config
|
|
|
|
homeDir, _ := cmd.Flags().GetString(flags.FlagHome)
|
|
config.SetRoot(homeDir)
|
|
|
|
if _, err := os.Stat(config.GenesisFile()); os.IsNotExist(err) {
|
|
return err
|
|
}
|
|
|
|
db, err := openDB(config.RootDir, GetAppDBBackend(serverCtx.Viper))
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
if appExporter == nil {
|
|
if _, err := fmt.Fprintln(os.Stderr, "WARNING: App exporter not defined. Returning genesis file."); err != nil {
|
|
return err
|
|
}
|
|
|
|
genesis, err := os.ReadFile(config.GenesisFile())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
fmt.Println(string(genesis))
|
|
return nil
|
|
}
|
|
|
|
traceWriterFile, _ := cmd.Flags().GetString(flagTraceStore)
|
|
traceWriter, err := openTraceWriter(traceWriterFile)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
height, _ := cmd.Flags().GetInt64(FlagHeight)
|
|
forZeroHeight, _ := cmd.Flags().GetBool(FlagForZeroHeight)
|
|
jailAllowedAddrs, _ := cmd.Flags().GetStringSlice(FlagJailAllowedAddrs)
|
|
|
|
exported, err := appExporter(serverCtx.Logger, db, traceWriter, height, forZeroHeight, jailAllowedAddrs, serverCtx.Viper)
|
|
if err != nil {
|
|
return fmt.Errorf("error exporting state: %v", err)
|
|
}
|
|
|
|
doc, err := tmtypes.GenesisDocFromFile(serverCtx.Config.GenesisFile())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
doc.AppState = exported.AppState
|
|
doc.Validators = exported.Validators
|
|
doc.InitialHeight = exported.Height
|
|
doc.ConsensusParams = &tmtypes.ConsensusParams{
|
|
Block: tmtypes.BlockParams{
|
|
MaxBytes: exported.ConsensusParams.Block.MaxBytes,
|
|
MaxGas: exported.ConsensusParams.Block.MaxGas,
|
|
},
|
|
Evidence: tmtypes.EvidenceParams{
|
|
MaxAgeNumBlocks: exported.ConsensusParams.Evidence.MaxAgeNumBlocks,
|
|
MaxAgeDuration: exported.ConsensusParams.Evidence.MaxAgeDuration,
|
|
MaxBytes: exported.ConsensusParams.Evidence.MaxBytes,
|
|
},
|
|
Validator: tmtypes.ValidatorParams{
|
|
PubKeyTypes: exported.ConsensusParams.Validator.PubKeyTypes,
|
|
},
|
|
}
|
|
|
|
// NOTE: Tendermint uses a custom JSON decoder for GenesisDoc
|
|
// (except for stuff inside AppState). Inside AppState, we're free
|
|
// to encode as protobuf or amino.
|
|
encoded, err := tmjson.Marshal(doc)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
cmd.Println(string(sdk.MustSortJSON(encoded)))
|
|
return nil
|
|
},
|
|
}
|
|
|
|
cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory")
|
|
cmd.Flags().Int64(FlagHeight, -1, "Export state from a particular height (-1 means latest height)")
|
|
cmd.Flags().Bool(FlagForZeroHeight, false, "Export state to start at height zero (perform preproccessing)")
|
|
cmd.Flags().StringSlice(FlagJailAllowedAddrs, []string{}, "Comma-separated list of operator addresses of jailed validators to unjail")
|
|
|
|
return cmd
|
|
}
|