From febcb9219327ca4462e1610414d5cdbef64ca9d1 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Wed, 23 Feb 2022 23:22:10 +0100 Subject: [PATCH] refactor: prune everything (backport #11177) (#11258) * refactor: prune everything (#11177) (cherry picked from commit 75bcf47f13b9e7d046ae5969e03dae1dc8f22067) # Conflicts: # CHANGELOG.md # server/config/toml.go # server/start.go # store/rootmulti/store.go # store/types/pruning.go # store/v2/multi/store_test.go * updates * updates * updates * updates * updates Co-authored-by: Aleksandr Bezobchuk Co-authored-by: Aleksandr Bezobchuk --- CHANGELOG.md | 1 + server/config/config.go | 5 +++++ server/config/toml.go | 2 +- server/start.go | 2 +- store/rootmulti/store.go | 2 +- store/types/pruning.go | 2 +- 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0f05697049af..5d514a8adf4b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Bug Fixes +* (store) [\#11177](https://github.com/cosmos/cosmos-sdk/pull/11177) Update the prune `nothing` strategy to store the last two heights. * (store) [\#11117](https://github.com/cosmos/cosmos-sdk/pull/11117) Fix data race in store trace component ### Improvements diff --git a/server/config/config.go b/server/config/config.go index 803808b19a72..f17e70f11832 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -321,6 +321,11 @@ func (c Config) ValidateBasic() error { if c.BaseConfig.MinGasPrices == "" { return sdkerrors.ErrAppConfig.Wrap("set min gas price in app.toml or flag or env variable") } + if c.Pruning == storetypes.PruningOptionEverything && c.StateSync.SnapshotInterval > 0 { + return sdkerrors.ErrAppConfig.Wrapf( + "cannot enable state sync snapshots with '%s' pruning setting", storetypes.PruningOptionEverything, + ) + } return nil } diff --git a/server/config/toml.go b/server/config/toml.go index 9e8eeadaf1ef..09361110d54e 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -22,7 +22,7 @@ minimum-gas-prices = "{{ .BaseConfig.MinGasPrices }}" # default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals # nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) -# everything: all saved states will be deleted, storing only the current state; pruning at 10 block intervals +# everything: all saved states will be deleted, storing only the current and previous state; pruning at 10 block intervals # custom: allow pruning options to be manually specified through 'pruning-keep-recent', 'pruning-keep-every', and 'pruning-interval' pruning = "{{ .BaseConfig.Pruning }}" diff --git a/server/start.go b/server/start.go index bda8b6ed8117..6ff040da4b57 100644 --- a/server/start.go +++ b/server/start.go @@ -88,7 +88,7 @@ For '--pruning' the options are as follows: default: the last 100 states are kept in addition to every 500th state; pruning at 10 block intervals nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) -everything: all saved states will be deleted, storing only the current state; pruning at 10 block intervals +everything: all saved states will be deleted, storing only the current and previous state; pruning at 10 block intervals custom: allow pruning options to be manually specified through 'pruning-keep-recent', 'pruning-keep-every', and 'pruning-interval' Node halting configurations exist in the form of two flags: '--halt-height' and '--halt-time'. During diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index e1acd62e3ac5..05d8631e8c05 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -407,7 +407,7 @@ func (rs *Store) Commit() types.CommitID { // Determine if pruneHeight height needs to be added to the list of heights to // be pruned, where pruneHeight = (commitHeight - 1) - KeepRecent. - if int64(rs.pruningOpts.KeepRecent) < previousHeight { + if rs.pruningOpts.Interval > 0 && int64(rs.pruningOpts.KeepRecent) < previousHeight { pruneHeight := previousHeight - int64(rs.pruningOpts.KeepRecent) // We consider this height to be pruned iff: // diff --git a/store/types/pruning.go b/store/types/pruning.go index 4419acb950d8..dcb57b2467a3 100644 --- a/store/types/pruning.go +++ b/store/types/pruning.go @@ -21,7 +21,7 @@ var ( // PruneEverything defines a pruning strategy where all committed heights are // deleted, storing only the current height and where to-be pruned heights are // pruned at every 10th height. - PruneEverything = NewPruningOptions(0, 0, 10) + PruneEverything = NewPruningOptions(2, 0, 10) // PruneNothing defines a pruning strategy where all heights are kept on disk. PruneNothing = NewPruningOptions(0, 1, 0)