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 1ee99c0 commit d910cb7
Show file tree
Hide file tree
Showing 4 changed files with 434 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

Check failure on line 24 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected declaration, found '<<'

Check failure on line 24 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected declaration, found '<<' (typecheck)

Check failure on line 24 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body
func PruningCmd(appCreator servertypes.AppCreator) *cobra.Command {
=======

Check failure on line 26 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected ==, expecting }
func Cmd(appCreator servertypes.AppCreator, defaultNodeHome string) *cobra.Command {
>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856))

Check failure on line 28 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 28 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)

Check failure on line 28 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected >>, expecting }

Check failure on line 28 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'
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 {

Check failure on line 47 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

method has multiple receivers

Check failure on line 47 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected {, expecting (
vp := viper.New()

Check failure on line 48 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: unexpected := in parameter list; possibly missing comma or )
=======

Check failure on line 49 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

syntax error: non-declaration statement outside function body
The pruning option is provided via the 'pruning' argument or alternatively with '--pruning-keep-recent'

Check failure on line 50 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal rune literal

Check failure on line 50 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal rune literal

Check failure on line 50 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal rune literal (typecheck)

Check failure on line 50 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

more than one character in rune literal
>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856))

Check failure on line 51 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'

Check failure on line 51 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal character U+0023 '#' (typecheck)

Check failure on line 51 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / tests (00)

invalid character U+0023 '#'

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

Check failure on line 56 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal rune literal

Check failure on line 56 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal rune literal (typecheck)

Note: When the --app-db-backend flag is not specified, the default backend type is 'goleveldb'.

Check failure on line 58 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected type, found 'goleveldb'

Check failure on line 58 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal rune literal

Check failure on line 58 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal rune literal (typecheck)
Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,

Check failure on line 59 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal rune literal

Check failure on line 59 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found ','

Check failure on line 59 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal rune literal (typecheck)
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'),

Check failure on line 144 in client/pruning/main.go

View workflow job for this annotation

GitHub Actions / golangci-lint

illegal rune literal (typecheck)
Expand Down
5 changes: 5 additions & 0 deletions simapp/simd/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,13 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig params.EncodingConfig) {
genutilcli.InitCmd(simapp.ModuleBasics, simapp.DefaultNodeHome),
NewTestnetCmd(simapp.ModuleBasics, banktypes.GenesisBalancesIterator{}),
debug.Cmd(),
<<<<<<< HEAD
config.Cmd(),
pruning.PruningCmd(newApp),
=======
confixcmd.ConfigCommand(),
pruning.Cmd(newApp, simapp.DefaultNodeHome),
>>>>>>> 317fb0b33 (fix(cli): improve `prune` command ux (#16856))
snapshot.Cmd(newApp),
)

Expand Down
Loading

0 comments on commit d910cb7

Please sign in to comment.