@@ -531,28 +531,25 @@ func (mux *abciMux) executeProposal(
531531 mux .state .resetProposal ()
532532 mux .state .proposal .hash = hash
533533
534- resultsBeginBlock := mux .BeginBlock (types.RequestBeginBlock {
534+ // The proposal is updated inside every call, as the end block phase
535+ // requires these results immediately to validate system transactions.
536+ mux .BeginBlock (types.RequestBeginBlock {
535537 Hash : hash ,
536538 Header : header ,
537539 LastCommitInfo : lastCommit ,
538540 ByzantineValidators : misbehavior ,
539541 })
540542
541- resultsDeliverTx := make ([]* types.ResponseDeliverTx , 0 , len (txs ))
542543 for _ , tx := range txs {
543- resp := mux .DeliverTx (types.RequestDeliverTx {
544+ mux .DeliverTx (types.RequestDeliverTx {
544545 Tx : tx ,
545546 })
546- resultsDeliverTx = append (resultsDeliverTx , & resp )
547547 }
548548
549- resultsEndBlock := mux .EndBlock (types.RequestEndBlock {
549+ mux .EndBlock (types.RequestEndBlock {
550550 Height : header .Height ,
551551 })
552552
553- // Update the proposal with results, marking the proposal as executed.
554- mux .state .proposal .setResults (& resultsBeginBlock , resultsDeliverTx , & resultsEndBlock )
555-
556553 return nil
557554}
558555
@@ -638,19 +635,22 @@ func (mux *abciMux) BeginBlock(req types.RequestBeginBlock) types.ResponseBeginB
638635 }
639636 }
640637
641- response := mux .BaseApplication .BeginBlock (req )
638+ result := mux .BaseApplication .BeginBlock (req )
642639
643640 // During the first block, also collect and prepend application events generated during
644641 // InitChain to BeginBlock events.
645642 if mux .state .BlockHeight () == 0 {
646- response .Events = append (response .Events , mux .state .initEvents ... )
643+ result .Events = append (result .Events , mux .state .initEvents ... )
647644 }
648645
649646 // Collect and return events from the application's BeginBlock calls.
650- response .Events = append (response .Events , ctx .GetEvents ()... )
647+ result .Events = append (result .Events , ctx .GetEvents ()... )
651648 mux .processProvableEvents (ctx )
652649
653- return response
650+ // Update the proposal.
651+ mux .state .proposal .resultsBeginBlock = & result
652+
653+ return result
654654}
655655
656656func (mux * abciMux ) notifyInvalidatedCheckTx (txHash hash.Hash , err error ) {
@@ -715,7 +715,17 @@ func (mux *abciMux) DeliverTx(req types.RequestDeliverTx) types.ResponseDeliverT
715715 ctx := mux .state .NewContext (api .ContextDeliverTx )
716716 defer ctx .Close ()
717717
718- if err := mux .executeTx (ctx , req .Tx ); err != nil {
718+ var results types.ResponseDeliverTx
719+ switch err := mux .executeTx (ctx , req .Tx ); err {
720+ case nil :
721+ results = types.ResponseDeliverTx {
722+ Code : types .CodeTypeOK ,
723+ Data : cbor .Marshal (ctx .Data ()),
724+ Events : ctx .GetEvents (),
725+ GasWanted : int64 (ctx .Gas ().GasWanted ()),
726+ GasUsed : int64 (ctx .Gas ().GasUsed ()),
727+ }
728+ default :
719729 if api .IsUnavailableStateError (err ) {
720730 // Make sure to not commit any transactions which include results based on unavailable
721731 // and/or corrupted state -- doing so can further corrupt state.
@@ -726,9 +736,7 @@ func (mux *abciMux) DeliverTx(req types.RequestDeliverTx) types.ResponseDeliverT
726736 }
727737 module , code := errors .Code (err )
728738
729- mux .processProvableEvents (ctx )
730-
731- return types.ResponseDeliverTx {
739+ results = types.ResponseDeliverTx {
732740 Codespace : module ,
733741 Code : code ,
734742 Log : err .Error (),
@@ -740,13 +748,10 @@ func (mux *abciMux) DeliverTx(req types.RequestDeliverTx) types.ResponseDeliverT
740748
741749 mux .processProvableEvents (ctx )
742750
743- return types.ResponseDeliverTx {
744- Code : types .CodeTypeOK ,
745- Data : cbor .Marshal (ctx .Data ()),
746- Events : ctx .GetEvents (),
747- GasWanted : int64 (ctx .Gas ().GasWanted ()),
748- GasUsed : int64 (ctx .Gas ().GasUsed ()),
749- }
751+ // Update the proposal.
752+ mux .state .proposal .resultsDeliverTx = append (mux .state .proposal .resultsDeliverTx , & results )
753+
754+ return results
750755}
751756
752757func (mux * abciMux ) EndBlock (req types.RequestEndBlock ) types.ResponseEndBlock {
@@ -768,9 +773,9 @@ func (mux *abciMux) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock {
768773 defer ctx .Close ()
769774
770775 // Dispatch EndBlock to all applications.
771- resp := mux .BaseApplication .EndBlock (req )
776+ results := mux .BaseApplication .EndBlock (req )
772777 for _ , app := range mux .appsByLexOrder {
773- newResp , err := app .EndBlock (ctx )
778+ newResults , err := app .EndBlock (ctx )
774779 if err != nil {
775780 mux .logger .Error ("EndBlock: fatal error in application" ,
776781 "err" , err ,
@@ -779,7 +784,7 @@ func (mux *abciMux) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock {
779784 panic (fmt .Errorf ("mux: EndBlock: fatal error in application: '%s': %w" , app .Name (), err ))
780785 }
781786 if app .Blessed () {
782- resp = newResp
787+ results = newResults
783788 }
784789 }
785790
@@ -798,22 +803,25 @@ func (mux *abciMux) EndBlock(req types.RequestEndBlock) types.ResponseEndBlock {
798803 }
799804
800805 // Collect and return events.
801- resp .Events = ctx .GetEvents ()
806+ results .Events = ctx .GetEvents ()
802807 mux .processProvableEvents (ctx )
803808
804809 // Update version to what we are actually running.
805- resp .ConsensusParamUpdates = & cmtproto.ConsensusParams {
810+ results .ConsensusParamUpdates = & cmtproto.ConsensusParams {
806811 Version : & cmtproto.VersionParams {
807812 App : version .CometBFTAppVersion ,
808813 },
809814 }
810815
816+ // Update the proposal.
817+ mux .state .proposal .resultsEndBlock = & results
818+
811819 // Validate system transactions included by the proposer.
812820 if err := mux .validateSystemTxs (); err != nil {
813821 panic (fmt .Errorf ("proposed block has invalid system transactions: %w" , err ))
814822 }
815823
816- return resp
824+ return results
817825}
818826
819827func (mux * abciMux ) Commit () types.ResponseCommit {
0 commit comments