Skip to content

Commit 05863f6

Browse files
mmsqeHuangYi
andauthored
Problem: CacheWrapWithTrace is not supported (#1043)
* Revert "Problem: CacheWrapWithTrace api is not used (#207)" This reverts commit 56cb96c. * resolve * cleanup * fix cyclic dependency * fix test * better equavalence --------- Co-authored-by: HuangYi <[email protected]>
1 parent d9bb1b6 commit 05863f6

File tree

23 files changed

+126
-4
lines changed

23 files changed

+126
-4
lines changed

runtime/store.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package runtime
22

33
import (
44
"context"
5+
"io"
56

67
"cosmossdk.io/core/store"
78
storetypes "cosmossdk.io/store/types"
@@ -109,6 +110,10 @@ func (kvStoreAdapter) CacheWrap() storetypes.CacheWrap {
109110
panic("unimplemented")
110111
}
111112

113+
func (kvStoreAdapter) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap {
114+
panic("unimplemented")
115+
}
116+
112117
func (kvStoreAdapter) GetStoreType() storetypes.StoreType {
113118
panic("unimplemented")
114119
}

server/mock/store.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ func (ms multiStore) CacheWrap() storetypes.CacheWrap {
3030
panic("not implemented")
3131
}
3232

33+
func (ms multiStore) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap {
34+
panic("unimplemented")
35+
}
36+
3337
func (ms multiStore) TracingEnabled() bool {
3438
panic("not implemented")
3539
}
@@ -178,6 +182,10 @@ func (kv kvStore) CacheWrap() storetypes.CacheWrap {
178182
panic("not implemented")
179183
}
180184

185+
func (kv kvStore) CacheWrapWithTrace(w io.Writer, tc storetypes.TraceContext) storetypes.CacheWrap {
186+
panic("unimplemented")
187+
}
188+
181189
func (kv kvStore) GetStoreType() storetypes.StoreType {
182190
panic("not implemented")
183191
}

store/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
3535
* [#243](https://github.com/crypto-org-chain/cosmos-sdk/pull/243) Support `RunAtomic` API to use new CoW cache store.
3636
* [#244](https://github.com/crypto-org-chain/cosmos-sdk/pull/244) Add `Discard` method to CacheWrap to discard the write buffer.
3737
* [#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.
38+
* [#1043](https://github.com/crypto-org-chain/cosmos-sdk/pull/1043) Add back CacheWrapWithTrace api.
3839

3940
## [Unreleased]
4041

store/cachekv/store.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package cachekv
22

33
import (
4+
"io"
5+
46
"cosmossdk.io/store/cachekv/internal"
57
"cosmossdk.io/store/internal/btree"
68
"cosmossdk.io/store/types"
@@ -128,6 +130,11 @@ func (store *GStore[V]) CacheWrap() types.CacheWrap {
128130
return NewGStore(store, store.isZero, store.valueLen)
129131
}
130132

133+
// CacheWrapWithTrace implements the CacheWrapper interface.
134+
func (store *GStore[V]) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
135+
panic("cannot CacheWrapWithTrace a cachekv Store")
136+
}
137+
131138
//----------------------------------------
132139
// Iteration
133140

store/cachemulti/store.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,11 @@ func (cms Store) CacheWrap() types.CacheWrap {
145145
return cms.CacheMultiStore().(types.CacheWrap)
146146
}
147147

148+
// CacheWrapWithTrace implements the CacheWrapper interface.
149+
func (cms Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap {
150+
return cms.CacheWrap()
151+
}
152+
148153
// Implements MultiStore.
149154
func (cms Store) CacheMultiStore() types.CacheMultiStore {
150155
return NewFromParent(cms.getCacheWrapper, cms.traceWriter, cms.traceContext)

store/dbadapter/store.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package dbadapter
22

33
import (
4+
"io"
5+
46
dbm "github.com/cosmos/cosmos-db"
57

68
"cosmossdk.io/store/cachekv"
9+
"cosmossdk.io/store/tracekv"
710
"cosmossdk.io/store/types"
811
)
912

@@ -78,5 +81,10 @@ func (dsa Store) CacheWrap() types.CacheWrap {
7881
return cachekv.NewStore(dsa)
7982
}
8083

84+
// CacheWrapWithTrace implements KVStore.
85+
func (dsa Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
86+
return cachekv.NewStore(tracekv.NewStore(dsa, w, tc))
87+
}
88+
8189
// dbm.DB implements KVStore so we can CacheKVStore it.
8290
var _ types.KVStore = Store{}

store/dbadapter/store_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,7 @@ func TestCacheWraps(t *testing.T) {
8080

8181
cacheWrapper := store.CacheWrap()
8282
require.IsType(t, &cachekv.Store{}, cacheWrapper)
83+
84+
cacheWrappedWithTrace := store.CacheWrapWithTrace(nil, nil)
85+
require.IsType(t, &cachekv.Store{}, cacheWrappedWithTrace)
8386
}

store/gaskv/store.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
package gaskv
22

3-
import "cosmossdk.io/store/types"
3+
import (
4+
"io"
5+
6+
"cosmossdk.io/store/types"
7+
)
48

59
// ObjectValueLength is the emulated number of bytes for storing transient objects in gas accounting.
610
const ObjectValueLength = 16
@@ -115,6 +119,11 @@ func (gs *GStore[V]) CacheWrap() types.CacheWrap {
115119
panic("cannot CacheWrap a GasKVStore")
116120
}
117121

122+
// CacheWrapWithTrace implements the KVStore interface.
123+
func (gs *GStore[V]) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap {
124+
panic("cannot CacheWrapWithTrace a GasKVStore")
125+
}
126+
118127
func (gs *GStore[V]) iterator(start, end []byte, ascending bool) types.GIterator[V] {
119128
var parent types.GIterator[V]
120129
if ascending {

store/gaskv/store_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ func TestGasKVStoreBasic(t *testing.T) {
2424

2525
require.Equal(t, types.StoreTypeDB, st.GetStoreType())
2626
require.Panics(t, func() { st.CacheWrap() })
27+
require.Panics(t, func() { st.CacheWrapWithTrace(nil, nil) })
2728

2829
require.Panics(t, func() { st.Set(nil, []byte("value")) }, "setting a nil key should panic")
2930
require.Panics(t, func() { st.Set([]byte(""), []byte("value")) }, "setting an empty key should panic")

store/iavl/store.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package iavl
33
import (
44
"errors"
55
"fmt"
6+
"io"
67

78
cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
89
dbm "github.com/cosmos/cosmos-db"
@@ -15,6 +16,7 @@ import (
1516
"cosmossdk.io/store/internal/kv"
1617
"cosmossdk.io/store/metrics"
1718
pruningtypes "cosmossdk.io/store/pruning/types"
19+
"cosmossdk.io/store/tracekv"
1820
"cosmossdk.io/store/types"
1921
"cosmossdk.io/store/wrapper"
2022
)
@@ -191,6 +193,11 @@ func (st *Store) CacheWrap() types.CacheWrap {
191193
return cachekv.NewStore(st)
192194
}
193195

196+
// CacheWrapWithTrace implements the Store interface.
197+
func (st *Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
198+
return cachekv.NewStore(tracekv.NewStore(st, w, tc))
199+
}
200+
194201
// Implements types.KVStore.
195202
func (st *Store) Set(key, value []byte) {
196203
types.AssertValidKey(key)

0 commit comments

Comments
 (0)