Skip to content

Commit

Permalink
DefaultStoreOptions to store/v2/root
Browse files Browse the repository at this point in the history
  • Loading branch information
hieuvubk committed Jul 23, 2024
1 parent 3d01423 commit 32249d3
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 31 deletions.
8 changes: 3 additions & 5 deletions runtime/v2/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,9 @@ func (a *AppBuilder[T]) Build(opts ...AppBuilderOption[T]) (*App[T], error) {
v := a.viper
home := v.GetString(FlagHome)

storeOpts := rootstore.Options{}
if v != nil {
if err := v.Sub("store.options").Unmarshal(&storeOpts); err != nil {
return nil, fmt.Errorf("failed to store options: %w", err)
}
storeOpts := rootstore.DefaultStoreOptions()
if err := v.Sub("store.options").Unmarshal(&storeOpts); err != nil {
return nil, fmt.Errorf("failed to store options: %w", err)
}

scRawDb, err := db.NewDB(db.DBType(v.GetString("store.app-db-backend")), "application", filepath.Join(home, "data"), nil)
Expand Down
4 changes: 2 additions & 2 deletions server/v2/store/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Supported app-db-backend types include 'goleveldb', 'rocksdb', 'pebbledb'.`,
}

logger := log.NewLogger(cmd.OutOrStdout())
home, err := cmd.Flags().GetString(serverv2.FlagHome) // should be FlagHome
home, err := cmd.Flags().GetString(serverv2.FlagHome)
if err != nil {
return err
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func createRootStore(cmd *cobra.Command, rootDir string, v *viper.Viper, logger
}
}

storeOpts := DefaultStoreOptions()
storeOpts := root.DefaultStoreOptions()
if v != nil {
if err := v.Sub("store.options").Unmarshal(&storeOpts); err != nil {
return nil, 0, fmt.Errorf("failed to store options: %w", err)
Expand Down
25 changes: 2 additions & 23 deletions server/v2/store/config.go
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
package store

import (
storev2 "cosmossdk.io/store/v2"
"cosmossdk.io/store/v2/commitment/iavl"
"cosmossdk.io/store/v2/root"
)

func DefaultConfig() *Config {
return &Config{
AppDBBackend: "goleveldb",
Options: DefaultStoreOptions(),
}
}

func DefaultStoreOptions() root.Options {
return root.Options{
SSType: 0,
SCType: 0,
SCPruningOption: &storev2.PruningOption{
KeepRecent: 2,
Interval: 1,
},
SSPruningOption: &storev2.PruningOption{
KeepRecent: 2,
Interval: 1,
},
IavlConfig: &iavl.Config{
CacheSize: 100_000,
SkipFastStorageUpgrade: true,
},
Options: root.DefaultStoreOptions(),
}
}

type Config struct {
AppDBBackend string `mapstructure:"app-db-backend" toml:"app-db-backend"`
AppDBBackend string `mapstructure:"app-db-backend" toml:"app-db-backend" comment:"The type of database for application and snapshots databases."`
Options root.Options `mapstructure:"options" toml:"options"`
}
2 changes: 1 addition & 1 deletion store/v2/commitment/iavl/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package iavl
// Config is the configuration for the IAVL tree.
type Config struct {
CacheSize int `mapstructure:"cache_size" toml:"cache_size" comment:"CacheSize set the size of the iavl tree cache."`
SkipFastStorageUpgrade bool `mapstructure:"skip_fast_storage_upgrade" toml:"skip_fast_storage_upgrade", comment:"If true, the tree will work like no fast storage and always not upgrade fast storage."`
SkipFastStorageUpgrade bool `mapstructure:"skip_fast_storage_upgrade" toml:"skip_fast_storage_upgrade" comment:"If true, the tree will work like no fast storage and always not upgrade fast storage."`
}

// DefaultConfig returns the default configuration for the IAVL tree.
Expand Down

0 comments on commit 32249d3

Please sign in to comment.