@@ -336,11 +336,11 @@ func (app *BaseApp) ApplySnapshotChunk(req *abci.RequestApplySnapshotChunk) (*ab
336
336
func (app * BaseApp ) CheckTx (req * abci.RequestCheckTx ) (* abci.ResponseCheckTx , error ) {
337
337
var mode execMode
338
338
339
- switch {
340
- case req . Type == abci .CheckTxType_New :
339
+ switch req . Type {
340
+ case abci .CheckTxType_New :
341
341
mode = execModeCheck
342
342
343
- case req . Type == abci .CheckTxType_Recheck :
343
+ case abci .CheckTxType_Recheck :
344
344
mode = execModeReCheck
345
345
346
346
default :
@@ -775,48 +775,34 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request
775
775
776
776
// Reset the gas meter so that the AnteHandlers aren't required to
777
777
gasMeter = app .getBlockGasMeter (app .finalizeBlockState .Context ())
778
- app .finalizeBlockState .SetContext (app .finalizeBlockState .Context ().WithBlockGasMeter (gasMeter ))
778
+ app .finalizeBlockState .SetContext (
779
+ app .finalizeBlockState .Context ().
780
+ WithBlockGasMeter (gasMeter ).
781
+ WithTxCount (len (req .Txs )),
782
+ )
779
783
780
784
// Iterate over all raw transactions in the proposal and attempt to execute
781
785
// them, gathering the execution results.
782
786
//
783
787
// NOTE: Not all raw transactions may adhere to the sdk.Tx interface, e.g.
784
788
// vote extensions, so skip those.
785
- txResults := make ([]* abci.ExecTxResult , 0 , len (req .Txs ))
786
- for _ , rawTx := range req .Txs {
787
- var response * abci.ExecTxResult
788
-
789
- if _ , err := app .txDecoder (rawTx ); err == nil {
790
- response = app .deliverTx (rawTx )
791
- } else {
792
- // In the case where a transaction included in a block proposal is malformed,
793
- // we still want to return a default response to comet. This is because comet
794
- // expects a response for each transaction included in a block proposal.
795
- response = sdkerrors .ResponseExecTxResultWithEvents (
796
- sdkerrors .ErrTxDecode ,
797
- 0 ,
798
- 0 ,
799
- nil ,
800
- false ,
801
- )
802
- }
803
-
804
- // check after every tx if we should abort
805
- select {
806
- case <- ctx .Done ():
807
- return nil , ctx .Err ()
808
- default :
809
- // continue
810
- }
811
-
812
- txResults = append (txResults , response )
789
+ txResults , err := app .executeTxs (ctx , req .Txs )
790
+ if err != nil {
791
+ // usually due to canceled
792
+ return nil , err
813
793
}
814
794
815
795
if app .finalizeBlockState .ms .TracingEnabled () {
816
796
app .finalizeBlockState .ms = app .finalizeBlockState .ms .SetTracingContext (nil ).(storetypes.CacheMultiStore )
817
797
}
818
798
819
- endBlock , err := app .endBlock (app .finalizeBlockState .Context ())
799
+ var blockGasUsed uint64
800
+ for _ , res := range txResults {
801
+ blockGasUsed += uint64 (res .GasUsed )
802
+ }
803
+ sdkCtx := app .finalizeBlockState .Context ().WithBlockGasUsed (blockGasUsed )
804
+
805
+ endBlock , err := app .endBlock (sdkCtx )
820
806
if err != nil {
821
807
return nil , err
822
808
}
@@ -840,6 +826,45 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Request
840
826
}, nil
841
827
}
842
828
829
+ func (app * BaseApp ) executeTxs (ctx context.Context , txs [][]byte ) ([]* abci.ExecTxResult , error ) {
830
+ if app .txExecutor != nil {
831
+ return app .txExecutor (ctx , len (txs ), app .finalizeBlockState .ms , func (i int , ms storetypes.MultiStore ) * abci.ExecTxResult {
832
+ return app .deliverTxWithMultiStore (txs [i ], i , ms )
833
+ })
834
+ }
835
+
836
+ txResults := make ([]* abci.ExecTxResult , 0 , len (txs ))
837
+ for i , rawTx := range txs {
838
+ var response * abci.ExecTxResult
839
+
840
+ if _ , err := app .txDecoder (rawTx ); err == nil {
841
+ response = app .deliverTx (rawTx , i )
842
+ } else {
843
+ // In the case where a transaction included in a block proposal is malformed,
844
+ // we still want to return a default response to comet. This is because comet
845
+ // expects a response for each transaction included in a block proposal.
846
+ response = sdkerrors .ResponseExecTxResultWithEvents (
847
+ sdkerrors .ErrTxDecode ,
848
+ 0 ,
849
+ 0 ,
850
+ nil ,
851
+ false ,
852
+ )
853
+ }
854
+
855
+ // check after every tx if we should abort
856
+ select {
857
+ case <- ctx .Done ():
858
+ return nil , ctx .Err ()
859
+ default :
860
+ // continue
861
+ }
862
+
863
+ txResults = append (txResults , response )
864
+ }
865
+ return txResults , nil
866
+ }
867
+
843
868
// FinalizeBlock will execute the block proposal provided by RequestFinalizeBlock.
844
869
// Specifically, it will execute an application's BeginBlock (if defined), followed
845
870
// by the transactions in the proposal, finally followed by the application's
0 commit comments