diff --git a/runtime/v2/app.go b/runtime/v2/app.go index 71b6f79fc187..a9869da24bca 100644 --- a/runtime/v2/app.go +++ b/runtime/v2/app.go @@ -14,7 +14,6 @@ import ( coreappmanager "cosmossdk.io/server/v2/core/appmanager" corestore "cosmossdk.io/server/v2/core/store" "cosmossdk.io/server/v2/stf" - storetypes "cosmossdk.io/store/types" "github.com/cosmos/cosmos-sdk/codec" codectypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -59,7 +58,7 @@ type App struct { appConfig *appv1alpha1.Config // modules configuration - storeKeys []storetypes.StoreKey + storeKeys []string interfaceRegistry codectypes.InterfaceRegistry cdc codec.Codec amino *codec.LegacyAmino @@ -100,24 +99,26 @@ func (a *App) Close() error { // This method should only be used for registering extra stores // wiich is necessary for modules that not registered using the app config. // To be used in combination of RegisterModules. -func (a *App) RegisterStores(keys ...storetypes.StoreKey) error { +func (a *App) RegisterStores(keys ...string) error { a.storeKeys = append(a.storeKeys, keys...) // a.MountStores(keys...) + // TODO verify if still needed + return nil } // GetStoreKeys returns all the stored store keys. -func (a *App) GetStoreKeys() []storetypes.StoreKey { +func (a *App) 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) UnsafeFindStoreKey(storeKey string) storetypes.StoreKey { - i := slices.IndexFunc(a.storeKeys, func(s storetypes.StoreKey) bool { return s.Name() == storeKey }) +func (a *App) UnsafeFindStoreKey(storeKey string) string { + i := slices.Index(a.storeKeys, storeKey) if i == -1 { - return nil + return "" } return a.storeKeys[i] diff --git a/runtime/v2/go.mod b/runtime/v2/go.mod index 9495859d04f6..d29008cc44d6 100644 --- a/runtime/v2/go.mod +++ b/runtime/v2/go.mod @@ -41,7 +41,6 @@ require ( cosmossdk.io/server/v2/appmanager v0.0.0-00010101000000-000000000000 cosmossdk.io/server/v2/core v0.0.0-00010101000000-000000000000 cosmossdk.io/server/v2/stf v0.0.0-00010101000000-000000000000 - cosmossdk.io/store v1.0.2 cosmossdk.io/store/v2 v2.0.0-00010101000000-000000000000 cosmossdk.io/x/tx v0.13.1 github.com/cosmos/cosmos-sdk v0.51.0 @@ -58,6 +57,7 @@ require ( cosmossdk.io/collections v0.4.0 // indirect cosmossdk.io/errors v1.0.1 // indirect cosmossdk.io/math v1.3.0 // indirect + cosmossdk.io/store v1.0.2 // indirect cosmossdk.io/x/auth v0.0.0-00010101000000-000000000000 // indirect filippo.io/edwards25519 v1.1.0 // indirect github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect diff --git a/runtime/v2/module.go b/runtime/v2/module.go index 06cbc582ff20..9a0d21c842c7 100644 --- a/runtime/v2/module.go +++ b/runtime/v2/module.go @@ -24,7 +24,6 @@ import ( "cosmossdk.io/log" "cosmossdk.io/runtime/v2/services" "cosmossdk.io/server/v2/stf" - storetypes "cosmossdk.io/store/types" "cosmossdk.io/x/tx/signing" "github.com/cosmos/cosmos-sdk/codec" @@ -167,7 +166,7 @@ func ProvideInterfaceRegistry(addressCodec address.Codec, validatorAddressCodec return interfaceRegistry, nil } -func registerStoreKey(wrapper *AppBuilder, key storetypes.StoreKey) { +func registerStoreKey(wrapper *AppBuilder, key string) { wrapper.app.storeKeys = append(wrapper.app.storeKeys, key) } @@ -180,25 +179,32 @@ func storeKeyOverride(config *runtimev2.Module, moduleName string) *runtimev2.St return nil } -func ProvideKVStoreKey(config *runtimev2.Module, key depinject.ModuleKey, app *AppBuilder) *storetypes.KVStoreKey { +type ( + KVStoreKey string + MemoryStoreKey string +) + +func ProvideKVStoreKey(config *runtimev2.Module, key depinject.ModuleKey, app *AppBuilder) KVStoreKey { override := storeKeyOverride(config, key.Name()) var storeKeyName string if override != nil { storeKeyName = override.KvStoreKey + if storeKeyName == "" { + panic(fmt.Sprintf("store key name for module %s cannot be empty", key.Name())) + } } else { storeKeyName = key.Name() } - storeKey := storetypes.NewKVStoreKey(storeKeyName) - registerStoreKey(app, storeKey) - return storeKey + registerStoreKey(app, storeKeyName) + return KVStoreKey(storeKeyName) } -func ProvideMemoryStoreKey(key depinject.ModuleKey, app *AppBuilder) *storetypes.MemoryStoreKey { - storeKey := storetypes.NewMemoryStoreKey(fmt.Sprintf("memory:%s", key.Name())) +func ProvideMemoryStoreKey(key depinject.ModuleKey, app *AppBuilder) MemoryStoreKey { + storeKey := fmt.Sprintf("memory:%s", key.Name()) registerStoreKey(app, storeKey) - return storeKey + return MemoryStoreKey(storeKey) } // ProvideEnvironment provides the environment for keeper modules, while maintaining backward compatibility and provide services directly as well. @@ -208,10 +214,10 @@ func ProvideEnvironment(logger log.Logger, config *runtimev2.Module, key depinje store.MemoryStoreService, ) { kvStoreKey := ProvideKVStoreKey(config, key, app) - kvService := stf.NewKVStoreService([]byte(kvStoreKey.Name())) + kvService := stf.NewKVStoreService([]byte(kvStoreKey)) memStoreKey := ProvideMemoryStoreKey(key, app) - memService := stf.NewMemoryStoreService([]byte(memStoreKey.Name())) + memService := stf.NewMemoryStoreService([]byte(memStoreKey)) env := appmodulev2.Environment{ Logger: logger, diff --git a/runtime/v2/store.go b/runtime/v2/store.go index 9098f2538aae..d3c44b0edcd5 100644 --- a/runtime/v2/store.go +++ b/runtime/v2/store.go @@ -4,14 +4,13 @@ import ( "cosmossdk.io/core/store" corestore "cosmossdk.io/server/v2/core/store" "cosmossdk.io/server/v2/stf" - storetypes "cosmossdk.io/store/types" storev2 "cosmossdk.io/store/v2" ) // NewKVStoreService creates a new KVStoreService. -// This wrapper is kept for backwards compatibility. -func NewKVStoreService(storeKey *storetypes.KVStoreKey) store.KVStoreService { - return stf.NewKVStoreService([]byte(storeKey.Name())) +// Compared to runtime/v1.NewKVStoreService, this function takes a storeKey as a string. +func NewKVStoreService(storeKey string) store.KVStoreService { + return stf.NewKVStoreService([]byte(storeKey)) } type Store interface { diff --git a/simapp/app_test.go b/simapp/app_test.go index 4b7dd25eb0e4..13f8011662de 100644 --- a/simapp/app_test.go +++ b/simapp/app_test.go @@ -239,7 +239,6 @@ func TestInitGenesisOnMigration(t *testing.T) { mockDefaultGenesis := json.RawMessage(`{"key": "value"}`) mockModule.EXPECT().DefaultGenesis().Times(1).Return(mockDefaultGenesis) mockModule.EXPECT().InitGenesis(gomock.Eq(ctx), gomock.Eq(mockDefaultGenesis)).Times(1) - mockModule.EXPECT().ConsensusVersion().Times(1).Return(uint64(0)) app.ModuleManager.Modules["mock"] = mockModule