mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-14 03:56:36 +00:00
eth/tracers: fix json logger for evm blocktest (#29795)
This commit is contained in:
parent
0d4cdb3dbe
commit
fa581766f5
2 changed files with 32 additions and 13 deletions
|
|
@ -804,9 +804,13 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block
|
||||||
// Execute the transaction and flush any traces to disk
|
// Execute the transaction and flush any traces to disk
|
||||||
vmenv := vm.NewEVM(vmctx, txContext, statedb, chainConfig, vmConf)
|
vmenv := vm.NewEVM(vmctx, txContext, statedb, chainConfig, vmConf)
|
||||||
statedb.SetTxContext(tx.Hash(), i)
|
statedb.SetTxContext(tx.Hash(), i)
|
||||||
vmConf.Tracer.OnTxStart(vmenv.GetVMContext(), tx, msg.From)
|
if vmConf.Tracer.OnTxStart != nil {
|
||||||
|
vmConf.Tracer.OnTxStart(vmenv.GetVMContext(), tx, msg.From)
|
||||||
|
}
|
||||||
vmRet, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
|
vmRet, err := core.ApplyMessage(vmenv, msg, new(core.GasPool).AddGas(msg.GasLimit))
|
||||||
vmConf.Tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, err)
|
if vmConf.Tracer.OnTxEnd != nil {
|
||||||
|
vmConf.Tracer.OnTxEnd(&types.Receipt{GasUsed: vmRet.UsedGas}, err)
|
||||||
|
}
|
||||||
if writer != nil {
|
if writer != nil {
|
||||||
writer.Flush()
|
writer.Flush()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -58,6 +58,7 @@ type jsonLogger struct {
|
||||||
encoder *json.Encoder
|
encoder *json.Encoder
|
||||||
cfg *Config
|
cfg *Config
|
||||||
env *tracing.VMContext
|
env *tracing.VMContext
|
||||||
|
hooks *tracing.Hooks
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewJSONLogger creates a new EVM tracer that prints execution steps as JSON objects
|
// NewJSONLogger creates a new EVM tracer that prints execution steps as JSON objects
|
||||||
|
|
@ -67,12 +68,14 @@ func NewJSONLogger(cfg *Config, writer io.Writer) *tracing.Hooks {
|
||||||
if l.cfg == nil {
|
if l.cfg == nil {
|
||||||
l.cfg = &Config{}
|
l.cfg = &Config{}
|
||||||
}
|
}
|
||||||
return &tracing.Hooks{
|
l.hooks = &tracing.Hooks{
|
||||||
OnTxStart: l.OnTxStart,
|
OnTxStart: l.OnTxStart,
|
||||||
OnExit: l.OnExit,
|
OnSystemCallStart: l.onSystemCallStart,
|
||||||
OnOpcode: l.OnOpcode,
|
OnExit: l.OnEnd,
|
||||||
OnFault: l.OnFault,
|
OnOpcode: l.OnOpcode,
|
||||||
|
OnFault: l.OnFault,
|
||||||
}
|
}
|
||||||
|
return l.hooks
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewJSONLoggerWithCallFrames creates a new EVM tracer that prints execution steps as JSON objects
|
// NewJSONLoggerWithCallFrames creates a new EVM tracer that prints execution steps as JSON objects
|
||||||
|
|
@ -82,13 +85,15 @@ func NewJSONLoggerWithCallFrames(cfg *Config, writer io.Writer) *tracing.Hooks {
|
||||||
if l.cfg == nil {
|
if l.cfg == nil {
|
||||||
l.cfg = &Config{}
|
l.cfg = &Config{}
|
||||||
}
|
}
|
||||||
return &tracing.Hooks{
|
l.hooks = &tracing.Hooks{
|
||||||
OnTxStart: l.OnTxStart,
|
OnTxStart: l.OnTxStart,
|
||||||
OnEnter: l.OnEnter,
|
OnSystemCallStart: l.onSystemCallStart,
|
||||||
OnExit: l.OnExit,
|
OnEnter: l.OnEnter,
|
||||||
OnOpcode: l.OnOpcode,
|
OnExit: l.OnExit,
|
||||||
OnFault: l.OnFault,
|
OnOpcode: l.OnOpcode,
|
||||||
|
OnFault: l.OnFault,
|
||||||
}
|
}
|
||||||
|
return l.hooks
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *jsonLogger) OnFault(pc uint64, op byte, gas uint64, cost uint64, scope tracing.OpContext, depth int, err error) {
|
func (l *jsonLogger) OnFault(pc uint64, op byte, gas uint64, cost uint64, scope tracing.OpContext, depth int, err error) {
|
||||||
|
|
@ -122,6 +127,16 @@ func (l *jsonLogger) OnOpcode(pc uint64, op byte, gas, cost uint64, scope tracin
|
||||||
l.encoder.Encode(log)
|
l.encoder.Encode(log)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (l *jsonLogger) onSystemCallStart() {
|
||||||
|
// Process no events while in system call.
|
||||||
|
hooks := *l.hooks
|
||||||
|
*l.hooks = tracing.Hooks{
|
||||||
|
OnSystemCallEnd: func() {
|
||||||
|
*l.hooks = hooks
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// OnEnter is not enabled by default.
|
// OnEnter is not enabled by default.
|
||||||
func (l *jsonLogger) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
|
func (l *jsonLogger) OnEnter(depth int, typ byte, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
|
||||||
frame := callFrame{
|
frame := callFrame{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue