diff --git a/CHANGELOG.md b/CHANGELOG.md index 15046e02b0b7..fdd92a8a58f1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#507](https://github.com/crypto-org-chain/cosmos-sdk/pull/507) mempool respect gas wanted returned by ante handler * [#744](https://github.com/crypto-org-chain/cosmos-sdk/pull/744) Pass raw transactions to tx executor so it can do pre-estimations. * [#884](https://github.com/crypto-org-chain/cosmos-sdk/pull/884) Avoid decoding tx for in PrepareProposal if it's NopMempool. +* [#]() Prune cmd wait for async pruning to finish. ## [Unreleased] diff --git a/client/pruning/main.go b/client/pruning/main.go index 51dc5f9c2162..58ffcf964c30 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -87,8 +87,12 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, pruningHeight := latestHeight - int64(pruningOptions.KeepRecent) cmd.Printf("pruning heights up to %v\n", pruningHeight) - err = rootMultiStore.PruneStores(pruningHeight) - if err != nil { + if err := rootMultiStore.PruneStores(pruningHeight); err != nil { + return err + } + + // close will wait for async pruning process to finish + if err := rootMultiStore.Close(); err != nil { return err } diff --git a/store/iavl/store.go b/store/iavl/store.go index 7066891cda19..1ff68609e8a3 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -389,6 +389,13 @@ func (st *Store) TraverseStateChanges(startVersion, endVersion int64, fn func(ve return st.tree.TraverseStateChanges(startVersion, endVersion, fn) } +func (st *Store) Close() error { + if closer, ok := st.tree.(io.Closer); ok { + return closer.Close() + } + return nil +} + // Takes a MutableTree, a key, and a flag for creating existence or absence proof and returns the // appropriate merkle.Proof. Since this must be called after querying for the value, this function should never error // Thus, it will panic on error rather than returning it diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 540814b51415..7484f5d4be26 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -1188,6 +1188,16 @@ func (rs *Store) flushMetadata(db dbm.DB, version int64, cInfo *types.CommitInfo rs.logger.Debug("flushing metadata finished", "height", version) } +func (rs *Store) Close() error { + errs := make([]error, 0, len(rs.stores)) + for _, store := range rs.stores { + if closer, ok := store.(io.Closer); ok { + errs = append(errs, closer.Close()) + } + } + return errors.Join(errs...) +} + type storeParams struct { key types.StoreKey db dbm.DB