feat: support alternative query multistore (#13529)
* support customize query multistore * Update CHANGELOG.md * fix test * Update baseapp/abci.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> * Update baseapp/baseapp.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> * Update baseapp/options.go Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com> * Apply suggestions from code review Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Aleksandr Bezobchuk <alexanderbez@users.noreply.github.com>
This commit is contained in:
co-authored by
Aleksandr Bezobchuk
Marko
parent
ed9cd41396
commit
15accd76fc
@@ -152,6 +152,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
|
||||
|
||||
|
||||
+8
-2
@@ -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
|
||||
qms := app.qms
|
||||
if qms == nil {
|
||||
qms = app.cms.(sdk.MultiStore)
|
||||
}
|
||||
|
||||
lastBlockHeight := qms.LatestVersion()
|
||||
if height > lastBlockHeight {
|
||||
return sdk.Context{},
|
||||
sdkerrors.Wrap(
|
||||
@@ -665,7 +671,7 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e
|
||||
)
|
||||
}
|
||||
|
||||
cacheMS, err := app.cms.CacheMultiStoreWithVersion(height)
|
||||
cacheMS, err := qms.CacheMultiStoreWithVersion(height)
|
||||
if err != nil {
|
||||
return sdk.Context{},
|
||||
sdkerrors.Wrapf(
|
||||
|
||||
@@ -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 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
|
||||
|
||||
@@ -240,3 +240,10 @@ 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.
|
||||
//
|
||||
// Ref: https://github.com/cosmos/cosmos-sdk/issues/13317
|
||||
func (app *BaseApp) SetQueryMultiStore(ms sdk.MultiStore) {
|
||||
app.qms = ms
|
||||
}
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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()....
|
||||
|
||||
Reference in New Issue
Block a user