diff --git a/CHANGELOG.md b/CHANGELOG.md index be5c97c17b6d..31c00356c15d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,17 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +<<<<<<< HEAD +======= +### Features + +### Improvements + +* (cli) [#16856](https://github.com/cosmos/cosmos-sdk/pull/16856) Improve `simd prune` UX by using the app default home directory and set pruning method as first variable argument (defaults to default). +* (all) [#16537](https://github.com/cosmos/cosmos-sdk/pull/16537) Properly propagated fmt.Errorf errors + using errors.New where appropriate. +* (x/authz) [#16869](https://github.com/cosmos/cosmos-sdk/pull/16869) Error message has been improvised in `Exec` command when grant not found. + +>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856)) ### Bug Fixes * (x/bank) [#16841](https://github.com/cosmos/cosmos-sdk/pull/16841) Correctly process legacy `DenomAddressIndex` values. diff --git a/client/pruning/main.go b/client/pruning/main.go index 850658b31897..51dc5f9c2162 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -21,41 +21,50 @@ const FlagAppDBBackend = "app-db-backend" // Cmd prunes the sdk root multi store history versions based on the pruning options // specified by command flags. -func Cmd(appCreator servertypes.AppCreator) *cobra.Command { +func Cmd(appCreator servertypes.AppCreator, defaultNodeHome string) *cobra.Command { cmd := &cobra.Command{ - Use: "prune", + Use: "prune [pruning-method]", Short: "Prune app history states by keeping the recent heights and deleting old heights", Long: `Prune app history states by keeping the recent heights and deleting old heights. - The pruning option is provided via the '--pruning' flag or alternatively with '--pruning-keep-recent' - - For '--pruning' the options are as follows: - - default: the last 362880 states are kept - nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) - everything: 2 latest states will be kept - custom: allow pruning options to be manually specified through 'pruning-keep-recent'. - besides pruning options, database home directory and database backend type should also be specified via flags - '--home' and '--app-db-backend'. - valid app-db-backend type includes 'goleveldb', 'rocksdb', 'pebbledb'. - `, - Example: "prune --home './' --app-db-backend 'goleveldb' --pruning 'custom' --pruning-keep-recent 100", - RunE: func(cmd *cobra.Command, _ []string) error { - vp := viper.New() +The pruning option is provided via the 'pruning' argument or alternatively with '--pruning-keep-recent' + +- default: the last 362880 states are kept +- nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) +- everything: 2 latest states will be kept +- custom: allow pruning options to be manually specified through 'pruning-keep-recent' - // Bind flags to the Context's Viper so we can get pruning options. +Note: When the --app-db-backend flag is not specified, the default backend type is 'goleveldb'. +Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, + Example: "prune custom --pruning-keep-recent 100 --app-db-backend 'goleveldb'", + Args: cobra.RangeArgs(0, 1), + RunE: func(cmd *cobra.Command, args []string) error { + // bind flags to the Context's Viper so we can get pruning options. + vp := viper.New() if err := vp.BindPFlags(cmd.Flags()); err != nil { return err } + + // use the first argument if present to set the pruning method + if len(args) > 0 { + vp.Set(server.FlagPruning, args[0]) + } else { + vp.Set(server.FlagPruning, pruningtypes.PruningOptionDefault) + } pruningOptions, err := server.GetPruningOptionsFromFlags(vp) if err != nil { return err } - fmt.Printf("get pruning options from command flags, strategy: %v, keep-recent: %v\n", + + cmd.Printf("get pruning options from command flags, strategy: %v, keep-recent: %v\n", pruningOptions.Strategy, pruningOptions.KeepRecent, ) home := vp.GetString(flags.FlagHome) + if home == "" { + home = defaultNodeHome + } + db, err := openDB(home, server.GetAppDBBackend(vp)) if err != nil { return err @@ -76,23 +85,20 @@ func Cmd(appCreator servertypes.AppCreator) *cobra.Command { } pruningHeight := latestHeight - int64(pruningOptions.KeepRecent) - fmt.Printf( - "pruning heights up to %v\n", - pruningHeight, - ) + cmd.Printf("pruning heights up to %v\n", pruningHeight) err = rootMultiStore.PruneStores(pruningHeight) if err != nil { return err } - fmt.Printf("successfully pruned the application root multi stores\n") + + cmd.Println("successfully pruned the application root multi stores") return nil }, } - cmd.Flags().String(flags.FlagHome, "", "The database home directory") + cmd.Flags().String(flags.FlagHome, defaultNodeHome, "The application home directory") cmd.Flags().String(FlagAppDBBackend, "", "The type of database for application and snapshots databases") - cmd.Flags().String(server.FlagPruning, pruningtypes.PruningOptionDefault, "Pruning strategy (default|nothing|everything|custom)") cmd.Flags().Uint64(server.FlagPruningKeepRecent, 0, "Number of recent heights to keep on disk (ignored if pruning is not 'custom')") cmd.Flags().Uint64(server.FlagPruningInterval, 10, `Height interval at which pruned heights are removed from disk (ignored if pruning is not 'custom'), diff --git a/simapp/simd/cmd/root.go b/simapp/simd/cmd/root.go index ea75692e92ff..6d2cfc34e3b2 100644 --- a/simapp/simd/cmd/root.go +++ b/simapp/simd/cmd/root.go @@ -198,7 +198,7 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig, b NewTestnetCmd(basicManager, banktypes.GenesisBalancesIterator{}), debug.Cmd(), confixcmd.ConfigCommand(), - pruning.Cmd(newApp), + pruning.Cmd(newApp, simapp.DefaultNodeHome), snapshot.Cmd(newApp), ) diff --git a/simapp/simd/cmd/root_v2.go b/simapp/simd/cmd/root_v2.go index 99b99640b87d..c7fad78a06de 100644 --- a/simapp/simd/cmd/root_v2.go +++ b/simapp/simd/cmd/root_v2.go @@ -214,7 +214,7 @@ func initRootCmd( NewTestnetCmd(basicManager, banktypes.GenesisBalancesIterator{}), debug.Cmd(), confixcmd.ConfigCommand(), - pruning.Cmd(newApp), + pruning.Cmd(newApp, simapp.DefaultNodeHome), snapshot.Cmd(newApp), )