Skip to content

Commit

Permalink
Problem: CacheWrapWithTrace api is not used (#207)
Browse files Browse the repository at this point in the history
Solution:
- remove the api

changelog
  • Loading branch information
yihuang authored and dudong2 committed Oct 30, 2024
1 parent 10954ab commit f092d70
Show file tree
Hide file tree
Showing 19 changed files with 5 additions and 99 deletions.
8 changes: 0 additions & 8 deletions store/cachekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cachekv

import (
"bytes"
"io"
"sort"
"sync"

Expand All @@ -12,8 +11,6 @@ import (
"cosmossdk.io/store/cachekv/internal"
"cosmossdk.io/store/internal/btree"
"cosmossdk.io/store/internal/conv"
"cosmossdk.io/store/internal/kv"
"cosmossdk.io/store/tracekv"
"cosmossdk.io/store/types"
)

Expand Down Expand Up @@ -198,11 +195,6 @@ func (store *GStore[V]) CacheWrap() types.CacheWrap {
return NewGStore(store, store.isZero, store.valueLen)
}

// CacheWrapWithTrace implements the CacheWrapper interface.
func (store *Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
return NewStore(tracekv.NewStore(store, w, tc))
}

//----------------------------------------
// Iteration

Expand Down
5 changes: 0 additions & 5 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,6 @@ func (cms Store) CacheWrap() types.CacheWrap {
return cms.CacheMultiStore().(types.CacheWrap)
}

// CacheWrapWithTrace implements the CacheWrapper interface.
func (cms Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap {
return cms.CacheWrap()
}

// Implements MultiStore.
func (cms Store) CacheMultiStore() types.CacheMultiStore {
return newCacheMultiStoreFromCMS(cms)
Expand Down
8 changes: 0 additions & 8 deletions store/dbadapter/store.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package dbadapter

import (
"io"

dbm "github.com/cosmos/cosmos-db"

"cosmossdk.io/store/cachekv"
"cosmossdk.io/store/tracekv"
"cosmossdk.io/store/types"
)

Expand Down Expand Up @@ -81,10 +78,5 @@ func (dsa Store) CacheWrap() types.CacheWrap {
return cachekv.NewStore(dsa)
}

// CacheWrapWithTrace implements KVStore.
func (dsa Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
return cachekv.NewStore(tracekv.NewStore(dsa, w, tc))
}

// dbm.DB implements KVStore so we can CacheKVStore it.
var _ types.KVStore = Store{}
3 changes: 0 additions & 3 deletions store/dbadapter/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,4 @@ func TestCacheWraps(t *testing.T) {

cacheWrapper := store.CacheWrap()
require.IsType(t, &cachekv.Store{}, cacheWrapper)

cacheWrappedWithTrace := store.CacheWrapWithTrace(nil, nil)
require.IsType(t, &cachekv.Store{}, cacheWrappedWithTrace)
}
7 changes: 0 additions & 7 deletions store/gaskv/store.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package gaskv

import (
"io"

"cosmossdk.io/store/types"
)

Expand Down Expand Up @@ -126,11 +124,6 @@ func (gs *GStore[V]) CacheWrap() types.CacheWrap {
panic("cannot CacheWrap a GasKVStore")
}

// CacheWrapWithTrace implements the KVStore interface.
func (gs *Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap {
panic("cannot CacheWrapWithTrace a GasKVStore")
}

func (gs *GStore[V]) iterator(start, end []byte, ascending bool) types.GIterator[V] {
var parent types.GIterator[V]
if ascending {
Expand Down
1 change: 0 additions & 1 deletion store/gaskv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestGasKVStoreBasic(t *testing.T) {

require.Equal(t, types.StoreTypeDB, st.GetStoreType())
require.Panics(t, func() { st.CacheWrap() })
require.Panics(t, func() { st.CacheWrapWithTrace(nil, nil) })

require.Panics(t, func() { st.Set(nil, []byte("value")) }, "setting a nil key should panic")
require.Panics(t, func() { st.Set([]byte(""), []byte("value")) }, "setting an empty key should panic")
Expand Down
7 changes: 0 additions & 7 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package iavl
import (
"errors"
"fmt"
"io"

cmtprotocrypto "github.com/cometbft/cometbft/proto/tendermint/crypto"
dbm "github.com/cosmos/cosmos-db"
Expand All @@ -16,7 +15,6 @@ import (
"cosmossdk.io/store/internal/kv"
"cosmossdk.io/store/metrics"
pruningtypes "cosmossdk.io/store/pruning/types"
"cosmossdk.io/store/tracekv"
"cosmossdk.io/store/types"
"cosmossdk.io/store/wrapper"
)
Expand Down Expand Up @@ -179,11 +177,6 @@ func (st *Store) CacheWrap() types.CacheWrap {
return cachekv.NewStore(st)
}

// CacheWrapWithTrace implements the Store interface.
func (st *Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
return cachekv.NewStore(tracekv.NewStore(st, w, tc))
}

// Implements types.KVStore.
func (st *Store) Set(key, value []byte) {
types.AssertValidKey(key)
Expand Down
3 changes: 0 additions & 3 deletions store/iavl/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,9 +663,6 @@ func TestCacheWraps(t *testing.T) {

cacheWrapper := store.CacheWrap()
require.IsType(t, &cachekv.Store{}, cacheWrapper)

cacheWrappedWithTrace := store.CacheWrapWithTrace(nil, nil)
require.IsType(t, &cachekv.Store{}, cacheWrappedWithTrace)
}

func TestChangeSets(t *testing.T) {
Expand Down
8 changes: 0 additions & 8 deletions store/listenkv/store.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package listenkv

import (
"io"

"cosmossdk.io/store/cachekv"
"cosmossdk.io/store/types"
)
Expand Down Expand Up @@ -135,9 +133,3 @@ func (s *Store) GetStoreType() types.StoreType {
func (s *Store) CacheWrap() types.CacheWrap {
return cachekv.NewStore(s)
}

// CacheWrapWithTrace implements the KVStore interface. It panics as a
// Store cannot be cache wrapped.
func (s *Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap {
panic("cannot CacheWrapWithTrace a ListenKVStore")
}
5 changes: 0 additions & 5 deletions store/listenkv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,3 @@ func TestListenKVStoreCacheWrap(t *testing.T) {
store := newEmptyListenKVStore(nil)
store.CacheWrap()
}

func TestListenKVStoreCacheWrapWithTrace(t *testing.T) {
store := newEmptyListenKVStore(nil)
require.Panics(t, func() { store.CacheWrapWithTrace(nil, nil) })
}
3 changes: 0 additions & 3 deletions store/mem/mem_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ func TestStore(t *testing.T) {

cacheWrapper := db.CacheWrap()
require.IsType(t, &cachekv.Store{}, cacheWrapper)

cacheWrappedWithTrace := db.CacheWrapWithTrace(nil, nil)
require.IsType(t, &cachekv.Store{}, cacheWrappedWithTrace)
}

func TestCommit(t *testing.T) {
Expand Down
8 changes: 0 additions & 8 deletions store/mem/store.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package mem

import (
"io"

dbm "github.com/cosmos/cosmos-db"

"cosmossdk.io/store/cachekv"
"cosmossdk.io/store/dbadapter"
pruningtypes "cosmossdk.io/store/pruning/types"
"cosmossdk.io/store/tracekv"
"cosmossdk.io/store/types"
)

Expand Down Expand Up @@ -41,11 +38,6 @@ func (s Store) CacheWrap() types.CacheWrap {
return cachekv.NewStore(s)
}

// CacheWrapWithTrace implements KVStore.
func (s Store) CacheWrapWithTrace(w io.Writer, tc types.TraceContext) types.CacheWrap {
return cachekv.NewStore(tracekv.NewStore(s, w, tc))
}

// Commit performs a no-op as entries are persistent between commitments.
func (s *Store) Commit() (id types.CommitID) { return }

Expand Down
7 changes: 0 additions & 7 deletions store/prefix/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ package prefix
import (
"bytes"
"errors"
"io"

"cosmossdk.io/store/cachekv"
"cosmossdk.io/store/tracekv"
"cosmossdk.io/store/types"
)

Expand Down Expand Up @@ -52,11 +50,6 @@ func (s Store) CacheWrap() types.CacheWrap {
return cachekv.NewStore(s)
}

// 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))
}

// Implements KVStore
func (s Store) Get(key []byte) []byte {
res := s.parent.Get(s.key(key))
Expand Down
3 changes: 0 additions & 3 deletions store/prefix/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,4 @@ func TestCacheWraps(t *testing.T) {

cacheWrapper := store.CacheWrap()
require.IsType(t, &cachekv.Store{}, cacheWrapper)

cacheWrappedWithTrace := store.CacheWrapWithTrace(nil, nil)
require.IsType(t, &cachekv.Store{}, cacheWrappedWithTrace)
}
5 changes: 0 additions & 5 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,11 +550,6 @@ func (rs *Store) CacheWrap() types.CacheWrap {
return rs.CacheMultiStore().(types.CacheWrap)
}

// CacheWrapWithTrace implements the CacheWrapper interface.
func (rs *Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap {
return rs.CacheWrap()
}

// CacheMultiStore creates ephemeral branch of the multi-store and returns a CacheMultiStore.
// It implements the MultiStore interface.
func (rs *Store) CacheMultiStore() types.CacheMultiStore {
Expand Down
6 changes: 2 additions & 4 deletions store/rootmulti/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
sdkmaps "cosmossdk.io/store/internal/maps"
"cosmossdk.io/store/metrics"
pruningtypes "cosmossdk.io/store/pruning/types"
"cosmossdk.io/store/tracekv"
"cosmossdk.io/store/types"
)

Expand Down Expand Up @@ -690,9 +691,6 @@ func TestCacheWraps(t *testing.T) {

cacheWrapper := multi.CacheWrap()
require.IsType(t, cachemulti.Store{}, cacheWrapper)

cacheWrappedWithTrace := multi.CacheWrapWithTrace(nil, nil)
require.IsType(t, cachemulti.Store{}, cacheWrappedWithTrace)
}

func TestTraceConcurrency(t *testing.T) {
Expand All @@ -710,7 +708,7 @@ func TestTraceConcurrency(t *testing.T) {

cms := multi.CacheMultiStore()
store1 := cms.GetKVStore(key)
cw := store1.CacheWrapWithTrace(b, tc)
cw := tracekv.NewStore(store1.CacheWrap().(types.KVStore), b, tc)
_ = cw
require.NotNil(t, store1)

Expand Down
6 changes: 0 additions & 6 deletions store/tracekv/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,6 @@ func (tkv *Store) CacheWrap() types.CacheWrap {
return cachekv.NewStore(tkv)
}

// CacheWrapWithTrace implements the KVStore interface. It panics as a
// Store cannot be branched.
func (tkv *Store) CacheWrapWithTrace(_ io.Writer, _ types.TraceContext) types.CacheWrap {
panic("cannot CacheWrapWithTrace a TraceKVStore")
}

// writeOperation writes a KVStore operation to the underlying io.Writer as
// JSON-encoded data where the key/value pair is base64 encoded.
func writeOperation(w io.Writer, op operation, tc types.TraceContext, key, value []byte) {
Expand Down
5 changes: 0 additions & 5 deletions store/tracekv/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,8 +285,3 @@ func TestTraceKVStoreCacheWrap(t *testing.T) {
store := newEmptyTraceKVStore(nil)
store.CacheWrap()
}

func TestTraceKVStoreCacheWrapWithTrace(t *testing.T) {
store := newEmptyTraceKVStore(nil)
require.Panics(t, func() { store.CacheWrapWithTrace(nil, nil) })
}
6 changes: 3 additions & 3 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -333,14 +333,14 @@ type CacheWrap interface {

// Write syncs with the underlying store.
Write()

// CacheWrap recursively wraps again.
CacheWrap() CacheWrap
}

type CacheWrapper interface {
// CacheWrap branches a store.
CacheWrap() CacheWrap

// CacheWrapWithTrace branches a store with tracing enabled.
CacheWrapWithTrace(w io.Writer, tc TraceContext) CacheWrap
}

func (cid CommitID) IsZero() bool {
Expand Down

0 comments on commit f092d70

Please sign in to comment.