From 532a6add3eeb755fb6ff51ffc78f28646dc98dcd Mon Sep 17 00:00:00 2001 From: Roy Crihfield Date: Tue, 15 Feb 2022 14:42:01 +0800 Subject: [PATCH] viewstore.CacheStore() replaces CacheMultiStoreWithVersion --- baseapp/abci.go | 6 ++---- baseapp/test_helpers.go | 2 +- store/v2/multi/cache_store.go | 5 ----- store/v2/multi/view_store.go | 4 +++- 4 files changed, 6 insertions(+), 11 deletions(-) diff --git a/baseapp/abci.go b/baseapp/abci.go index d039ee637510..299b21f4e466 100644 --- a/baseapp/abci.go +++ b/baseapp/abci.go @@ -17,7 +17,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" snapshottypes "github.com/cosmos/cosmos-sdk/snapshots/types" - "github.com/cosmos/cosmos-sdk/store/v2/multi" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" "github.com/cosmos/cosmos-sdk/types/tx" @@ -646,11 +645,10 @@ func (app *BaseApp) createQueryContext(height int64, prove bool) (sdk.Context, e "failed to load state at height %d; %s (latest height: %d)", height, err, app.LastBlockHeight(), ) } - cacheMS := multi.BasicAsCacheStore(version) - // branch the commit-multistore for safety ctx := sdk.NewContext( - cacheMS, app.checkState.ctx.BlockHeader(), true, app.logger, + version.CacheWrap(), // branch the commit-multistore for safety + app.checkState.ctx.BlockHeader(), true, app.logger, ).WithMinGasPrices(app.minGasPrices).WithBlockHeight(height) return ctx, nil diff --git a/baseapp/test_helpers.go b/baseapp/test_helpers.go index 28cac0c7308a..37ba5588848c 100644 --- a/baseapp/test_helpers.go +++ b/baseapp/test_helpers.go @@ -98,5 +98,5 @@ func (app *BaseApp) NewContextAt(isCheckTx bool, header tmproto.Header, height i if err != nil { return sdk.Context{}, err } - return sdk.NewContext(multi.BasicAsCacheStore(view), header, isCheckTx, app.logger), nil + return sdk.NewContext(view.CacheWrap(), header, isCheckTx, app.logger), nil } diff --git a/store/v2/multi/cache_store.go b/store/v2/multi/cache_store.go index a1c281a59e8c..5b2fc9014309 100644 --- a/store/v2/multi/cache_store.go +++ b/store/v2/multi/cache_store.go @@ -53,11 +53,6 @@ type noopCacheStore struct { func (noopCacheStore) Write() {} -// pretend basic store is cache store -func BasicAsCacheStore(bs types.MultiStore) types.CacheMultiStore { - return noopCacheStore{newCacheStore(bs)} -} - // pretend commit store is cache store func CommitAsCacheStore(s types.CommitMultiStore) types.CacheMultiStore { return noopCacheStore{newCacheStore(s)} diff --git a/store/v2/multi/view_store.go b/store/v2/multi/view_store.go index c51b1d065275..58c32c4c3ae8 100644 --- a/store/v2/multi/view_store.go +++ b/store/v2/multi/view_store.go @@ -63,8 +63,10 @@ func (vs *viewStore) getSubstore(key string) (*viewSubstore, error) { }, nil } +// CacheWrap implements MultiStore. +// Because this store is a read-only view, the returned store's Write operation is a no-op. func (vs *viewStore) CacheWrap() types.CacheMultiStore { - return newCacheStore(vs) + return noopCacheStore{newCacheStore(vs)} } func (s *viewSubstore) GetStateCommitmentStore() *smt.Store {