Skip to content

Commit

Permalink
fix(runtime): remove appv1alpha1.Config from runtime (#21042)
Browse files Browse the repository at this point in the history
(cherry picked from commit 502450c)

# Conflicts:
#	runtime/module.go
#	runtime/v2/app.go
#	runtime/v2/module.go
  • Loading branch information
julienrbrt authored and mergify[bot] committed Jul 25, 2024
1 parent 0702719 commit 53f49f9
Show file tree
Hide file tree
Showing 4 changed files with 387 additions and 3 deletions.
2 changes: 0 additions & 2 deletions runtime/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"golang.org/x/exp/slices"

runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
"cosmossdk.io/core/appmodule"
"cosmossdk.io/log"
storetypes "cosmossdk.io/store/types"
Expand Down Expand Up @@ -51,7 +50,6 @@ type App struct {
baseAppOptions []BaseAppOption
msgServiceRouter *baseapp.MsgServiceRouter
grpcQueryRouter *baseapp.GRPCQueryRouter
appConfig *appv1alpha1.Config
logger log.Logger
// initChainer is the init chainer function defined by the app config.
// this is only required if the chain wants to add special InitChainer logic.
Expand Down
17 changes: 16 additions & 1 deletion runtime/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,16 @@ import (
"google.golang.org/protobuf/reflect/protoregistry"

runtimev1alpha1 "cosmossdk.io/api/cosmos/app/runtime/v1alpha1"
<<<<<<< HEAD

Check failure on line 12 in runtime/module.go

View workflow job for this annotation

GitHub Actions / split-test-files

missing import path

Check failure on line 12 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path

Check failure on line 12 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path

Check failure on line 12 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path
appv1alpha1 "cosmossdk.io/api/cosmos/app/v1alpha1"
authmodulev1 "cosmossdk.io/api/cosmos/auth/module/v1"
stakingmodulev1 "cosmossdk.io/api/cosmos/staking/module/v1"
"cosmossdk.io/core/address"
=======

Check failure on line 17 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path
autocliv1 "cosmossdk.io/api/cosmos/autocli/v1"
reflectionv1 "cosmossdk.io/api/cosmos/reflection/v1"
"cosmossdk.io/core/app"
>>>>>>> 502450cd1 (fix(runtime): remove `appv1alpha1.Config` from runtime (#21042))

Check failure on line 21 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

missing import path

Check failure on line 21 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found ':'

Check failure on line 21 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'
"cosmossdk.io/core/appmodule"
"cosmossdk.io/core/comet"
"cosmossdk.io/core/event"
Expand Down Expand Up @@ -127,6 +133,7 @@ func ProvideApp(interfaceRegistry codectypes.InterfaceRegistry) (
type AppInputs struct {
depinject.In

<<<<<<< HEAD

Check failure on line 136 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected '}', found '<<'

Check failure on line 136 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

expected ';', found '<<'
AppConfig *appv1alpha1.Config
Config *runtimev1alpha1.Module
AppBuilder *AppBuilder
Expand All @@ -136,13 +143,21 @@ type AppInputs struct {
InterfaceRegistry codectypes.InterfaceRegistry
LegacyAmino *codec.LegacyAmino
Logger log.Logger
=======
Logger log.Logger
Config *runtimev1alpha1.Module
AppBuilder *AppBuilder
ModuleManager *module.Manager
BaseAppOptions []BaseAppOption
InterfaceRegistry codectypes.InterfaceRegistry
LegacyAmino legacy.Amino
>>>>>>> 502450cd1 (fix(runtime): remove `appv1alpha1.Config` from runtime (#21042))

Check failure on line 154 in runtime/module.go

View workflow job for this annotation

GitHub Actions / dependency-review

illegal character U+0023 '#'
}

func SetupAppBuilder(inputs AppInputs) {
app := inputs.AppBuilder.app
app.baseAppOptions = inputs.BaseAppOptions
app.config = inputs.Config
app.appConfig = inputs.AppConfig
app.logger = inputs.Logger
app.ModuleManager = module.NewManagerFromMap(inputs.Modules)

Expand Down
123 changes: 123 additions & 0 deletions runtime/v2/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package runtime

import (
"encoding/json"
"errors"

gogoproto "github.com/cosmos/gogoproto/proto"
"golang.org/x/exp/slices"

runtimev2 "cosmossdk.io/api/cosmos/app/runtime/v2"
"cosmossdk.io/core/legacy"
"cosmossdk.io/core/log"
"cosmossdk.io/core/registry"
"cosmossdk.io/core/transaction"
"cosmossdk.io/server/v2/appmanager"
"cosmossdk.io/server/v2/stf"
)

// App is a wrapper around AppManager and ModuleManager that can be used in hybrid
// app.go/app config scenarios or directly as a servertypes.Application instance.
// To get an instance of *App, *AppBuilder must be requested as a dependency
// in a container which declares the runtime module and the AppBuilder.Build()
// method must be called.
//
// App can be used to create a hybrid app.go setup where some configuration is
// done declaratively with an app config and the rest of it is done the old way.
// See simapp/app_v2.go for an example of this setup.
type App[T transaction.Tx] struct {
*appmanager.AppManager[T]

// app manager dependencies
stf *stf.STF[T]
msgRouterBuilder *stf.MsgRouterBuilder
queryRouterBuilder *stf.MsgRouterBuilder
db Store

// app configuration
logger log.Logger
config *runtimev2.Module

// modules configuration
storeKeys []string
interfaceRegistrar registry.InterfaceRegistrar
amino legacy.Amino
moduleManager *MM[T]

// GRPCQueryDecoders maps gRPC method name to a function that decodes the request
// bytes into a gogoproto.Message, which then can be passed to appmanager.
GRPCQueryDecoders map[string]func(requestBytes []byte) (gogoproto.Message, error)
}

// Name returns the app name.
func (a *App[T]) Name() string {
return a.config.AppName
}

// Logger returns the app logger.
func (a *App[T]) Logger() log.Logger {
return a.logger
}

// ModuleManager returns the module manager.
func (a *App[T]) ModuleManager() *MM[T] {
return a.moduleManager
}

// DefaultGenesis returns a default genesis from the registered modules.
func (a *App[T]) DefaultGenesis() map[string]json.RawMessage {
return a.moduleManager.DefaultGenesis()
}

// LoadLatest loads the latest version.
func (a *App[T]) LoadLatest() error {
return a.db.LoadLatestVersion()
}

// LoadHeight loads a particular height
func (a *App[T]) LoadHeight(height uint64) error {
return a.db.LoadVersion(height)
}

// Close is called in start cmd to gracefully cleanup resources.
func (a *App[T]) Close() error {
return nil
}

// GetStoreKeys returns all the app store keys.
func (a *App[T]) GetStoreKeys() []string {
return a.storeKeys
}

// UnsafeFindStoreKey fetches a registered StoreKey from the App in linear time.
// NOTE: This should only be used in testing.
func (a *App[T]) UnsafeFindStoreKey(storeKey string) (string, error) {
i := slices.IndexFunc(a.storeKeys, func(s string) bool { return s == storeKey })
if i == -1 {
return "", errors.New("store key not found")
}

return a.storeKeys[i], nil
}

// GetStore returns the app store.
func (a *App[T]) GetStore() Store {
return a.db
}

// GetLogger returns the app logger.
func (a *App[T]) GetLogger() log.Logger {
return a.logger
}

func (a *App[T]) ExecuteGenesisTx(_ []byte) error {
panic("App.ExecuteGenesisTx not supported in runtime/v2")
}

func (a *App[T]) GetAppManager() *appmanager.AppManager[T] {
return a.AppManager
}

func (a *App[T]) GetGRPCQueryDecoders() map[string]func(requestBytes []byte) (gogoproto.Message, error) {
return a.GRPCQueryDecoders
}
Loading

0 comments on commit 53f49f9

Please sign in to comment.