eth/tracers: add pc field to callTracer

This commit is contained in:
Ilias Tsatiris 2025-11-05 18:05:04 +02:00
parent 395425902d
commit 22475726d7
2 changed files with 16 additions and 0 deletions

View file

@ -45,10 +45,12 @@ type callLog struct {
// Position of the log relative to subcalls within the same trace // Position of the log relative to subcalls within the same trace
// See https://github.com/ethereum/go-ethereum/pull/28389 for details // See https://github.com/ethereum/go-ethereum/pull/28389 for details
Position hexutil.Uint `json:"position"` Position hexutil.Uint `json:"position"`
Pc uint64 `json:"pc"`
} }
type callFrame struct { type callFrame struct {
Type vm.OpCode `json:"-"` Type vm.OpCode `json:"-"`
Pc uint64 `json:"pc"`
From common.Address `json:"from"` From common.Address `json:"from"`
Gas uint64 `json:"gas"` Gas uint64 `json:"gas"`
GasUsed uint64 `json:"gasUsed"` GasUsed uint64 `json:"gasUsed"`
@ -117,6 +119,7 @@ type callTracer struct {
depth int depth int
interrupt atomic.Bool // Atomic flag to signal execution interruption interrupt atomic.Bool // Atomic flag to signal execution interruption
reason error // Textual reason for the interruption reason error // Textual reason for the interruption
lastPc uint64
} }
type callTracerConfig struct { type callTracerConfig struct {
@ -138,6 +141,7 @@ func newCallTracer(ctx *tracers.Context, cfg json.RawMessage, chainConfig *param
OnEnter: t.OnEnter, OnEnter: t.OnEnter,
OnExit: t.OnExit, OnExit: t.OnExit,
OnLog: t.OnLog, OnLog: t.OnLog,
OnOpcode: t.OnOpcode,
}, },
GetResult: t.GetResult, GetResult: t.GetResult,
Stop: t.Stop, Stop: t.Stop,
@ -173,6 +177,7 @@ func (t *callTracer) OnEnter(depth int, typ byte, from common.Address, to common
Input: common.CopyBytes(input), Input: common.CopyBytes(input),
Gas: gas, Gas: gas,
Value: value, Value: value,
Pc: t.lastPc,
} }
if depth == 0 { if depth == 0 {
call.Gas = t.gasLimit call.Gas = t.gasLimit
@ -219,6 +224,10 @@ func (t *callTracer) OnTxStart(env *tracing.VMContext, tx *types.Transaction, fr
t.gasLimit = tx.Gas() t.gasLimit = tx.Gas()
} }
func (t *callTracer) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracing.OpContext, rData []byte, depth int, err error) {
t.lastPc = pc
}
func (t *callTracer) OnTxEnd(receipt *types.Receipt, err error) { func (t *callTracer) OnTxEnd(receipt *types.Receipt, err error) {
// Error happened during tx validation. // Error happened during tx validation.
if err != nil { if err != nil {
@ -251,6 +260,7 @@ func (t *callTracer) OnLog(log *types.Log) {
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[len(t.callstack)-1].Calls)),
Pc: t.lastPc,
} }
t.callstack[len(t.callstack)-1].Logs = append(t.callstack[len(t.callstack)-1].Logs, l) t.callstack[len(t.callstack)-1].Logs = append(t.callstack[len(t.callstack)-1].Logs, l)
} }

View file

@ -17,6 +17,7 @@ var _ = (*callFrameMarshaling)(nil)
func (c callFrame) MarshalJSON() ([]byte, error) { func (c callFrame) MarshalJSON() ([]byte, error) {
type callFrame0 struct { type callFrame0 struct {
Type vm.OpCode `json:"-"` Type vm.OpCode `json:"-"`
Pc uint64 `json:"pc"`
From common.Address `json:"from"` From common.Address `json:"from"`
Gas hexutil.Uint64 `json:"gas"` Gas hexutil.Uint64 `json:"gas"`
GasUsed hexutil.Uint64 `json:"gasUsed"` GasUsed hexutil.Uint64 `json:"gasUsed"`
@ -44,6 +45,7 @@ func (c callFrame) MarshalJSON() ([]byte, error) {
enc.Logs = c.Logs enc.Logs = c.Logs
enc.Value = (*hexutil.Big)(c.Value) enc.Value = (*hexutil.Big)(c.Value)
enc.TypeString = c.TypeString() enc.TypeString = c.TypeString()
enc.Pc = c.Pc
return json.Marshal(&enc) return json.Marshal(&enc)
} }
@ -51,6 +53,7 @@ func (c callFrame) MarshalJSON() ([]byte, error) {
func (c *callFrame) UnmarshalJSON(input []byte) error { func (c *callFrame) UnmarshalJSON(input []byte) error {
type callFrame0 struct { type callFrame0 struct {
Type *vm.OpCode `json:"-"` Type *vm.OpCode `json:"-"`
Pc uint64 `json:"pc"`
From *common.Address `json:"from"` From *common.Address `json:"from"`
Gas *hexutil.Uint64 `json:"gas"` Gas *hexutil.Uint64 `json:"gas"`
GasUsed *hexutil.Uint64 `json:"gasUsed"` GasUsed *hexutil.Uint64 `json:"gasUsed"`
@ -70,6 +73,9 @@ func (c *callFrame) UnmarshalJSON(input []byte) error {
if dec.Type != nil { if dec.Type != nil {
c.Type = *dec.Type c.Type = *dec.Type
} }
c.Pc = dec.Pc
if dec.From != nil { if dec.From != nil {
c.From = *dec.From c.From = *dec.From
} }