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: support alternative query multistore #13529

Merged
merged 9 commits into from
Oct 17, 2022
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (x/gov) [#13160](https://github.com/cosmos/cosmos-sdk/pull/13160) Remove custom marshaling of proposl and voteoption.
* (types) [#13430](https://github.com/cosmos/cosmos-sdk/pull/13430) Remove unused code `ResponseCheckTx` and `ResponseDeliverTx`
* (auth) [#13460](https://github.com/cosmos/cosmos-sdk/pull/13460) The `q auth address-by-id` CLI command has been renamed to `q auth address-by-acc-num` to be more explicit. However, the old `address-by-id` version is still kept as an alias, for backwards compatibility.
* (store) [#13529](https://github.com/cosmos/cosmos-sdk/pull/13529) Add method `LatestVersion` to `MultiStore` interface, add method `SetQueryMultiStore` to baesapp to support alternative `MultiStore` implementation for query service.

### CLI Breaking Changes

Expand Down
10 changes: 8 additions & 2 deletions baseapp/abci.go
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,13 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
return sdk.Context{}, err
}

lastBlockHeight := app.LastBlockHeight()
// use custom query multistore if provided
ms := app.qms
if ms == nil {
ms = app.cms.(sdk.MultiStore)
}
yihuang marked this conversation as resolved.
Show resolved Hide resolved

lastBlockHeight := ms.LatestVersion()
yihuang marked this conversation as resolved.
Show resolved Hide resolved
if height > lastBlockHeight {
return sdk.Context{},
sdkerrors.Wrap(
Expand All @@ -665,7 +671,7 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
)
}

cacheMS, err := app.cms.CacheMultiStoreWithVersion(height)
cacheMS, err := ms.CacheMultiStoreWithVersion(height)
yihuang marked this conversation as resolved.
Show resolved Hide resolved
yihuang marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return sdk.Context{},
sdkerrors.Wrapf(
Expand Down
1 change: 1 addition & 0 deletions baseapp/baseapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type BaseApp struct { //nolint: maligned
name string // application name from abci.Info
db dbm.DB // common DB backend
cms sdk.CommitMultiStore // Main (uncached) state
qms sdk.MultiStore // Optional alternative multistore for query purpose.
yihuang marked this conversation as resolved.
Show resolved Hide resolved
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
6 changes: 6 additions & 0 deletions baseapp/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,9 @@ func (app *BaseApp) SetStreamingService(s StreamingService) {
func (app *BaseApp) SetTxDecoder(txDecoder sdk.TxDecoder) {
app.txDecoder = txDecoder
}

// SetQueryMultiStore set a alternative MultiStore implementation to support grpc query service.
// see: https://github.com/cosmos/cosmos-sdk/issues/13317
yihuang marked this conversation as resolved.
Show resolved Hide resolved
func (app *BaseApp) SetQueryMultiStore(ms sdk.MultiStore) {
app.qms = ms
}
4 changes: 4 additions & 0 deletions server/mock/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ func (ms multiStore) RollbackToVersion(version int64) error {
panic("not implemented")
}

func (ms multiStore) LatestVersion() int64 {
panic("not implemented")
}

var _ sdk.KVStore = kvStore{}

type kvStore struct {
Expand Down
5 changes: 5 additions & 0 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ func (cms Store) ListeningEnabled(key types.StoreKey) bool {
return false
}

// 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 Down
5 changes: 5 additions & 0 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ func (rs *Store) ListeningEnabled(key types.StoreKey) bool {
return false
}

// LatestVersion returns the latest version in the store
func (rs *Store) LatestVersion() int64 {
return rs.LastCommitID().Version
}

// LastCommitID implements Committer/CommitStore.
func (rs *Store) LastCommitID() types.CommitID {
if rs.lastCommitInfo == nil {
Expand Down
3 changes: 3 additions & 0 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ type MultiStore interface {
// AddListeners adds WriteListeners for the KVStore belonging to the provided StoreKey
// It appends the listeners to a current set, if one already exists
AddListeners(key StoreKey, listeners []WriteListener)

// LatestVersion returns the latest version in the store
LatestVersion() int64
}

// From MultiStore.CacheMultiStore()....
Expand Down