From a5c5f11c648241775744baf8ae69dd1453deac89 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Mon, 18 Dec 2023 11:03:09 -0800 Subject: [PATCH] cherry pick: 2ec442da9 --- baseapp/options.go | 6 ++++++ go.mod | 2 ++ store/iavl/store.go | 32 ++++++++++++++++++++++++++++---- store/rootmulti/store.go | 13 +++++++++++-- store/types/store.go | 6 ++++++ 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/baseapp/options.go b/baseapp/options.go index c0c9caf05895..3ae4d3c59c49 100644 --- a/baseapp/options.go +++ b/baseapp/options.go @@ -23,6 +23,12 @@ import ( // File for storing in-package BaseApp optional functions, // for options that need access to non-exported fields of the BaseApp +func SetCommitSync(sync bool) func(app *BaseApp) { + return func(bapp *BaseApp) { + bapp.cms.SetCommitSync(sync) + } +} + // SetPruning sets a pruning option on the multistore associated with the app func SetPruning(opts pruningtypes.PruningOptions) func(*BaseApp) { return func(bapp *BaseApp) { bapp.cms.SetPruning(opts) } diff --git a/go.mod b/go.mod index b17960260d30..4c25d1e18b16 100644 --- a/go.mod +++ b/go.mod @@ -180,6 +180,8 @@ replace ( github.com/gin-gonic/gin => github.com/gin-gonic/gin v1.9.1 // replace broken goleveldb github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 + + cosmossdk.io/store => ./store ) retract ( diff --git a/store/iavl/store.go b/store/iavl/store.go index 7734066269c8..487bcb7b8b52 100644 --- a/store/iavl/store.go +++ b/store/iavl/store.go @@ -42,16 +42,40 @@ type Store struct { // LoadStore returns an IAVL Store as a CommitKVStore. Internally, it will load the // store's version (id) from the provided DB. An error is returned if the version // fails to load, or if called with a positive version on an empty tree. -func LoadStore(db dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) { - return LoadStoreWithInitialVersion(db, logger, key, id, 0, cacheSize, disableFastNode, metrics) +func LoadStore( + db dbm.DB, + logger log.Logger, + key types.StoreKey, + id types.CommitID, + cacheSize int, + disableFastNode, commitSync bool, + metrics metrics.StoreMetrics, +) (types.CommitKVStore, error) { + return LoadStoreWithInitialVersion(db, logger, key, id, 0, cacheSize, disableFastNode, commitSync, metrics) } // LoadStoreWithInitialVersion returns an IAVL Store as a CommitKVStore setting its initialVersion // to the one given. Internally, it will load the store's version (id) from the // 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 dbm.DB, logger log.Logger, key types.StoreKey, id types.CommitID, initialVersion uint64, cacheSize int, disableFastNode bool, metrics metrics.StoreMetrics) (types.CommitKVStore, error) { - tree := iavl.NewMutableTree(db, cacheSize, disableFastNode, logger, iavl.InitialVersionOption(initialVersion)) +func LoadStoreWithInitialVersion( + db dbm.DB, + logger log.Logger, + key types.StoreKey, + id types.CommitID, + initialVersion uint64, + cacheSize int, + disableFastNode, commitSync bool, + metrics metrics.StoreMetrics, +) (types.CommitKVStore, error) { + tree := iavl.NewMutableTree( + db, + cacheSize, + disableFastNode, + logger, + iavl.InitialVersionOption(initialVersion), + iavl.SyncOption(commitSync), + ) isUpgradeable, err := tree.IsUpgradeable() if err != nil { diff --git a/store/rootmulti/store.go b/store/rootmulti/store.go index 551a53e635c8..a836a39feccd 100644 --- a/store/rootmulti/store.go +++ b/store/rootmulti/store.go @@ -74,6 +74,7 @@ type Store struct { listeners map[types.StoreKey]*types.MemoryListener metrics metrics.StoreMetrics commitHeader cmtproto.Header + commitSync bool } var ( @@ -106,6 +107,14 @@ func (rs *Store) GetPruning() pruningtypes.PruningOptions { return rs.pruningManager.GetOptions() } +func (rs *Store) GetCommitSync() bool { + return rs.commitSync +} + +func (rs *Store) SetCommitSync(sync bool) { + rs.commitSync = sync +} + // SetPruning sets the pruning strategy on the root store and all the sub-stores. // Note, calling SetPruning on the root store prior to LoadVersion or // LoadLatestVersion performs a no-op as the stores aren't mounted yet. @@ -1009,9 +1018,9 @@ func (rs *Store) loadCommitStoreFromParams(key types.StoreKey, id types.CommitID var err error if params.initialVersion == 0 { - store, err = iavl.LoadStore(db, rs.logger, key, id, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics) + store, err = iavl.LoadStore(db, rs.logger, key, id, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.commitSync, rs.metrics) } else { - store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.metrics) + store, err = iavl.LoadStoreWithInitialVersion(db, rs.logger, key, id, params.initialVersion, rs.iavlCacheSize, rs.iavlDisableFastNode, rs.commitSync, rs.metrics) } if err != nil { diff --git a/store/types/store.go b/store/types/store.go index 8980179950e2..108785cc221c 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -224,6 +224,12 @@ type CommitMultiStore interface { // SetMetrics sets the metrics for the KVStore SetMetrics(metrics metrics.StoreMetrics) + + // SetCommitSync set store commit sync mode + SetCommitSync(sync bool) + + // GetCommitSync get store commit sync mode + GetCommitSync() bool } //---------subsp-------------------------------