eth/tracers: cache callstack frame index in OnLog

This commit is contained in:
wit 2025-12-13 11:49:41 +08:00
parent 16f50285b7
commit f229fe945b

View file

@ -246,13 +246,17 @@ func (t *callTracer) OnLog(log *types.Log) {
if t.interrupt.Load() { if t.interrupt.Load() {
return return
} }
// Cache the index of the current frame to avoid repeated calculations
lastIdx := len(t.callstack) - 1
l := callLog{ l := callLog{
Address: log.Address, Address: log.Address,
Topics: log.Topics, Topics: log.Topics,
Data: log.Data, Data: log.Data,
Position: hexutil.Uint(len(t.callstack[len(t.callstack)-1].Calls)), Position: hexutil.Uint(len(t.callstack[lastIdx].Calls)),
} }
t.callstack[len(t.callstack)-1].Logs = append(t.callstack[len(t.callstack)-1].Logs, l) t.callstack[lastIdx].Logs = append(t.callstack[lastIdx].Logs, l)
} }
// GetResult returns the json-encoded nested list of call traces, and any // GetResult returns the json-encoded nested list of call traces, and any