From 38fc4cc39495576dd877cac6813555c90e016963 Mon Sep 17 00:00:00 2001 From: mmsqe Date: Thu, 12 Dec 2024 18:15:25 +0800 Subject: [PATCH] resolve --- runtime/store.go | 5 +++++ server/mock/store.go | 8 ++++++++ store/CHANGELOG.md | 1 + store/cachekv/store.go | 7 +++++-- store/gaskv/store.go | 2 +- store/internal/btreeadaptor.go | 7 +++++++ store/prefix/store.go | 7 +++++-- store/tracekv/store.go | 3 +-- store/types/store.go | 3 +++ 9 files changed, 36 insertions(+), 7 deletions(-) diff --git a/runtime/store.go b/runtime/store.go index 965bdafd7372..9a956d4459e8 100644 --- a/runtime/store.go +++ b/runtime/store.go @@ -2,6 +2,7 @@ package runtime import ( "context" + "io" "cosmossdk.io/core/store" storetypes "cosmossdk.io/store/types" @@ -109,6 +110,10 @@ func (kvStoreAdapter) CacheWrap() storetypes.CacheWrap { panic("unimplemented") } +func (kvStoreAdapter) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { + panic("unimplemented") +} + func (kvStoreAdapter) GetStoreType() storetypes.StoreType { panic("unimplemented") } diff --git a/server/mock/store.go b/server/mock/store.go index 45ff433193a2..7344fff610cb 100644 --- a/server/mock/store.go +++ b/server/mock/store.go @@ -30,6 +30,10 @@ func (ms multiStore) CacheWrap() storetypes.CacheWrap { panic("not implemented") } +func (ms multiStore) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { + panic("unimplemented") +} + func (ms multiStore) TracingEnabled() bool { panic("not implemented") } @@ -178,6 +182,10 @@ func (kv kvStore) CacheWrap() storetypes.CacheWrap { panic("not implemented") } +func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap { + panic("unimplemented") +} + func (kv kvStore) GetStoreType() storetypes.StoreType { panic("not implemented") } diff --git a/store/CHANGELOG.md b/store/CHANGELOG.md index df5fbe76d050..e275931f39c9 100644 --- a/store/CHANGELOG.md +++ b/store/CHANGELOG.md @@ -35,6 +35,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ * [#243](https://github.com/crypto-org-chain/cosmos-sdk/pull/243) Support `RunAtomic` API to use new CoW cache store. * [#244](https://github.com/crypto-org-chain/cosmos-sdk/pull/244) Add `Discard` method to CacheWrap to discard the write buffer. * [#258](https://github.com/crypto-org-chain/cosmos-sdk/pull/258) Add `NewFromParent` API to cachemulti store to create a new store from block-stm multiversion data structure. +* [#1043](https://github.com/crypto-org-chain/cosmos-sdk/pull/1043) Add back CacheWrapWithTrace api. ## [Unreleased] diff --git a/store/cachekv/store.go b/store/cachekv/store.go index 1c10315959c9..084adef7cd79 100644 --- a/store/cachekv/store.go +++ b/store/cachekv/store.go @@ -132,8 +132,11 @@ func (store *GStore[V]) CacheWrap() types.CacheWrap { } // CacheWrapWithTrace implements the CacheWrapper interface. -func (store *Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap { - return NewStore(tracekv.NewStore(store, w, tc)) +func (store *GStore[V]) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap { + if store, ok := any(store).(*GStore[[]byte]); ok { + return NewStore(tracekv.NewStore(store, w, tc)) + } + return store.CacheWrap() } //---------------------------------------- diff --git a/store/gaskv/store.go b/store/gaskv/store.go index efc14c988c29..f1d71d151c46 100644 --- a/store/gaskv/store.go +++ b/store/gaskv/store.go @@ -120,7 +120,7 @@ func (gs *GStore[V]) CacheWrap() types.CacheWrap { } // CacheWrapWithTrace implements the KVStore interface. -func (gs *Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap { +func (gs *GStore[V]) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap { panic("cannot CacheWrapWithTrace a GasKVStore") } diff --git a/store/internal/btreeadaptor.go b/store/internal/btreeadaptor.go index dbc212779177..c4b3b9b25b50 100644 --- a/store/internal/btreeadaptor.go +++ b/store/internal/btreeadaptor.go @@ -1,6 +1,8 @@ package internal import ( + "io" + "cosmossdk.io/store/cachekv" "cosmossdk.io/store/internal/btree" "cosmossdk.io/store/types" @@ -59,3 +61,8 @@ func (ts *BTreeStore[V]) GetStoreType() types.StoreType { func (ts *BTreeStore[V]) CacheWrap() types.CacheWrap { return cachekv.NewGStore(ts, ts.isZero, ts.valueLen) } + +// CacheWrapWithTrace branches the underlying store. +func (ts *BTreeStore[V]) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap { + return cachekv.NewGStore(ts, ts.isZero, ts.valueLen) +} diff --git a/store/prefix/store.go b/store/prefix/store.go index 775636ef88b2..0adbe5aaae1a 100644 --- a/store/prefix/store.go +++ b/store/prefix/store.go @@ -86,8 +86,11 @@ func (s GStore[V]) CacheWrap() types.CacheWrap { } // CacheWrapWithTrace implements the KVStore interface. -func (s Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap { - return cachekv.NewStore(tracekv.NewStore(s, w, tc)) +func (s GStore[V]) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap { + if store, ok := any(s).(*GStore[[]byte]); ok { + return cachekv.NewGStore(tracekv.NewStore(store, w, tc), store.isZero, store.valueLen) + } + return s.CacheWrap() } // Implements KVStore diff --git a/store/tracekv/store.go b/store/tracekv/store.go index 9f101f0722b0..435bb8f7ae96 100644 --- a/store/tracekv/store.go +++ b/store/tracekv/store.go @@ -6,7 +6,6 @@ import ( "io" "cosmossdk.io/errors" - "cosmossdk.io/store/cachekv" "cosmossdk.io/store/types" ) @@ -165,7 +164,7 @@ func (tkv *Store) GetStoreType() types.StoreType { // CacheWrap implements the KVStore interface. It panics because a Store // cannot be branched. func (tkv *Store) CacheWrap() types.CacheWrap { - return cachekv.NewStore(tkv) + return tkv.parent.CacheWrap() } // CacheWrapWithTrace implements the KVStore interface. It panics as a diff --git a/store/types/store.go b/store/types/store.go index 5835e97da279..f716a6c0e306 100644 --- a/store/types/store.go +++ b/store/types/store.go @@ -353,6 +353,9 @@ type CacheWrap interface { // Discard the write set Discard() + + // CacheWrapWithTrace branches a store with tracing enabled. + CacheWrapWithTrace(w io.Writer, tc TraceContext) CacheWrap } type CacheWrapper interface {