@@ -606,6 +606,36 @@ func (app *BaseApp) getBlockGasMeter(ctx sdk.Context) storetypes.GasMeter {
606606 return storetypes .NewInfiniteGasMeter ()
607607}
608608
609+ func (app * BaseApp ) getContextForTx (mode sdk.ExecMode , txBytes []byte , txIndex int ) sdk.Context {
610+ app .mu .Lock ()
611+ defer app .mu .Unlock ()
612+
613+ modeState := app .stateManager .GetState (mode )
614+ if modeState == nil {
615+ panic (fmt .Sprintf ("state is nil for mode %v" , mode ))
616+ }
617+ ctx := modeState .Context ().
618+ WithTxBytes (txBytes ).
619+ WithTxIndex (txIndex ).
620+ WithGasMeter (storetypes .NewInfiniteGasMeter ())
621+ // WithVoteInfos(app.voteInfos) // TODO: identify if this is needed
622+
623+ ctx = ctx .WithIsSigverifyTx (app .sigverifyTx )
624+
625+ ctx = ctx .WithConsensusParams (app .GetConsensusParams (ctx ))
626+
627+ if mode == execModeReCheck {
628+ ctx = ctx .WithIsReCheckTx (true )
629+ }
630+
631+ if mode == execModeSimulate {
632+ ctx , _ = ctx .CacheContext ()
633+ ctx = ctx .WithExecMode (execModeSimulate )
634+ }
635+
636+ return ctx
637+ }
638+
609639// cacheTxContext returns a new context based off of the provided context with
610640// a branched multi-store.
611641func (app * BaseApp ) cacheTxContext (ctx sdk.Context , txBytes []byte ) (sdk.Context , storetypes.CacheMultiStore ) {
@@ -671,6 +701,43 @@ func (app *BaseApp) beginBlock(_ *abci.RequestFinalizeBlock) (sdk.BeginBlock, er
671701 return resp , nil
672702}
673703
704+ func (app * BaseApp ) deliverTx (tx []byte , txMultiStore storetypes.MultiStore , txIndex int , incarnationCache map [string ]any ) * abci.ExecTxResult {
705+ gInfo := sdk.GasInfo {}
706+ resultStr := "successful"
707+
708+ var resp * abci.ExecTxResult
709+
710+ defer func () {
711+ telemetry .IncrCounter (1 , "tx" , "count" )
712+ telemetry .IncrCounter (1 , "tx" , resultStr )
713+ telemetry .SetGauge (float32 (gInfo .GasUsed ), "tx" , "gas" , "used" )
714+ telemetry .SetGauge (float32 (gInfo .GasWanted ), "tx" , "gas" , "wanted" )
715+ }()
716+
717+ gInfo , result , anteEvents , err := app .RunTx (execModeFinalize , tx , nil , txIndex , txMultiStore , incarnationCache )
718+ if err != nil {
719+ resultStr = "failed"
720+ resp = sdkerrors .ResponseExecTxResultWithEvents (
721+ err ,
722+ gInfo .GasWanted ,
723+ gInfo .GasUsed ,
724+ sdk .MarkEventsToIndex (anteEvents , app .indexEvents ),
725+ app .trace ,
726+ )
727+ return resp
728+ }
729+
730+ resp = & abci.ExecTxResult {
731+ GasWanted : int64 (gInfo .GasWanted ),
732+ GasUsed : int64 (gInfo .GasUsed ),
733+ Log : result .Log ,
734+ Data : result .Data ,
735+ Events : sdk .MarkEventsToIndex (result .Events , app .indexEvents ),
736+ }
737+
738+ return resp
739+ }
740+
674741// endBlock is an application-defined function that is called after transactions
675742// have been processed in FinalizeBlock.
676743func (app * BaseApp ) endBlock (_ context.Context ) (sdk.EndBlock , error ) {
@@ -896,73 +963,6 @@ func (app *BaseApp) RunTx(mode sdk.ExecMode, txBytes []byte, tx sdk.Tx, txIndex
896963 return gInfo , result , anteEvents , err
897964}
898965
899- func (app * BaseApp ) getContextForTx (mode sdk.ExecMode , txBytes []byte , txIndex int ) sdk.Context {
900- app .mu .Lock ()
901- defer app .mu .Unlock ()
902-
903- modeState := app .stateManager .GetState (mode )
904- if modeState == nil {
905- panic (fmt .Sprintf ("state is nil for mode %v" , mode ))
906- }
907- ctx := modeState .Context ().
908- WithTxBytes (txBytes ).
909- WithTxIndex (txIndex ).
910- WithGasMeter (storetypes .NewInfiniteGasMeter ())
911- // WithVoteInfos(app.voteInfos) // TODO: identify if this is needed
912-
913- ctx = ctx .WithIsSigverifyTx (app .sigverifyTx )
914-
915- ctx = ctx .WithConsensusParams (app .GetConsensusParams (ctx ))
916-
917- if mode == execModeReCheck {
918- ctx = ctx .WithIsReCheckTx (true )
919- }
920-
921- if mode == execModeSimulate {
922- ctx , _ = ctx .CacheContext ()
923- ctx = ctx .WithExecMode (execModeSimulate )
924- }
925-
926- return ctx
927- }
928-
929- func (app * BaseApp ) deliverTx (tx []byte , txMultiStore storetypes.MultiStore , txIndex int , incarnationCache map [string ]any ) * abci.ExecTxResult {
930- gInfo := sdk.GasInfo {}
931- resultStr := "successful"
932-
933- var resp * abci.ExecTxResult
934-
935- defer func () {
936- telemetry .IncrCounter (1 , "tx" , "count" )
937- telemetry .IncrCounter (1 , "tx" , resultStr )
938- telemetry .SetGauge (float32 (gInfo .GasUsed ), "tx" , "gas" , "used" )
939- telemetry .SetGauge (float32 (gInfo .GasWanted ), "tx" , "gas" , "wanted" )
940- }()
941-
942- gInfo , result , anteEvents , err := app .RunTx (execModeFinalize , tx , nil , txIndex , txMultiStore , incarnationCache )
943- if err != nil {
944- resultStr = "failed"
945- resp = sdkerrors .ResponseExecTxResultWithEvents (
946- err ,
947- gInfo .GasWanted ,
948- gInfo .GasUsed ,
949- sdk .MarkEventsToIndex (anteEvents , app .indexEvents ),
950- app .trace ,
951- )
952- return resp
953- }
954-
955- resp = & abci.ExecTxResult {
956- GasWanted : int64 (gInfo .GasWanted ),
957- GasUsed : int64 (gInfo .GasUsed ),
958- Log : result .Log ,
959- Data : result .Data ,
960- Events : sdk .MarkEventsToIndex (result .Events , app .indexEvents ),
961- }
962-
963- return resp
964- }
965-
966966// runMsgs iterates through a list of messages and executes them with the provided
967967// Context and execution mode. Messages will only be executed during simulation
968968// and DeliverTx. An error is returned if any single message fails or if a
@@ -978,7 +978,7 @@ func (app *BaseApp) runMsgs(ctx sdk.Context, msgs []sdk.Msg, msgsV2 []protov2.Me
978978 break
979979 }
980980
981- ctx .WithMsgIndex (i )
981+ ctx = ctx .WithMsgIndex (i )
982982
983983 handler := app .msgServiceRouter .Handler (msg )
984984 if handler == nil {
0 commit comments