Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime/v2): provide default factory options if unset in app builder #21690

Merged
merged 5 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading