@@ -26,6 +26,8 @@ and standard additions here would be better just to add to the Context struct
2626type Context struct {
2727 ctx context.Context
2828 ms MultiStore
29+ nextMs MultiStore // ms of the next height; only used in tracing
30+ nextStoreKeys map [string ]struct {} // store key names that should use nextMs
2931 header tmproto.Header
3032 headerHash tmbytes.HexBytes
3133 chainID string
@@ -505,6 +507,15 @@ func (c Context) WithIsTracing(it bool) Context {
505507 return c
506508}
507509
510+ func (c Context ) WithNextMs (ms MultiStore , nextStoreKeys []string ) Context {
511+ c .nextMs = ms
512+ c .nextStoreKeys = make (map [string ]struct {}, len (nextStoreKeys ))
513+ for _ , k := range nextStoreKeys {
514+ c .nextStoreKeys [k ] = struct {}{}
515+ }
516+ return c
517+ }
518+
508519// TODO: remove???
509520func (c Context ) IsZero () bool {
510521 return c .ms == nil
@@ -541,11 +552,21 @@ func (c Context) Value(key interface{}) interface{} {
541552
542553// KVStore fetches a KVStore from the MultiStore.
543554func (c Context ) KVStore (key StoreKey ) KVStore {
555+ if c .isTracing {
556+ if _ , ok := c .nextStoreKeys [key .Name ()]; ok {
557+ return gaskv .NewStore (c .nextMs .GetKVStore (key ), c .GasMeter (), stypes .KVGasConfig ())
558+ }
559+ }
544560 return gaskv .NewStore (c .MultiStore ().GetKVStore (key ), c .GasMeter (), stypes .KVGasConfig ())
545561}
546562
547563// TransientStore fetches a TransientStore from the MultiStore.
548564func (c Context ) TransientStore (key StoreKey ) KVStore {
565+ if c .isTracing {
566+ if _ , ok := c .nextStoreKeys [key .Name ()]; ok {
567+ return gaskv .NewStore (c .nextMs .GetKVStore (key ), c .GasMeter (), stypes .TransientGasConfig ())
568+ }
569+ }
549570 return gaskv .NewStore (c .MultiStore ().GetKVStore (key ), c .GasMeter (), stypes .TransientGasConfig ())
550571}
551572
0 commit comments