Skip to content
Merged
6 changes: 3 additions & 3 deletions types/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,20 +278,20 @@ func (c Context) Value(key interface{}) interface{} {

// KVStore fetches a KVStore from the MultiStore.
func (c Context) KVStore(key storetypes.StoreKey) KVStore {
Comment thread
testinginprod marked this conversation as resolved.
return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), c.kvGasConfig)
return gaskv.NewStore(c.ms.GetKVStore(key), c.gasMeter, c.kvGasConfig)
}

// TransientStore fetches a TransientStore from the MultiStore.
func (c Context) TransientStore(key storetypes.StoreKey) KVStore {
return gaskv.NewStore(c.MultiStore().GetKVStore(key), c.GasMeter(), c.transientKVGasConfig)
return gaskv.NewStore(c.ms.GetKVStore(key), c.gasMeter, c.transientKVGasConfig)
}

// CacheContext returns a new Context with the multi-store cached and a new
// EventManager. The cached context is written to the context when writeCache
// is called. Note, events are automatically emitted on the parent context's
// EventManager when the caller executes the write.
func (c Context) CacheContext() (cc Context, writeCache func()) {
cms := c.MultiStore().CacheMultiStore()
cms := c.ms.CacheMultiStore()
cc = c.WithMultiStore(cms).WithEventManager(NewEventManager())

writeCache = func() {
Comment on lines 290 to 297

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change potentially affects state.

Call sequence:

(github.com/cosmos/cosmos-sdk/types.Context).CacheContext (types/context.go:293)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).getContextForTx (types/context.go:570)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).runTx (types/context.go:618)
(*github.com/cosmos/cosmos-sdk/baseapp.BaseApp).DeliverTx (types/context.go:326)

Expand Down
41 changes: 41 additions & 0 deletions types/context_bench_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package types_test

import (
"testing"

"github.com/cosmos/cosmos-sdk/store/types"
"github.com/cosmos/cosmos-sdk/testutil"
)

func BenchmarkContext_KVStore(b *testing.B) {
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext")

ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name()))

b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ctx.KVStore(key)
}
}

func BenchmarkContext_TransientStore(b *testing.B) {
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext")

ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name()))

b.ResetTimer()
for i := 0; i < b.N; i++ {
_ = ctx.TransientStore(key)
}
}

func BenchmarkContext_CacheContext(b *testing.B) {
key := types.NewKVStoreKey(b.Name() + "_TestCacheContext")

ctx := testutil.DefaultContext(key, types.NewTransientStoreKey("transient_"+b.Name()))

b.ResetTimer()
for i := 0; i < b.N; i++ {
_, _ = ctx.CacheContext()
}
}