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

Problem: MultiStore interface is bloated #240

Merged
merged 1 commit into from
Mar 29, 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
2 changes: 1 addition & 1 deletion baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ func (app *BaseApp) CreateQueryContext(height int64, prove bool) (sdk.Context, e
// use custom query multi-store if provided
qms := app.qms
if qms == nil {
qms = app.cms.(storetypes.MultiStore)
qms = storetypes.RootMultiStore(app.cms)
}

lastBlockHeight := qms.LatestVersion()
Expand Down
2 changes: 1 addition & 1 deletion baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ type BaseApp struct {
name string // application name from abci.BlockInfo
db dbm.DB // common DB backend
cms storetypes.CommitMultiStore // Main (uncached) state
qms storetypes.MultiStore // Optional alternative multistore for querying only.
qms storetypes.RootMultiStore // Optional alternative multistore for querying only.
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()
grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls
msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages
Expand Down
2 changes: 1 addition & 1 deletion baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (app *BaseApp) SetTxEncoder(txEncoder sdk.TxEncoder) {
// SetQueryMultiStore set a alternative MultiStore implementation to support grpc query service.
//
// Ref: https://github.com/cosmos/cosmos-sdk/issues/13317
func (app *BaseApp) SetQueryMultiStore(ms storetypes.MultiStore) {
func (app *BaseApp) SetQueryMultiStore(ms storetypes.RootMultiStore) {
app.qms = ms
}

Expand Down
2 changes: 1 addition & 1 deletion server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
storetypes "cosmossdk.io/store/types"
)

var _ storetypes.MultiStore = multiStore{}
var _ storetypes.CommitMultiStore = multiStore{}

type multiStore struct {
kv map[storetypes.StoreKey]kvStore
Expand Down
1 change: 1 addition & 0 deletions store/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Ref: https://keepachangelog.com/en/1.0.0/

* [#207](https://github.com/crypto-org-chain/cosmos-sdk/pull/207) Remove api CacheWrapWithTrace.
* [#205](https://github.com/crypto-org-chain/cosmos-sdk/pull/205) Support object store.
* [#240](https://github.com/crypto-org-chain/cosmos-sdk/pull/240) Split methods from `MultiStore` into specialized `RootMultiStore`, keep `MultiStore` generic.

## v1.1.0 (March 20, 2024)

Expand Down
14 changes: 0 additions & 14 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,6 @@ func (cms Store) TracingEnabled() bool {
return cms.traceWriter != nil
}

// LatestVersion returns the branch version of the store
func (cms Store) LatestVersion() int64 {
panic("cannot get latest version from branch cached multi-store")
}

// GetStoreType returns the type of the store.
func (cms Store) GetStoreType() types.StoreType {
return types.StoreTypeMulti
Expand All @@ -139,15 +134,6 @@ func (cms Store) CacheMultiStore() types.CacheMultiStore {
return newCacheMultiStoreFromCMS(cms)
}

// CacheMultiStoreWithVersion implements the MultiStore interface. It will panic
// as an already cached multi-store cannot load previous versions.
//
// TODO: The store implementation can possibly be modified to support this as it
// seems safe to load previous versions (heights).
func (cms Store) CacheMultiStoreWithVersion(_ int64) (types.CacheMultiStore, error) {
panic("cannot branch cached multi-store with a version")
}

// GetStore returns an underlying Store by key.
func (cms Store) GetStore(key types.StoreKey) types.Store {
s := cms.stores[key]
Expand Down
14 changes: 9 additions & 5 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,6 @@ type MultiStore interface {
// call CacheMultiStore.Write().
CacheMultiStore() CacheMultiStore

// CacheMultiStoreWithVersion branches the underlying MultiStore where
// each stored is loaded at a specific version (height).
CacheMultiStoreWithVersion(version int64) (CacheMultiStore, error)

// Convenience for fetching substores.
// If the store does not exist, panics.
GetStore(StoreKey) Store
Expand All @@ -150,6 +146,14 @@ type MultiStore interface {
// implied that the caller should update the context when necessary between
// tracing operations. The modified MultiStore is returned.
SetTracingContext(TraceContext) MultiStore
}

type RootMultiStore interface {
MultiStore

// CacheMultiStoreWithVersion branches the underlying MultiStore where
// each stored is loaded at a specific version (height).
CacheMultiStoreWithVersion(version int64) (CacheMultiStore, error)

// LatestVersion returns the latest version in the store
LatestVersion() int64
Expand All @@ -164,7 +168,7 @@ type CacheMultiStore interface {
// CommitMultiStore is an interface for a MultiStore without cache capabilities.
type CommitMultiStore interface {
Committer
MultiStore
RootMultiStore
snapshottypes.Snapshotter

// Mount a store of type using the given db.
Expand Down
Loading