diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a3515a5b7a9..8c6bc2fa2a91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -56,6 +56,7 @@ Every module contains its own CHANGELOG.md. Please refer to the module you are i * (sims) [#21906](https://github.com/cosmos/cosmos-sdk/pull/21906) Skip sims test when running dry on validators * (cli) [#21919](https://github.com/cosmos/cosmos-sdk/pull/21919) Query address-by-acc-num by account_id instead of id. +* (cli) [#22656](https://github.com/cosmos/cosmos-sdk/pull/22656) Prune cmd should disable async pruning. ### API Breaking Changes diff --git a/baseapp/options.go b/baseapp/options.go index 743d04c5543c..54e2f88a1b3c 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -86,6 +86,11 @@ func SetIAVLDisableFastNode(disable bool) func(*BaseApp) { return func(bapp *BaseApp) { bapp.cms.SetIAVLDisableFastNode(disable) } } +// SetIAVLSyncPruning set sync/async pruning in the IAVL store. +func SetIAVLSyncPruning(syncPruning bool) func(*BaseApp) { + return func(bapp *BaseApp) { bapp.cms.SetIAVLSyncPruning(syncPruning) } +} + // SetInterBlockCache provides a BaseApp option function that sets the // inter-block cache. func SetInterBlockCache(cache storetypes.MultiStorePersistentCache) func(*BaseApp) { diff --git a/client/pruning/main.go b/client/pruning/main.go index bdcff50a9bc5..0168308ea325 100644 --- a/client/pruning/main.go +++ b/client/pruning/main.go @@ -50,6 +50,9 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, return err } + // must disable async pruning + vp.Set(server.FlagIAVLSyncPruning, true) + // use the first argument if present to set the pruning method if len(args) > 0 { vp.Set(server.FlagPruning, args[0]) @@ -72,6 +75,9 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`, return err } + // in our test, it's important to close db explicitly for pebbledb to write to disk. + defer db.Close() + logger := log.NewLogger(cmd.OutOrStdout()) app := appCreator(logger, db, nil, vp) cms := app.CommitMultiStore() diff --git a/server/mock/store.go b/server/mock/store.go index 18bb4f2d7d40..12755c613731 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -142,6 +142,10 @@ func (ms multiStore) SetIAVLDisableFastNode(disable bool) { panic("not implemented") } +func (ms multiStore) SetIAVLSyncPruning(syncPruning bool) { + panic("not implemented") +} + func (ms multiStore) SetInitialVersion(version int64) error { panic("not implemented") } diff --git a/server/start.go b/server/start.go index f9ae56676305..7c74255e6992 100644 --- a/server/start.go +++ b/server/start.go @@ -79,6 +79,7 @@ const ( FlagMinRetainBlocks = "min-retain-blocks" FlagIAVLCacheSize = "iavl-cache-size" FlagDisableIAVLFastNode = "iavl-disable-fastnode" + FlagIAVLSyncPruning = "iavl-sync-pruning" FlagShutdownGrace = "shutdown-grace" // state sync-related flags diff --git a/server/util.go b/server/util.go index ca28fc568a3b..4bd944d356fb 100644 --- a/server/util.go +++ b/server/util.go @@ -555,6 +555,7 @@ func DefaultBaseappOptions(appOpts types.AppOptions) []func(*baseapp.BaseApp) { baseapp.SetSnapshot(snapshotStore, snapshotOptions), baseapp.SetIAVLCacheSize(cast.ToInt(appOpts.Get(FlagIAVLCacheSize))), baseapp.SetIAVLDisableFastNode(cast.ToBool(appOpts.Get(FlagDisableIAVLFastNode))), + baseapp.SetIAVLSyncPruning(cast.ToBool(appOpts.Get(FlagIAVLSyncPruning))), defaultMempool, baseapp.SetChainID(chainID), baseapp.SetQueryGasLimit(cast.ToUint64(appOpts.Get(FlagQueryGasLimit))), diff --git a/store/iavl/store.go b/store/iavl/store.go index ab04b73c47b7..aa44a0b7438d 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -51,11 +51,16 @@ func LoadStore(db corestore.KVStoreWithBatch, logger types.Logger, key types.Sto // provided DB. An error is returned if the version fails to load, or if called with a positive // version on an empty tree. func LoadStoreWithInitialVersion(db corestore.KVStoreWithBatch, logger types.Logger, key types.StoreKey, id types.CommitID, initialVersion uint64, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) { + return LoadStoreWithOpts(db, logger, key, id, initialVersion, cacheSize, disableFastNode, metrics, iavl.AsyncPruningOption(true)) +} + +func LoadStoreWithOpts(db corestore.KVStoreWithBatch, logger types.Logger, key types.StoreKey, id types.CommitID, initialVersion uint64, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics, opts ...iavl.Option) (types.CommitKVStore, error) { // store/v1 and app/v1 flows never require an initial version of 0 if initialVersion == 0 { initialVersion = 1 } - tree := iavl.NewMutableTree(db, cacheSize, disableFastNode, logger, iavl.InitialVersionOption(initialVersion), iavl.AsyncPruningOption(true)) + opts = append(opts, iavl.InitialVersionOption(initialVersion)) + tree := iavl.NewMutableTree(db, cacheSize, disableFastNode, logger, opts...) isUpgradeable, err := tree.IsUpgradeable() if err != nil { diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index e821e930de7f..50ccc8af67b1 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -63,6 +63,7 @@ type Store struct { pruningManager *pruning.Manager iavlCacheSize int iavlDisableFastNode bool + iavlSyncPruning bool storesParams map[types.StoreKey]storeParams stores map[types.StoreKey]types.CommitKVStore keysByName map[string]types.StoreKey @@ -133,6 +134,10 @@ func (rs *Store) SetIAVLDisableFastNode(disableFastNode bool) { rs.iavlDisableFastNode = disableFastNode } +func (rs *Store) SetIAVLSyncPruning(syncPruning bool) { + rs.iavlSyncPruning = syncPruning +} + // GetStoreType implements Store. func (rs *Store) GetStoreType() types.StoreType { return types.StoreTypeMulti @@ -1033,15 +1038,7 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID panic("recursive MultiStores not yet supported") case types.StoreTypeIAVL: - var store types.CommitKVStore - var err error - - if params.initialVersion == 0 { - store, err = iavl.LoadStore(db, rs.logger, key, id, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics) - } else { - store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics) - } - + store, err := iavl.LoadStoreWithOpts(db, rs.logger, key, id, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics, iavltree.AsyncPruningOption(!rs.iavlSyncPruning)) if err != nil { return nil, err } diff --git a/store/types/store.go b/store/types/store.go index 8aab76a170b0..16ffc90c72d1 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -221,6 +221,9 @@ type CommitMultiStore interface { // SetIAVLDisableFastNode enables/disables fastnode feature on iavl. SetIAVLDisableFastNode(disable bool) + // SetIAVLSyncPruning set sync/async pruning on iavl. + SetIAVLSyncPruning(sync bool) + // RollbackToVersion rollback the db to specific version(height). RollbackToVersion(version int64) error