From 10db680cd47c51e378703bbb527bc3738d258476 Mon Sep 17 00:00:00 2001 From: deelawn Date: Mon, 16 Sep 2024 17:30:33 -0700 Subject: [PATCH 1/2] don't emit events for a failed transaction --- tm2/pkg/sdk/baseapp.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/tm2/pkg/sdk/baseapp.go b/tm2/pkg/sdk/baseapp.go index 867a38d680a..f6669f01f63 100644 --- a/tm2/pkg/sdk/baseapp.go +++ b/tm2/pkg/sdk/baseapp.go @@ -625,11 +625,12 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res ctx = ctx.WithEventLogger(NewEventLogger()) msgLogs := make([]string, 0, len(msgs)) - data := make([]byte, 0, len(msgs)) - err := error(nil) - events := []Event{} + var ( + err error + events []Event + ) // NOTE: GasWanted is determined by ante handler and GasUsed by the GasMeter. for i, msg := range msgs { @@ -660,6 +661,7 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res fmt.Sprintf("msg:%d,success:%v,log:%s,events:%v", i, false, msgResult.Log, events)) err = msgResult.Error + events = nil break } @@ -667,7 +669,10 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res fmt.Sprintf("msg:%d,success:%v,log:%s,events:%v", i, true, msgResult.Log, events)) } - events = append(events, ctx.EventLogger().Events()...) + + if err == nil { + events = append(events, ctx.EventLogger().Events()...) + } result.Error = ABCIError(err) result.Data = data From 8fed41f2b0f4121473b84a3faaa0ace20f12dd73 Mon Sep 17 00:00:00 2001 From: deelawn Date: Thu, 19 Sep 2024 06:16:25 -1000 Subject: [PATCH 2/2] initialize events slice --- tm2/pkg/sdk/baseapp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tm2/pkg/sdk/baseapp.go b/tm2/pkg/sdk/baseapp.go index f6669f01f63..671f18cf058 100644 --- a/tm2/pkg/sdk/baseapp.go +++ b/tm2/pkg/sdk/baseapp.go @@ -629,7 +629,7 @@ func (app *BaseApp) runMsgs(ctx Context, msgs []Msg, mode RunTxMode) (result Res var ( err error - events []Event + events = []Event{} ) // NOTE: GasWanted is determined by ante handler and GasUsed by the GasMeter.