Skip to content

Commit ceee9c9

Browse files
committed
eth/tracers: add WithRemovedLog option to mark failed logs as removed
1 parent 5e6f737 commit ceee9c9

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

eth/tracers/native/call.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ type callLog struct {
4545
// Position of the log relative to subcalls within the same trace
4646
// See https://github.com/ethereum/go-ethereum/pull/28389 for details
4747
Position hexutil.Uint `json:"position"`
48+
Removed bool `json:"removed,omitempty"`
4849
}
4950

5051
type callFrame struct {
@@ -120,8 +121,9 @@ type callTracer struct {
120121
}
121122

122123
type callTracerConfig struct {
123-
OnlyTopCall bool `json:"onlyTopCall"` // If true, call tracer won't collect any subcalls
124-
WithLog bool `json:"withLog"` // If true, call tracer will collect event logs
124+
OnlyTopCall bool `json:"onlyTopCall"` // If true, call tracer won't collect any subcalls
125+
WithLog bool `json:"withLog"` // If true, call tracer will collect event logs
126+
WithRemovedLog bool `json:"withRemovedLog"` // If true, mark failed logs as removed instead of deleting them
125127
}
126128

127129
// newCallTracer returns a native go tracer which tracks
@@ -229,7 +231,7 @@ func (t *callTracer) OnTxEnd(receipt *types.Receipt, err error) {
229231
}
230232
if t.config.WithLog {
231233
// Logs are not emitted when the call fails
232-
clearFailedLogs(&t.callstack[0], false)
234+
clearFailedLogs(&t.callstack[0], false, t.config.WithRemovedLog)
233235
}
234236
}
235237

@@ -277,13 +279,19 @@ func (t *callTracer) Stop(err error) {
277279

278280
// clearFailedLogs clears the logs of a callframe and all its children
279281
// in case of execution failure.
280-
func clearFailedLogs(cf *callFrame, parentFailed bool) {
282+
func clearFailedLogs(cf *callFrame, parentFailed bool, withRemovedLog bool) {
281283
failed := cf.failed() || parentFailed
282284
// Clear own logs
283285
if failed {
284-
cf.Logs = nil
286+
if withRemovedLog {
287+
for i := range cf.Logs {
288+
cf.Logs[i].Removed = true
289+
}
290+
} else {
291+
cf.Logs = nil
292+
}
285293
}
286294
for i := range cf.Calls {
287-
clearFailedLogs(&cf.Calls[i], failed)
295+
clearFailedLogs(&cf.Calls[i], failed, withRemovedLog)
288296
}
289297
}

0 commit comments

Comments
 (0)