From bc9627b01ee6fdfc3796b9b550dc9f0cd4df4423 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 | 4 ++-- server/config/toml.go | 2 +- server/start.go | 4 ++-- store/rootmulti/store.go | 17 +++++++++++------ 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5a9c0c83b297..18397048d07b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,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 5fe5371023e5..6611476a8129 100644 --- a/server/config/config.go +++ b/server/config/config.go @@ -322,9 +322,9 @@ 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 == pruningtypes.PruningOptionEverything && c.StateSync.SnapshotInterval > 0 { + if c.Pruning == storetypes.PruningOptionEverything && c.StateSync.SnapshotInterval > 0 { return sdkerrors.ErrAppConfig.Wrapf( - "cannot enable state sync snapshots with '%s' pruning setting", pruningtypes.PruningOptionEverything, + "cannot enable state sync snapshots with '%s' pruning setting", storetypes.PruningOptionEverything, ) } diff --git a/server/config/toml.go b/server/config/toml.go index 6f91fa2e893a..750d09e05541 100644 --- a/server/config/toml.go +++ b/server/config/toml.go @@ -24,7 +24,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 03ff00511bbb..fe59e435036a 100644 --- a/server/start.go +++ b/server/start.go @@ -163,8 +163,8 @@ For '--pruning' the options are as follows: default: the last 362880 states are kept, pruning at 10 block intervals nothing: all historic states will be saved, nothing will be deleted (i.e. archiving node) -everything: 2 latest states will be kept; pruning at 10 block intervals. -custom: allow pruning options to be manually specified through 'pruning-keep-recent', and 'pruning-interval' +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 the ABCI Commit phase, the node will check if the current block height is greater than or equal to diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index e2f589094c58..777eefed8c86 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -508,12 +508,17 @@ func (rs *Store) Commit() types.CommitID { rs.lastCommitInfo.Timestamp = rs.commitHeader.Time defer rs.flushMetadata(rs.db, version, rs.lastCommitInfo) - // remove remnants of removed stores - for sk := range rs.removalMap { - if _, ok := rs.stores[sk]; ok { - delete(rs.stores, sk) - delete(rs.storesParams, sk) - delete(rs.keysByName, sk.Name()) + // Determine if pruneHeight height needs to be added to the list of heights to + // be pruned, where pruneHeight = (commitHeight - 1) - KeepRecent. + if rs.pruningOpts.Interval > 0 && int64(rs.pruningOpts.KeepRecent) < previousHeight { + pruneHeight := previousHeight - int64(rs.pruningOpts.KeepRecent) + // We consider this height to be pruned iff: + // + // - KeepEvery is zero as that means that all heights should be pruned. + // - KeepEvery % (height - KeepRecent) != 0 as that means the height is not + // a 'snapshot' height. + if rs.pruningOpts.KeepEvery == 0 || pruneHeight%int64(rs.pruningOpts.KeepEvery) != 0 { + rs.pruneHeights = append(rs.pruneHeights, pruneHeight) } }