Skip to content

Commit

Permalink
fix(cli): improve prune command ux (#16856)
Browse files Browse the repository at this point in the history
(cherry picked from commit 317fb0b)

# Conflicts:
#	CHANGELOG.md
#	client/pruning/main.go
#	simapp/simd/cmd/root.go
#	simapp/simd/cmd/root_v2.go
  • Loading branch information
julienrbrt authored and mergify[bot] committed Jul 7, 2023
1 parent b39cdb2 commit 60f98a7
Show file tree
Hide file tree
Showing 4 changed files with 435 additions and 6 deletions.
37 changes: 37 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,43 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Features

<<<<<<< HEAD
=======
### 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.

### Bug Fixes

* (server) [#16827](https://github.com/cosmos/cosmos-sdk/pull/16827) Properly use `--trace` flag (before it was setting the trace level instead of displaying the stacktraces).
* (x/bank) [#16841](https://github.com/cosmos/cosmos-sdk/pull/16841) correctly process legacy `DenomAddressIndex` values.

### API Breaking Changes

* (types/math) [#16040](https://github.com/cosmos/cosmos-sdk/pull/16798) Remove aliases in `types/math.go` (part 2).
* (x/distribution) [#16440](https://github.com/cosmos/cosmos-sdk/pull/16440) use collections for `DelegatorWithdrawAddresState`:
* remove `Keeper`: `SetDelegatorWithdrawAddr`, `DeleteDelegatorWithdrawAddr`, `IterateDelegatorWithdrawAddrs`.
* (x/distribution) [#16459](https://github.com/cosmos/cosmos-sdk/pull/16459) use collections for `ValidatorCurrentRewards` state management:
* remove `Keeper`: `IterateValidatorCurrentRewards`, `GetValidatorCurrentRewards`, `SetValidatorCurrentRewards`, `DeleteValidatorCurrentRewards`
* (x/authz) [#16509](https://github.com/cosmos/cosmos-sdk/pull/16509) `AcceptResponse` has been moved to sdk/types/authz and the `Updated` field is now of the type `sdk.Msg` instead of `authz.Authorization`.
* (x/distribution) [#16483](https://github.com/cosmos/cosmos-sdk/pull/16483) use collections for `DelegatorStartingInfo` state management:
* remove `Keeper`: `IterateDelegatorStartingInfo`, `GetDelegatorStartingInfo`, `SetDelegatorStartingInfo`, `DeleteDelegatorStartingInfo`, `HasDelegatorStartingInfo`
* (x/distribution) [#16571](https://github.com/cosmos/cosmos-sdk/pull/16571) use collections for `ValidatorAccumulatedCommission` state management:
* remove `Keeper`: `IterateValidatorAccumulatedCommission`, `GetValidatorAccumulatedCommission`, `SetValidatorAccumulatedCommission`, `DeleteValidatorAccumulatedCommission`
* (x/distribution) [#16590](https://github.com/cosmos/cosmos-sdk/pull/16590) use collections for `ValidatorOutstandingRewards` state management:
* remove `Keeper`: `IterateValidatorOutstandingRewards`, `GetValidatorOutstandingRewards`, `SetValidatorOutstandingRewards`, `DeleteValidatorOutstandingRewards`
* (x/distribution) [#16607](https://github.com/cosmos/cosmos-sdk/pull/16607) use collections for `ValidatorHistoricalRewards` state management:
* remove `Keeper`: `IterateValidatorHistoricalRewards`, `GetValidatorHistoricalRewards`, `SetValidatorHistoricalRewards`, `DeleteValidatorHistoricalRewards`, `DeleteValidatorHistoricalReward`, `DeleteAllValidatorHistoricalRewards`
* (x/staking) [#16795](https://github.com/cosmos/cosmos-sdk/pull/16795) `DelegationToDelegationResponse`, `DelegationsToDelegationResponses`, `RedelegationsToRedelegationResponses` are no longer exported.
* [#16441](https://github.com/cosmos/cosmos-sdk/pull/16441) Params state is migrated to collections. `GetParams` has been removed

## [v0.50.0-alpha.1](https://github.com/cosmos/cosmos-sdk/releases/tag/v0.50.0-alpha.1) - 2023-06-30

### Features

>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856))
* (sims) [#16656](https://github.com/cosmos/cosmos-sdk/pull/16656) Add custom max gas for block for sim config with unlimited as default.

### Improvements
Expand Down
48 changes: 42 additions & 6 deletions client/pruning/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ const FlagAppDBBackend = "app-db-backend"

// PruningCmd prunes the sdk root multi store history versions based on the pruning options
// specified by command flags.
<<<<<<< HEAD
func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command {
=======
func Cmd(appCreator servertypes.AppCreator, defaultNodeHome string) *cobra.Command {
>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856))
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.
<<<<<<< HEAD
The pruning option is provided via the '--pruning' flag or alternatively with '--pruning-keep-recent'
For '--pruning' the options are as follows:
Expand All @@ -41,21 +46,47 @@ func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command {
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'
>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856))

// Bind flags to the Context's Viper so we can get pruning options.
- 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'

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
Expand All @@ -75,6 +106,7 @@ func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command {
return fmt.Errorf("the database has no valid heights to prune, the latest height: %v", latestHeight)
}
<<<<<<< HEAD
var pruningHeights []int64
for height := int64(1); height < latestHeight; height++ {
if height < latestHeight-int64(pruningOptions.KeepRecent) {
Expand All @@ -90,19 +122,23 @@ func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command {
pruningHeights[0],
pruningHeights[len(pruningHeights)-1],
)
=======
pruningHeight := latestHeight - int64(pruningOptions.KeepRecent)
cmd.Printf("pruning heights up to %v\n", pruningHeight)
>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856))
err = rootMultiStore.PruneStores(false, pruningHeights)
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'),
Expand Down
6 changes: 6 additions & 0 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,15 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
tmcli.NewCompletionCmd(rootCmd, true),
NewTestnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
<<<<<<< HEAD
config.Cmd(),
pruning.PruningCmd(a.newApp),
snapshot.Cmd(a.newApp),
=======
confixcmd.ConfigCommand(),
pruning.Cmd(newApp, simapp.DefaultNodeHome),
snapshot.Cmd(newApp),
>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856))
)

server.AddCommands(rootCmd, simapp.DefaultNodeHome, a.newApp, a.appExport, addModuleInitFlags)
Expand Down
Loading

0 comments on commit 60f98a7

Please sign in to comment.