@@ -703,11 +703,21 @@ func (app *BaseApp) getContextForTx(mode execMode, txBytes []byte) sdk.Context {
703
703
return ctx
704
704
}
705
705
706
+ type poolingStore interface {
707
+ storetypes.MultiStore
708
+ CacheMultiStorePooled () storetypes.PooledCacheMultiStore
709
+ }
710
+
706
711
// cacheTxContext returns a new context based off of the provided context with
707
712
// a branched multi-store.
708
713
func (app * BaseApp ) cacheTxContext (ctx sdk.Context , txBytes []byte ) (sdk.Context , storetypes.CacheMultiStore ) {
709
714
ms := ctx .MultiStore ()
710
- msCache := ms .CacheMultiStore ()
715
+ var msCache storetypes.CacheMultiStore
716
+ if msPooled , ok := ms .(poolingStore ); ok {
717
+ msCache = msPooled .CacheMultiStorePooled ()
718
+ } else {
719
+ msCache = ms .CacheMultiStore ()
720
+ }
711
721
if msCache .TracingEnabled () {
712
722
msCache = msCache .SetTracingContext (
713
723
storetypes .TraceContext (
@@ -923,6 +933,9 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.G
923
933
// writes do not happen if aborted/failed. This may have some
924
934
// performance benefits, but it'll be more difficult to get right.
925
935
anteCtx , msCache = app .cacheTxContext (ctx , txBytes )
936
+ if pooledMSCache , ok := msCache .(storetypes.PooledCacheMultiStore ); ok {
937
+ defer pooledMSCache .Release ()
938
+ }
926
939
anteCtx = anteCtx .WithEventManager (sdk .NewEventManager ())
927
940
newCtx , err := app .anteHandler (anteCtx , tx , mode == execModeSimulate )
928
941
@@ -973,6 +986,9 @@ func (app *BaseApp) runTx(mode execMode, txBytes []byte, tx sdk.Tx) (gInfo sdk.G
973
986
// in case message processing fails. At this point, the MultiStore
974
987
// is a branch of a branch.
975
988
runMsgCtx , msCache := app .cacheTxContext (ctx , txBytes )
989
+ if pooledMSCache , ok := msCache .(storetypes.PooledCacheMultiStore ); ok {
990
+ defer pooledMSCache .Release ()
991
+ }
976
992
977
993
// Attempt to execute all messages and only update state if all messages pass
978
994
// and we're in DeliverTx. Note, runMsgs will never return a reference to a
0 commit comments