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

feat(runtime/v2): store/v2 #19723

Closed
wants to merge 2 commits into from
Closed
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
15 changes: 8 additions & 7 deletions runtime/v2/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion runtime/v2/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 17 additions & 11 deletions runtime/v2/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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.
Expand All @@ -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,
Expand Down
7 changes: 3 additions & 4 deletions runtime/v2/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 0 additions & 1 deletion simapp/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading