Skip to content

Commit

Permalink
cherry pick: 2ec442d
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderbez committed Dec 18, 2023
1 parent 47b0907 commit a5c5f11
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
6 changes: 6 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
32 changes: 28 additions & 4 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 11 additions & 2 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type Store struct {
listeners map[types.StoreKey]*types.MemoryListener
metrics metrics.StoreMetrics
commitHeader cmtproto.Header
commitSync bool
}

var (
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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-------------------------------
Expand Down

0 comments on commit a5c5f11

Please sign in to comment.