Skip to content

Commit

Permalink
fix(runtime/v2): provide default factory options if unset in app buil…
Browse files Browse the repository at this point in the history
…der (#21690)
  • Loading branch information
kocubinski authored Sep 13, 2024
1 parent c0e84af commit 9fc6675
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
12 changes: 9 additions & 3 deletions runtime/v2/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
type AppBuilder[T transaction.Tx] struct {
app *App[T]
config server.DynamicConfig
storeOptions rootstore.Options
storeOptions *rootstore.Options

// the following fields are used to overwrite the default
branch func(state store.ReaderMap) store.WriterMap
Expand Down Expand Up @@ -131,10 +131,16 @@ func (a *AppBuilder[T]) Build(opts ...AppBuilderOption[T]) (*App[T], error) {
panic(err)
}

var storeOptions rootstore.Options
if a.storeOptions != nil {
storeOptions = *a.storeOptions
} else {
storeOptions = rootstore.DefaultStoreOptions()
}
factoryOptions := &rootstore.FactoryOptions{
Logger: a.app.logger,
RootDir: home,
Options: a.storeOptions,
Options: storeOptions,
StoreKeys: append(a.app.storeKeys, "stf"),
SCRawDB: scRawDb,
}
Expand Down Expand Up @@ -216,7 +222,7 @@ func AppBuilderWithPostTxExec[T transaction.Tx](postTxExec func(ctx context.Cont
}
}

func AppBuilderWithStoreOptions[T transaction.Tx](opts rootstore.Options) AppBuilderOption[T] {
func AppBuilderWithStoreOptions[T transaction.Tx](opts *rootstore.Options) AppBuilderOption[T] {
return func(a *AppBuilder[T]) {
a.storeOptions = opts
}
Expand Down
8 changes: 5 additions & 3 deletions simapp/v2/app_di.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func NewSimApp[T transaction.Tx](
app = &SimApp[T]{}
appBuilder *runtime.AppBuilder[T]
err error
storeOptions = root.DefaultStoreOptions()
storeOptions = &root.Options{}

// merge the AppConfig and other configuration in one config
appConfig = depinject.Configs(
Expand Down Expand Up @@ -190,13 +190,15 @@ func NewSimApp[T transaction.Tx](
panic(err)
}

var builderOpts []runtime.AppBuilderOption[T]
if sub := viper.Sub("store.options"); sub != nil {
err = sub.Unmarshal(&storeOptions)
err = sub.Unmarshal(storeOptions)
if err != nil {
panic(err)
}
builderOpts = append(builderOpts, runtime.AppBuilderWithStoreOptions[T](storeOptions))
}
app.App, err = appBuilder.Build(runtime.AppBuilderWithStoreOptions[T](storeOptions))
app.App, err = appBuilder.Build(builderOpts...)
if err != nil {
panic(err)
}
Expand Down
8 changes: 2 additions & 6 deletions simapp/v2/simdv2/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,9 @@ import (
v2 "github.com/cosmos/cosmos-sdk/x/genutil/v2/cli"
)

func newApp[T transaction.Tx](
logger log.Logger, viper *viper.Viper,
) serverv2.AppI[T] {
func newApp[T transaction.Tx](logger log.Logger, viper *viper.Viper) serverv2.AppI[T] {
viper.Set(serverv2.FlagHome, simapp.DefaultNodeHome)

return serverv2.AppI[T](
simapp.NewSimApp[T](logger, viper))
return serverv2.AppI[T](simapp.NewSimApp[T](logger, viper))
}

func initRootCmd[T transaction.Tx](
Expand Down

0 comments on commit 9fc6675

Please sign in to comment.