Skip to content

Commit

Permalink
chore: backport tracekvstore store_name (cosmos#14159)
Browse files Browse the repository at this point in the history
* feat: add store name in `tracekv`-emitted store traces (cosmos#11646)

* feature: Clone and Merge methods on TraceContext

* chore: use TraceContext.Merge method in SetTracingContext

* feature: add Store name in TraceContext during execution

* chore: update rootmulti Store TraceContext on *Store after Merge()

* add changelog entry

Co-authored-by: Gianguido Sorà <[email protected]>
  • Loading branch information
2 people authored and JeancarloBarrios committed Sep 28, 2024
1 parent 9215abb commit 09a3352
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 30 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Ref: https://keepachangelog.com/en/1.0.0/

### Improvements


* (store) [#11646](https://github.com/cosmos/cosmos-sdk/pull/11646) Add store name in tracekv-emitted store traces
* (deps) Bump Tendermint version to [v0.34.24](https://github.com/tendermint/tendermint/releases/tag/v0.34.24).

## v0.45.11 - 2022-11-09
Expand Down
6 changes: 5 additions & 1 deletion store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func NewFromKVStore(

for key, store := range stores {
if cms.TracingEnabled() {
store = tracekv.NewStore(store.(types.KVStore), cms.traceWriter, cms.traceContext)
tctx := cms.traceContext.Clone().Merge(types.TraceContext{
storeNameCtxKey: key.Name(),
})

store = tracekv.NewStore(store.(types.KVStore), cms.traceWriter, tctx)
}
if cms.ListeningEnabled(key) {
store = listenkv.NewStore(store.(types.KVStore), key, listeners[key])
Expand Down
8 changes: 1 addition & 7 deletions store/rootmulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,13 +342,7 @@ func (rs *Store) SetTracer(w io.Writer) types.MultiStore {
func (rs *Store) SetTracingContext(tc types.TraceContext) types.MultiStore {
rs.traceContextMutex.Lock()
defer rs.traceContextMutex.Unlock()
if rs.traceContext != nil {
for k, v := range tc {
rs.traceContext[k] = v
}
} else {
rs.traceContext = tc
}
rs.traceContext = rs.traceContext.Merge(tc)

return rs
}
Expand Down
22 changes: 0 additions & 22 deletions store/types/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,6 @@ func TestTransientStoreKey(t *testing.T) {
require.Equal(t, fmt.Sprintf("TransientStoreKey{%p, test}", key), key.String())
}

func TestMemoryStoreKey(t *testing.T) {
t.Parallel()
key := NewMemoryStoreKey("test")
require.Equal(t, "test", key.name)
require.Equal(t, key.name, key.Name())
require.Equal(t, fmt.Sprintf("MemoryStoreKey{%p, test}", key), key.String())
}

func TestTraceContext_Clone(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -223,17 +215,3 @@ func TestTraceContext_Merge(t *testing.T) {
})
}
}

func TestNewTransientStoreKeys(t *testing.T) {
assert.DeepEqual(t, map[string]*TransientStoreKey{}, NewTransientStoreKeys())
assert.DeepEqual(t, 1, len(NewTransientStoreKeys("one")))
}

func TestNewInfiniteGasMeter(t *testing.T) {
gm := NewInfiniteGasMeter()
require.NotNil(t, gm)
}

func TestStoreTypes(t *testing.T) {
assert.DeepEqual(t, InclusiveEndBytes([]byte("endbytes")), InclusiveEndBytes([]byte("endbytes")))
}

0 comments on commit 09a3352

Please sign in to comment.