Skip to content

Commit eef3595

Browse files
yihuangJayT106
authored andcommitted
Problem: MultiStore interface is bloated (#240)
* Problem: MultiStore interface is bloated Solution: - Split out specialied methods from it, keeping the MultiStore generic * Update store/CHANGELOG.md Signed-off-by: yihuang <[email protected]> --------- Signed-off-by: yihuang <[email protected]>
1 parent 5e13974 commit eef3595

File tree

7 files changed

+14
-23
lines changed

7 files changed

+14
-23
lines changed

baseapp/abci.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ func (app *BaseApp) CreateQueryContextWithCheckHeader(height int64, prove, check
12381238
// use custom query multi-store if provided
12391239
qms := app.qms
12401240
if qms == nil {
1241-
qms = app.cms.(storetypes.MultiStore)
1241+
qms = storetypes.RootMultiStore(app.cms)
12421242
}
12431243

12441244
lastBlockHeight := qms.LatestVersion()

baseapp/baseapp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ type BaseApp struct {
6868
name string // application name from abci.BlockInfo
6969
db dbm.DB // common DB backend
7070
cms storetypes.CommitMultiStore // Main (uncached) state
71-
qms storetypes.MultiStore // Optional alternative multistore for querying only.
71+
qms storetypes.RootMultiStore // Optional alternative multistore for querying only.
7272
storeLoader StoreLoader // function to handle store loading, may be overridden with SetStoreLoader()
7373
grpcQueryRouter *GRPCQueryRouter // router for redirecting gRPC query calls
7474
msgServiceRouter *MsgServiceRouter // router for redirecting Msg service messages

baseapp/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ func (app *BaseApp) SetTxEncoder(txEncoder sdk.TxEncoder) {
326326
// SetQueryMultiStore set a alternative MultiStore implementation to support grpc query service.
327327
//
328328
// Ref: https://github.com/cosmos/cosmos-sdk/issues/13317
329-
func (app *BaseApp) SetQueryMultiStore(ms storetypes.MultiStore) {
329+
func (app *BaseApp) SetQueryMultiStore(ms storetypes.RootMultiStore) {
330330
app.qms = ms
331331
}
332332

server/mock/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
storetypes "cosmossdk.io/store/types"
1313
)
1414

15-
var _ storetypes.MultiStore = multiStore{}
15+
var _ storetypes.CommitMultiStore = multiStore{}
1616

1717
type multiStore struct {
1818
kv map[storetypes.StoreKey]kvStore

store/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
2929

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

3334
## v1.1.2 (March 31, 2025)
3435

store/cachemulti/store.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -110,11 +110,6 @@ func (cms Store) TracingEnabled() bool {
110110
return cms.traceWriter != nil
111111
}
112112

113-
// LatestVersion returns the branch version of the store
114-
func (cms Store) LatestVersion() int64 {
115-
panic("cannot get latest version from branch cached multi-store")
116-
}
117-
118113
// GetStoreType returns the type of the store.
119114
func (cms Store) GetStoreType() types.StoreType {
120115
return types.StoreTypeMulti
@@ -138,15 +133,6 @@ func (cms Store) CacheMultiStore() types.CacheMultiStore {
138133
return newCacheMultiStoreFromCMS(cms)
139134
}
140135

141-
// CacheMultiStoreWithVersion implements the MultiStore interface. It will panic
142-
// as an already cached multi-store cannot load previous versions.
143-
//
144-
// TODO: The store implementation can possibly be modified to support this as it
145-
// seems safe to load previous versions (heights).
146-
func (cms Store) CacheMultiStoreWithVersion(_ int64) (types.CacheMultiStore, error) {
147-
panic("cannot branch cached multi-store with a version")
148-
}
149-
150136
// GetStore returns an underlying Store by key.
151137
func (cms Store) GetStore(key types.StoreKey) types.Store {
152138
s := cms.stores[key]

store/types/store.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,6 @@ type MultiStore interface {
120120
// call CacheMultiStore.Write().
121121
CacheMultiStore() CacheMultiStore
122122

123-
// CacheMultiStoreWithVersion branches the underlying MultiStore where
124-
// each stored is loaded at a specific version (height).
125-
CacheMultiStoreWithVersion(version int64) (CacheMultiStore, error)
126-
127123
// Convenience for fetching substores.
128124
// If the store does not exist, panics.
129125
GetStore(StoreKey) Store
@@ -142,6 +138,14 @@ type MultiStore interface {
142138
// implied that the caller should update the context when necessary between
143139
// tracing operations. The modified MultiStore is returned.
144140
SetTracingContext(TraceContext) MultiStore
141+
}
142+
143+
type RootMultiStore interface {
144+
MultiStore
145+
146+
// CacheMultiStoreWithVersion branches the underlying MultiStore where
147+
// each stored is loaded at a specific version (height).
148+
CacheMultiStoreWithVersion(version int64) (CacheMultiStore, error)
145149

146150
// LatestVersion returns the latest version in the store
147151
LatestVersion() int64
@@ -156,7 +160,7 @@ type CacheMultiStore interface {
156160
// CommitMultiStore is an interface for a MultiStore without cache capabilities.
157161
type CommitMultiStore interface {
158162
Committer
159-
MultiStore
163+
RootMultiStore
160164
snapshottypes.Snapshotter
161165

162166
// Mount a store of type using the given db.

0 commit comments

Comments
 (0)