From ae14edc90089497efd194feaa5c037913b11b2bc Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 12:01:27 +0100 Subject: [PATCH 01/16] add pre run command to check for prunning options --- server/start.go | 40 ++++++++++++++----- server/start_test.go | 94 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 10 deletions(-) create mode 100644 server/start_test.go diff --git a/server/start.go b/server/start.go index 5a9cd0500884..7d7b40e46a00 100644 --- a/server/start.go +++ b/server/start.go @@ -20,18 +20,23 @@ import ( // Tendermint full-node start flags const ( - flagWithTendermint = "with-tendermint" - flagAddress = "address" - flagTraceStore = "trace-store" - flagPruning = "pruning" - flagCPUProfile = "cpu-profile" - FlagMinGasPrices = "minimum-gas-prices" - FlagHaltHeight = "halt-height" - FlagHaltTime = "halt-time" - FlagInterBlockCache = "inter-block-cache" - FlagUnsafeSkipUpgrades = "unsafe-skip-upgrades" + flagWithTendermint = "with-tendermint" + flagAddress = "address" + flagTraceStore = "trace-store" + flagPruning = "pruning" + flagPruningKeepEvery = "pruning-keep-every" + flagPruningSnapshotEvery = "pruning-snapshot-every" + flagCPUProfile = "cpu-profile" + FlagMinGasPrices = "minimum-gas-prices" + FlagHaltHeight = "halt-height" + FlagHaltTime = "halt-time" + FlagInterBlockCache = "inter-block-cache" + FlagUnsafeSkipUpgrades = "unsafe-skip-upgrades" ) +var errPruningWithGranularOptions = fmt.Errorf("%s flag is not compatible with granular options as %s or %s", flagPruning, flagPruningKeepEvery, flagPruningSnapshotEvery) +var errPruningGranularOptions = fmt.Errorf("%s and %s must be set together", flagPruningSnapshotEvery, flagPruningKeepEvery) + // StartCmd runs the service passed in, either stand-alone or in-process with // Tendermint. func StartCmd(ctx *Context, appCreator AppCreator) *cobra.Command { @@ -56,6 +61,21 @@ will not be able to commit subsequent blocks. For profiling and benchmarking purposes, CPU profiling can be enabled via the '--cpu-profile' flag which accepts a path for the resulting pprof file. `, + PreRunE: func(cmd *cobra.Command, args []string) error { + if viper.IsSet(flagPruning) { + if viper.IsSet(flagPruningKeepEvery) || viper.IsSet(flagPruningSnapshotEvery) { + return errPruningWithGranularOptions + } + + return nil + } + + if !(viper.IsSet(flagPruningKeepEvery) && viper.IsSet(flagPruningSnapshotEvery)) { + return errPruningGranularOptions + } + + return nil + }, RunE: func(cmd *cobra.Command, args []string) error { if !viper.GetBool(flagWithTendermint) { ctx.Logger.Info("starting ABCI without Tendermint") diff --git a/server/start_test.go b/server/start_test.go new file mode 100644 index 000000000000..cd7c6b6ae14b --- /dev/null +++ b/server/start_test.go @@ -0,0 +1,94 @@ +package server + +import ( + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/require" +) + +func TestPruningOptions(t *testing.T) { + startCommand := StartCmd(nil, nil) + + tests := []struct { + name string + paramInit func() + returnsErr bool + expectedErr error + }{ + { + name: "only keep-every provided", + paramInit: func() { + viper.Set(flagPruningKeepEvery, 12345) + }, + returnsErr: true, + expectedErr: errPruningGranularOptions, + }, + { + name: "only snapshot-every provided", + paramInit: func() { + viper.Set(flagPruningSnapshotEvery, 12345) + }, + returnsErr: true, + expectedErr: errPruningGranularOptions, + }, + { + name: "pruning flag with other granular options 1", + paramInit: func() { + viper.Set(flagPruning, "set") + viper.Set(flagPruningSnapshotEvery, 1234) + }, + returnsErr: true, + expectedErr: errPruningWithGranularOptions, + }, + { + name: "pruning flag with other granular options 2", + paramInit: func() { + viper.Set(flagPruning, "set") + viper.Set(flagPruningKeepEvery, 1234) + }, + returnsErr: true, + expectedErr: errPruningWithGranularOptions, + }, + { + name: "pruning flag with other granular options 3", + paramInit: func() { + viper.Set(flagPruning, "set") + viper.Set(flagPruningKeepEvery, 1234) + viper.Set(flagPruningSnapshotEvery, 1234) + }, + returnsErr: true, + expectedErr: errPruningWithGranularOptions, + }, + { + name: "only prunning set", + paramInit: func() { + viper.Set(flagPruning, "set") + }, + returnsErr: false, + expectedErr: nil, + }, + { + name: "only granular set", + paramInit: func() { + viper.Set(flagPruningSnapshotEvery, 12345) + viper.Set(flagPruningKeepEvery, 12345) + }, + returnsErr: false, + expectedErr: nil, + }, + } + + for _, tt := range tests { + viper.Reset() + tt.paramInit() + + err := startCommand.PreRunE(nil, nil) + + if tt.returnsErr { + require.EqualError(t, err, tt.expectedErr.Error()) + } else { + require.NoError(t, err) + } + } +} From 0d8dade5e2172ff52f4b6a0cdbbbc8433a683645 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 12:18:21 +0100 Subject: [PATCH 02/16] add case for none set --- server/start.go | 5 +++++ server/start_test.go | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/server/start.go b/server/start.go index 7d7b40e46a00..f3e8253e7bf7 100644 --- a/server/start.go +++ b/server/start.go @@ -36,6 +36,7 @@ const ( var errPruningWithGranularOptions = fmt.Errorf("%s flag is not compatible with granular options as %s or %s", flagPruning, flagPruningKeepEvery, flagPruningSnapshotEvery) var errPruningGranularOptions = fmt.Errorf("%s and %s must be set together", flagPruningSnapshotEvery, flagPruningKeepEvery) +var errPruningOptionsRequired = fmt.Errorf("pruning options required") // StartCmd runs the service passed in, either stand-alone or in-process with // Tendermint. @@ -62,6 +63,10 @@ For profiling and benchmarking purposes, CPU profiling can be enabled via the '- which accepts a path for the resulting pprof file. `, PreRunE: func(cmd *cobra.Command, args []string) error { + if !viper.IsSet(flagPruning) && !viper.IsSet(flagPruningKeepEvery) && !viper.IsSet(flagPruningSnapshotEvery) { + return errPruningOptionsRequired + } + if viper.IsSet(flagPruning) { if viper.IsSet(flagPruningKeepEvery) || viper.IsSet(flagPruningSnapshotEvery) { return errPruningWithGranularOptions diff --git a/server/start_test.go b/server/start_test.go index cd7c6b6ae14b..a61a31852b4a 100644 --- a/server/start_test.go +++ b/server/start_test.go @@ -16,6 +16,12 @@ func TestPruningOptions(t *testing.T) { returnsErr bool expectedErr error }{ + { + name: "none set", + paramInit: func() {}, + returnsErr: true, + expectedErr: errPruningOptionsRequired, + }, { name: "only keep-every provided", paramInit: func() { From a6cd6554ecb4966eafdf77654b4899a0e773a914 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 12:30:24 +0100 Subject: [PATCH 03/16] extract to function logic to check pruning params --- server/start.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/server/start.go b/server/start.go index f3e8253e7bf7..4749edf63378 100644 --- a/server/start.go +++ b/server/start.go @@ -63,23 +63,7 @@ For profiling and benchmarking purposes, CPU profiling can be enabled via the '- which accepts a path for the resulting pprof file. `, PreRunE: func(cmd *cobra.Command, args []string) error { - if !viper.IsSet(flagPruning) && !viper.IsSet(flagPruningKeepEvery) && !viper.IsSet(flagPruningSnapshotEvery) { - return errPruningOptionsRequired - } - - if viper.IsSet(flagPruning) { - if viper.IsSet(flagPruningKeepEvery) || viper.IsSet(flagPruningSnapshotEvery) { - return errPruningWithGranularOptions - } - - return nil - } - - if !(viper.IsSet(flagPruningKeepEvery) && viper.IsSet(flagPruningSnapshotEvery)) { - return errPruningGranularOptions - } - - return nil + return checkPruningParams() }, RunE: func(cmd *cobra.Command, args []string) error { if !viper.GetBool(flagWithTendermint) { @@ -114,6 +98,27 @@ which accepts a path for the resulting pprof file. return cmd } +// checkPruningParams checks that the provided pruning params are correct +func checkPruningParams() error { + if !viper.IsSet(flagPruning) && !viper.IsSet(flagPruningKeepEvery) && !viper.IsSet(flagPruningSnapshotEvery) { + return errPruningOptionsRequired + } + + if viper.IsSet(flagPruning) { + if viper.IsSet(flagPruningKeepEvery) || viper.IsSet(flagPruningSnapshotEvery) { + return errPruningWithGranularOptions + } + + return nil + } + + if !(viper.IsSet(flagPruningKeepEvery) && viper.IsSet(flagPruningSnapshotEvery)) { + return errPruningGranularOptions + } + + return nil +} + func startStandAlone(ctx *Context, appCreator AppCreator) error { addr := viper.GetString(flagAddress) home := viper.GetString("home") From cfb3819183b01e7c209ef5e9ea405b0a45cd85cb Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 13:40:01 +0100 Subject: [PATCH 04/16] add function to get pruning options from flags --- server/pruning.go | 21 ++++++++++++++++++ server/pruning_test.go | 50 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 server/pruning.go create mode 100644 server/pruning_test.go diff --git a/server/pruning.go b/server/pruning.go new file mode 100644 index 000000000000..d3fa8a102203 --- /dev/null +++ b/server/pruning.go @@ -0,0 +1,21 @@ +package server + +import ( + "github.com/cosmos/cosmos-sdk/store" + "github.com/spf13/viper" +) + +func GetPruningOptionsFromFlags() store.PruningOptions { + if viper.IsSet(flagPruning) { + return store.NewPruningOptionsFromString(viper.GetString(flagPruning)) + } + + if viper.IsSet(flagPruningKeepEvery) && viper.IsSet(flagPruningSnapshotEvery) { + return store.PruningOptions{ + KeepEvery: viper.GetInt64(flagPruningKeepEvery), + SnapshotEvery: viper.GetInt64(flagPruningSnapshotEvery), + } + } + + return store.PruneSyncable +} diff --git a/server/pruning_test.go b/server/pruning_test.go new file mode 100644 index 000000000000..0d4d0bc6ca48 --- /dev/null +++ b/server/pruning_test.go @@ -0,0 +1,50 @@ +package server + +import ( + "testing" + + "github.com/spf13/viper" + "github.com/stretchr/testify/require" + + "github.com/cosmos/cosmos-sdk/store" +) + +func TestGetPruningOptionsFromFlags(t *testing.T) { + tests := []struct { + name string + initParams func() + expectedOptions store.PruningOptions + }{ + { + name: "pruning", + initParams: func() { + viper.Set(flagPruning, store.PruningStrategyNothing) + }, + expectedOptions: store.PruneNothing, + }, + { + name: "granular pruning", + initParams: func() { + viper.Set(flagPruningSnapshotEvery, 1234) + viper.Set(flagPruningKeepEvery, 4321) + }, + expectedOptions: store.PruningOptions{ + SnapshotEvery: 1234, + KeepEvery: 4321, + }, + }, + { + name: "default", + initParams: func() {}, + expectedOptions: store.PruneSyncable, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(j *testing.T) { + viper.Reset() + tt.initParams() + require.Equal(t, tt.expectedOptions, GetPruningOptionsFromFlags()) + }) + } +} From 2f55b9d25549dd240a3e5710e7b491e5d7ef1eaf Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 15:56:07 +0100 Subject: [PATCH 05/16] change default and fix test --- server/start.go | 4 +++- server/start_test.go | 6 +++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/start.go b/server/start.go index 4749edf63378..68bd9e55efe4 100644 --- a/server/start.go +++ b/server/start.go @@ -83,6 +83,8 @@ which accepts a path for the resulting pprof file. cmd.Flags().String(flagAddress, "tcp://0.0.0.0:26658", "Listen address") cmd.Flags().String(flagTraceStore, "", "Enable KVStore tracing to an output file") cmd.Flags().String(flagPruning, "syncable", "Pruning strategy: syncable, nothing, everything") + cmd.Flags().Int64(flagPruningKeepEvery, 0, "Define the state number that will be kept") + cmd.Flags().Int64(flagPruningSnapshotEvery, 0, "Defines the state that will be snapshot for pruning") cmd.Flags().String( FlagMinGasPrices, "", "Minimum gas prices to accept for transactions; Any fee in a tx must meet this minimum (e.g. 0.01photino;0.0001stake)", @@ -101,7 +103,7 @@ which accepts a path for the resulting pprof file. // checkPruningParams checks that the provided pruning params are correct func checkPruningParams() error { if !viper.IsSet(flagPruning) && !viper.IsSet(flagPruningKeepEvery) && !viper.IsSet(flagPruningSnapshotEvery) { - return errPruningOptionsRequired + return nil // Use default } if viper.IsSet(flagPruning) { diff --git a/server/start_test.go b/server/start_test.go index a61a31852b4a..169a6fb5ae7c 100644 --- a/server/start_test.go +++ b/server/start_test.go @@ -17,10 +17,10 @@ func TestPruningOptions(t *testing.T) { expectedErr error }{ { - name: "none set", + name: "none set, returns nil and will use default from flags", paramInit: func() {}, - returnsErr: true, - expectedErr: errPruningOptionsRequired, + returnsErr: false, + expectedErr: nil, }, { name: "only keep-every provided", From 93e3f33461167e47deafe494667d760675309b39 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 16:02:29 +0100 Subject: [PATCH 06/16] remove unused error --- server/start.go | 1 - 1 file changed, 1 deletion(-) diff --git a/server/start.go b/server/start.go index 68bd9e55efe4..6fd9c2f35a61 100644 --- a/server/start.go +++ b/server/start.go @@ -36,7 +36,6 @@ const ( var errPruningWithGranularOptions = fmt.Errorf("%s flag is not compatible with granular options as %s or %s", flagPruning, flagPruningKeepEvery, flagPruningSnapshotEvery) var errPruningGranularOptions = fmt.Errorf("%s and %s must be set together", flagPruningSnapshotEvery, flagPruningKeepEvery) -var errPruningOptionsRequired = fmt.Errorf("pruning options required") // StartCmd runs the service passed in, either stand-alone or in-process with // Tendermint. From 9aeefa77d316b43b86e105ac13d69711cf3e901b Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 16:05:10 +0100 Subject: [PATCH 07/16] update command doc --- server/start.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/start.go b/server/start.go index 6fd9c2f35a61..0e29cc5d6854 100644 --- a/server/start.go +++ b/server/start.go @@ -46,7 +46,9 @@ func StartCmd(ctx *Context, appCreator AppCreator) *cobra.Command { Long: `Run the full node application with Tendermint in or out of process. By default, the application will run with Tendermint in process. -Pruning options can be provided via the '--pruning' flag. The options are as follows: +Pruning options can be provided via the '--pruning' flag or with '--pruning-snapshot-every' and 'pruning-keep-every' together. + +For '--pruning' the options are as follows: syncable: only those states not needed for state syncing will be deleted (flushes every 100th to disk and keeps every 10000th) nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) From 0c3117b3c75e1ede94abfd4f18560a120fb8d7ab Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 16:07:24 +0100 Subject: [PATCH 08/16] add godoc into GetPruningOptionsFromFlags --- server/pruning.go | 1 + 1 file changed, 1 insertion(+) diff --git a/server/pruning.go b/server/pruning.go index d3fa8a102203..3cfa8f05d122 100644 --- a/server/pruning.go +++ b/server/pruning.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/viper" ) +//GetPruningOptionsFromFlags parses start command flags and returns the correct PruningOptions. func GetPruningOptionsFromFlags() store.PruningOptions { if viper.IsSet(flagPruning) { return store.NewPruningOptionsFromString(viper.GetString(flagPruning)) From 2dbd364d3ba762f380489b17c199606d19f04c17 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 16:16:08 +0100 Subject: [PATCH 09/16] update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c3a38ae1e37..5ff37df3a448 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,8 @@ Ref: https://keepachangelog.com/en/1.0.0/ balances or a single balance by denom when the `denom` query parameter is present. * (client) [\#5640](https://github.com/cosmos/cosmos-sdk/pull/5640) The rest server endpoint `/swagger-ui/` is replaced by ´/´. * (x/auth) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5702) The `x/auth` querier route has changed from `"acc"` to `"auth"`. +* (server) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5709) There are two new flags for pruning, `--pruning-keep-every` +and `--pruning-snapshot-every` as an alternative to `--pruning`. They allow to fine tune the strategy for pruning the state. ### API Breaking Changes From 0a3fcf6d2d30f74ca2113f4f37e2b1e5a1610db1 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 16:23:15 +0100 Subject: [PATCH 10/16] change section in changelog --- CHANGELOG.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5ff37df3a448..0d0b80762013 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,8 +43,6 @@ Ref: https://keepachangelog.com/en/1.0.0/ balances or a single balance by denom when the `denom` query parameter is present. * (client) [\#5640](https://github.com/cosmos/cosmos-sdk/pull/5640) The rest server endpoint `/swagger-ui/` is replaced by ´/´. * (x/auth) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5702) The `x/auth` querier route has changed from `"acc"` to `"auth"`. -* (server) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5709) There are two new flags for pruning, `--pruning-keep-every` -and `--pruning-snapshot-every` as an alternative to `--pruning`. They allow to fine tune the strategy for pruning the state. ### API Breaking Changes @@ -147,6 +145,8 @@ Buffers for state serialization instead of Amino. * (rest) [\#5648](https://github.com/cosmos/cosmos-sdk/pull/5648) Enhance /txs usability: * Add `tx.minheight` key to filter transaction with an inclusive minimum block height * Add `tx.maxheight` key to filter transaction with an inclusive maximum block height +* (server) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5709) There are two new flags for pruning, `--pruning-keep-every` +and `--pruning-snapshot-every` as an alternative to `--pruning`. They allow to fine tune the strategy for pruning the state. ## [v0.38.1] - 2020-02-11 From a21a7faebcf2e20dad2d2b909514e386f88d04f2 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 16:33:30 +0100 Subject: [PATCH 11/16] update test error lint --- server/pruning_test.go | 1 + server/start_test.go | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/server/pruning_test.go b/server/pruning_test.go index 0d4d0bc6ca48..41fab48ec0f3 100644 --- a/server/pruning_test.go +++ b/server/pruning_test.go @@ -42,6 +42,7 @@ func TestGetPruningOptionsFromFlags(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(j *testing.T) { + tt := tt viper.Reset() tt.initParams() require.Equal(t, tt.expectedOptions, GetPruningOptionsFromFlags()) diff --git a/server/start_test.go b/server/start_test.go index 169a6fb5ae7c..a9ef4b88e1f1 100644 --- a/server/start_test.go +++ b/server/start_test.go @@ -86,15 +86,19 @@ func TestPruningOptions(t *testing.T) { } for _, tt := range tests { - viper.Reset() - tt.paramInit() + t.Run(tt.name, func(t *testing.T) { + tt := tt - err := startCommand.PreRunE(nil, nil) + viper.Reset() + tt.paramInit() - if tt.returnsErr { - require.EqualError(t, err, tt.expectedErr.Error()) - } else { - require.NoError(t, err) - } + err := startCommand.PreRunE(nil, nil) + + if tt.returnsErr { + require.EqualError(t, err, tt.expectedErr.Error()) + } else { + require.NoError(t, err) + } + }) } } From fa3572e300359c6a29f68f4c971307ccb9664b26 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 16:35:13 +0100 Subject: [PATCH 12/16] update start cmd desc --- server/start.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/start.go b/server/start.go index 0e29cc5d6854..06b4f9b8f0f1 100644 --- a/server/start.go +++ b/server/start.go @@ -46,7 +46,7 @@ func StartCmd(ctx *Context, appCreator AppCreator) *cobra.Command { Long: `Run the full node application with Tendermint in or out of process. By default, the application will run with Tendermint in process. -Pruning options can be provided via the '--pruning' flag or with '--pruning-snapshot-every' and 'pruning-keep-every' together. +Pruning options can be provided via the '--pruning' flag or alternatively with '--pruning-snapshot-every' and 'pruning-keep-every' together. For '--pruning' the options are as follows: From 191664bb30c926df3b4135fe7746d8aaa358f0c5 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 17:22:47 +0100 Subject: [PATCH 13/16] fix issue number --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d0b80762013..494533cd10a4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -145,7 +145,7 @@ Buffers for state serialization instead of Amino. * (rest) [\#5648](https://github.com/cosmos/cosmos-sdk/pull/5648) Enhance /txs usability: * Add `tx.minheight` key to filter transaction with an inclusive minimum block height * Add `tx.maxheight` key to filter transaction with an inclusive maximum block height -* (server) [\#5702](https://github.com/cosmos/cosmos-sdk/pull/5709) There are two new flags for pruning, `--pruning-keep-every` +* (server) [\#5709](https://github.com/cosmos/cosmos-sdk/pull/5709) There are two new flags for pruning, `--pruning-keep-every` and `--pruning-snapshot-every` as an alternative to `--pruning`. They allow to fine tune the strategy for pruning the state. ## [v0.38.1] - 2020-02-11 From 0027111db49e064f3df68393b86628dbc21f8434 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Thu, 27 Feb 2020 17:29:13 +0100 Subject: [PATCH 14/16] fix linter test --- server/pruning_test.go | 2 +- server/start_test.go | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/server/pruning_test.go b/server/pruning_test.go index 41fab48ec0f3..916f4e07dfba 100644 --- a/server/pruning_test.go +++ b/server/pruning_test.go @@ -41,8 +41,8 @@ func TestGetPruningOptionsFromFlags(t *testing.T) { } for _, tt := range tests { + tt := tt t.Run(tt.name, func(j *testing.T) { - tt := tt viper.Reset() tt.initParams() require.Equal(t, tt.expectedOptions, GetPruningOptionsFromFlags()) diff --git a/server/start_test.go b/server/start_test.go index a9ef4b88e1f1..c9c4f61ef640 100644 --- a/server/start_test.go +++ b/server/start_test.go @@ -86,9 +86,9 @@ func TestPruningOptions(t *testing.T) { } for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - tt := tt + tt := tt + t.Run(tt.name, func(t *testing.T) { viper.Reset() tt.paramInit() From 3c262306fa943f22c033ea7e34fefa10bd17feb2 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 28 Feb 2020 10:48:34 +0100 Subject: [PATCH 15/16] add more information into GetPruningOptionsFromFlags --- server/pruning.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/pruning.go b/server/pruning.go index 3cfa8f05d122..07730f36ad8a 100644 --- a/server/pruning.go +++ b/server/pruning.go @@ -5,7 +5,9 @@ import ( "github.com/spf13/viper" ) -//GetPruningOptionsFromFlags parses start command flags and returns the correct PruningOptions. +// GetPruningOptionsFromFlags parses start command flags and returns the correct PruningOptions. +// flagPruning prevails over flagPruningKeepEvery and flagPruningSnapshotEvery. +// Default option is PruneSyncable. func GetPruningOptionsFromFlags() store.PruningOptions { if viper.IsSet(flagPruning) { return store.NewPruningOptionsFromString(viper.GetString(flagPruning)) From 60970baf201a743d4e3d8951ab0e40ccae991d48 Mon Sep 17 00:00:00 2001 From: Jonathan Gimeno Date: Fri, 28 Feb 2020 10:53:56 +0100 Subject: [PATCH 16/16] update from PR comments --- server/start.go | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/server/start.go b/server/start.go index 06b4f9b8f0f1..c5bee58e8f1a 100644 --- a/server/start.go +++ b/server/start.go @@ -34,8 +34,16 @@ const ( FlagUnsafeSkipUpgrades = "unsafe-skip-upgrades" ) -var errPruningWithGranularOptions = fmt.Errorf("%s flag is not compatible with granular options as %s or %s", flagPruning, flagPruningKeepEvery, flagPruningSnapshotEvery) -var errPruningGranularOptions = fmt.Errorf("%s and %s must be set together", flagPruningSnapshotEvery, flagPruningKeepEvery) +var ( + errPruningWithGranularOptions = fmt.Errorf( + "'--%s' flag is not compatible with granular options '--%s' or '--%s'", + flagPruning, flagPruningKeepEvery, flagPruningSnapshotEvery, + ) + errPruningGranularOptions = fmt.Errorf( + "'--%s' and '--%s' must be set together", + flagPruningSnapshotEvery, flagPruningKeepEvery, + ) +) // StartCmd runs the service passed in, either stand-alone or in-process with // Tendermint. @@ -104,7 +112,7 @@ which accepts a path for the resulting pprof file. // checkPruningParams checks that the provided pruning params are correct func checkPruningParams() error { if !viper.IsSet(flagPruning) && !viper.IsSet(flagPruningKeepEvery) && !viper.IsSet(flagPruningSnapshotEvery) { - return nil // Use default + return nil } if viper.IsSet(flagPruning) {