github.com/spf13/viper's recent releases introduced a semantic
change in some public API such as viper.IsSet(), which have
broken some of our flags checks. Instead of checking whether
users have changed a flag's default value we should rely on such
defaults and adjust runtime behaviour accordingly. In order to do
so, it's important that we pick sane defaults for all our flags.
The --pruning flag and configuration option now allow for a
fake custom strategy. When users elect custom, then the
pruning-{keep,snapshot}-every options are interpreted and
parsed; else they're ignored.
Zero is pruning-{keep,snapshot}-every default value. When
users choose to set a custom pruning strategy they are
signalling that they want more fine-grainted control, therefore
it's legitimate to expect them to know what they are doing and
enter valid values for both options.
Ref #5964
34 lines
933 B
Go
34 lines
933 B
Go
package server
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
"github.com/cosmos/cosmos-sdk/store"
|
|
)
|
|
|
|
// GetPruningOptionsFromFlags parses start command flags and returns the correct PruningOptions.
|
|
// flagPruning prevails over flagPruningKeepEvery and flagPruningSnapshotEvery.
|
|
// Default option is PruneSyncable.
|
|
func GetPruningOptionsFromFlags() (store.PruningOptions, error) {
|
|
strategy := viper.GetString(flagPruning)
|
|
switch strategy {
|
|
case "syncable", "nothing", "everything":
|
|
return store.NewPruningOptionsFromString(viper.GetString(flagPruning)), nil
|
|
|
|
case "custom":
|
|
opts := store.PruningOptions{
|
|
KeepEvery: viper.GetInt64(flagPruningKeepEvery),
|
|
SnapshotEvery: viper.GetInt64(flagPruningSnapshotEvery),
|
|
}
|
|
if !opts.IsValid() {
|
|
return opts, fmt.Errorf("invalid granular options")
|
|
}
|
|
return opts, nil
|
|
|
|
default:
|
|
return store.PruningOptions{}, fmt.Errorf("unknown pruning strategy %s", strategy)
|
|
}
|
|
}
|