@@ -711,6 +711,7 @@ func (app *BaseApp) VerifyVoteExtension(req *abci.VerifyVoteExtensionRequest) (r
711711// must be used.
712712func (app * BaseApp ) internalFinalizeBlock (ctx context.Context , req * abci.FinalizeBlockRequest ) (* abci.FinalizeBlockResponse , error ) {
713713 var events []abci.Event
714+ var publishEvents sdk.PublishEvents
714715
715716 if err := app .checkHalt (req .Height , req .Time ); err != nil {
716717 return nil , err
@@ -803,6 +804,7 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
803804 // continue
804805 }
805806
807+ publishEvents = append (publishEvents , app .finalizeBlockState .Context ().PublishEventManager ().Events ()... )
806808 events = append (events , beginBlock .Events ... )
807809
808810 // Reset the gas meter so that the AnteHandlers aren't required to
@@ -814,7 +816,7 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
814816 //
815817 // NOTE: Not all raw transactions may adhere to the sdk.Tx interface, e.g.
816818 // vote extensions, so skip those.
817- txResults , err := app .executeTxs (ctx , req .Txs )
819+ txResults , txEventSet , err := app .executeTxs (ctx , req .Txs )
818820 if err != nil {
819821 return nil , err
820822 }
@@ -823,6 +825,8 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
823825 app .finalizeBlockState .ms = app .finalizeBlockState .ms .SetTracingContext (nil ).(storetypes.CacheMultiStore )
824826 }
825827
828+ app .finalizeBlockState .SetContext (app .finalizeBlockState .Context ().WithPublishEventManager (sdk .NewPublishEventManager ()))
829+
826830 endBlock , err := app .endBlock (app .finalizeBlockState .Context ())
827831 if err != nil {
828832 return nil , err
@@ -836,9 +840,23 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
836840 // continue
837841 }
838842
843+ publishEvents = append (publishEvents , app .finalizeBlockState .Context ().PublishEventManager ().Events ()... )
844+
839845 events = append (events , endBlock .Events ... )
840846 cp := app .GetConsensusParams (app .finalizeBlockState .Context ())
841847
848+ events , trueOrder := filterOutPublishEvents (events )
849+ app .flushData = PublishEventFlush {
850+ Height : header .Height ,
851+ PrevAppHash : header .AppHash ,
852+ BlockEvents : EventSet {
853+ AbciEvents : events ,
854+ PublishEvents : publishEvents ,
855+ TrueOrder : trueOrder ,
856+ },
857+ TxEvents : txEventSet ,
858+ }
859+
842860 return & abci.FinalizeBlockResponse {
843861 Events : events ,
844862 TxResults : txResults ,
@@ -847,11 +865,15 @@ func (app *BaseApp) internalFinalizeBlock(ctx context.Context, req *abci.Finaliz
847865 }, nil
848866}
849867
850- func (app * BaseApp ) executeTxs (ctx context.Context , txs [][]byte ) ([]* abci.ExecTxResult , error ) {
868+ func (app * BaseApp ) executeTxs (ctx context.Context , txs [][]byte ) ([]* abci.ExecTxResult , [] EventSet , error ) {
851869 txResults := make ([]* abci.ExecTxResult , 0 , len (txs ))
870+ txEventSet := make ([]EventSet , 0 )
871+
852872 for txIdx , rawTx := range txs {
853873 var response * abci.ExecTxResult
854874
875+ app .finalizeBlockState .SetContext (app .finalizeBlockState .Context ().WithPublishEventManager (sdk .NewPublishEventManager ()))
876+
855877 if memTx , err := app .txDecoder (rawTx ); err == nil {
856878 response = app .deliverTx (rawTx , memTx , txIdx )
857879 } else {
@@ -870,14 +892,36 @@ func (app *BaseApp) executeTxs(ctx context.Context, txs [][]byte) ([]*abci.ExecT
870892 // check after every tx if we should abort
871893 select {
872894 case <- ctx .Done ():
873- return nil , ctx .Err ()
895+ return nil , nil , ctx .Err ()
874896 default :
875897 // continue
876898 }
877-
899+ filtered , order := filterOutPublishEvents (response .Events )
900+ response .Events = filtered
878901 txResults = append (txResults , response )
902+ txEventSet = append (txEventSet , EventSet {
903+ AbciEvents : response .Events ,
904+ PublishEvents : app .finalizeBlockState .Context ().PublishEventManager ().Events (),
905+ TrueOrder : order ,
906+ })
879907 }
880- return txResults , nil
908+ return txResults , txEventSet , nil
909+ }
910+
911+ func filterOutPublishEvents (events []abci.Event ) ([]abci.Event , []EventType ) {
912+ var filteredEvents []abci.Event
913+ var trueOrder []EventType
914+
915+ for _ , e := range events {
916+ if e .Type == sdk .PlaceholderEventType {
917+ trueOrder = append (trueOrder , EventTypePublish )
918+ continue
919+ }
920+ filteredEvents = append (filteredEvents , e )
921+ trueOrder = append (trueOrder , EventTypeAbci )
922+ }
923+
924+ return filteredEvents , trueOrder
881925}
882926
883927// FinalizeBlock will execute the block proposal provided by RequestFinalizeBlock.
@@ -967,7 +1011,10 @@ func (app *BaseApp) Commit() (*abci.CommitResponse, error) {
9671011 rms .SetCommitHeader (header )
9681012 }
9691013
970- app .cms .Commit ()
1014+ commitId := app .cms .Commit ()
1015+
1016+ app .flushData .NewAppHash = commitId .Hash
1017+ app .PublishBlockEvents (app .flushData )
9711018
9721019 resp := & abci.CommitResponse {
9731020 RetainHeight : retainHeight ,
0 commit comments