From 0e71ce308e719f21e631d68f36acd60943fe3cd4 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 12 Sep 2024 09:13:02 -0500 Subject: [PATCH 1/4] fix(runtime/v2): provide default factory options if unset in app builder --- runtime/v2/builder.go | 12 +++++++++--- simapp/v2/app_di.go | 4 ++-- simapp/v2/simdv2/cmd/commands.go | 8 ++------ 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/runtime/v2/builder.go b/runtime/v2/builder.go index 2dc6ca7227d..0a1b279330d 100644 --- a/runtime/v2/builder.go +++ b/runtime/v2/builder.go @@ -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 @@ -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, } @@ -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 } diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 1411b28823b..0328f2f3d1c 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -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( @@ -191,7 +191,7 @@ func NewSimApp[T transaction.Tx]( } if sub := viper.Sub("store.options"); sub != nil { - err = sub.Unmarshal(&storeOptions) + err = sub.Unmarshal(storeOptions) if err != nil { panic(err) } diff --git a/simapp/v2/simdv2/cmd/commands.go b/simapp/v2/simdv2/cmd/commands.go index 2e315c64a18..d58619170e0 100644 --- a/simapp/v2/simdv2/cmd/commands.go +++ b/simapp/v2/simdv2/cmd/commands.go @@ -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]( From 3ad2a6e595f4f8c999194ab8f52401c6201bba8b Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 12 Sep 2024 09:54:49 -0500 Subject: [PATCH 2/4] fix simapp/v2 usage --- simapp/v2/app_di.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index 0328f2f3d1c..d2940eaa495 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -100,7 +100,7 @@ func NewSimApp[T transaction.Tx]( app = &SimApp[T]{} appBuilder *runtime.AppBuilder[T] err error - storeOptions *root.Options + storeOptions = &root.Options{} // merge the AppConfig and other configuration in one config appConfig = depinject.Configs( From d8a6ed70c8a3f06ba1bfbe1cbadcfbd145359b6f Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 12 Sep 2024 10:30:49 -0500 Subject: [PATCH 3/4] whitespace? --- testutil/rest.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/testutil/rest.go b/testutil/rest.go index 5026d1f01b9..3a3103dcbc8 100644 --- a/testutil/rest.go +++ b/testutil/rest.go @@ -42,7 +42,7 @@ func GetRequestWithHeaders(url string, headers map[string]string) ([]byte, error // GetRequest defines a wrapper around an HTTP GET request with a provided URL. // An error is returned if the request or reading the body fails. func GetRequest(url string) ([]byte, error) { - res, err := http.Get(url) + res, err := http.Get(url) if err != nil { return nil, err } @@ -61,7 +61,7 @@ func GetRequest(url string) ([]byte, error) { // PostRequest defines a wrapper around an HTTP POST request with a provided URL and data. // An error is returned if the request or reading the body fails. func PostRequest(url, contentType string, data []byte) ([]byte, error) { - res, err := http.Post(url, contentType, bytes.NewBuffer(data)) + res, err := http.Post(url, contentType, bytes.NewBuffer(data)) if err != nil { return nil, fmt.Errorf("error while sending post request: %w", err) } From c8ea058b7afbbd46cbbdf7197b75645163085ce0 Mon Sep 17 00:00:00 2001 From: Matt Kocubinski Date: Thu, 12 Sep 2024 14:22:38 -0500 Subject: [PATCH 4/4] fix test --- simapp/v2/app_di.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/simapp/v2/app_di.go b/simapp/v2/app_di.go index d2940eaa495..a41a6addafe 100644 --- a/simapp/v2/app_di.go +++ b/simapp/v2/app_di.go @@ -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) 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) }