Skip to content

Commit

Permalink
core,eth: rm unnecessary env field frome enter and exit
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Jul 28, 2021
1 parent 84f0ef4 commit 6b5627c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 22 deletions.
4 changes: 2 additions & 2 deletions core/vm/access_list_tracer.go
Expand Up @@ -166,10 +166,10 @@ func (*AccessListTracer) CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost

func (*AccessListTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {}

func (*AccessListTracer) CaptureEnter(env *EVM, type_ CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
func (*AccessListTracer) CaptureEnter(type_ CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
}

func (*AccessListTracer) CaptureExit(env *EVM, output []byte, gasUsed uint64, err error) {}
func (*AccessListTracer) CaptureExit(output []byte, gasUsed uint64, err error) {}

// AccessList returns the current accesslist maintained by the tracer.
func (a *AccessListTracer) AccessList() types.AccessList {
Expand Down
20 changes: 10 additions & 10 deletions core/vm/evm.go
Expand Up @@ -233,9 +233,9 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
}(gas, time.Now())
} else if evm.Config.Debug && evm.depth > 0 {
// Handle tracer events for entering and exiting a call frame
evm.Config.Tracer.CaptureEnter(evm, CallType, caller.Address(), addr, input, gas, value)
evm.Config.Tracer.CaptureEnter(CallType, caller.Address(), addr, input, gas, value)
defer func(startGas uint64) {
evm.Config.Tracer.CaptureExit(evm, ret, startGas-gas, err)
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
}(gas)
}

Expand Down Expand Up @@ -298,9 +298,9 @@ func (evm *EVM) CallCode(caller ContractRef, addr common.Address, input []byte,

// Invoke tracer hooks that signal entering/exiting a call frame
if evm.Config.Debug {
evm.Config.Tracer.CaptureEnter(evm, CallCodeType, caller.Address(), addr, input, gas, value)
evm.Config.Tracer.CaptureEnter(CallCodeType, caller.Address(), addr, input, gas, value)
defer func(startGas uint64) {
evm.Config.Tracer.CaptureExit(evm, ret, startGas-gas, err)
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
}(gas)
}

Expand Down Expand Up @@ -342,9 +342,9 @@ func (evm *EVM) DelegateCall(caller ContractRef, addr common.Address, input []by

// Invoke tracer hooks that signal entering/exiting a call frame
if evm.Config.Debug {
evm.Config.Tracer.CaptureEnter(evm, DelegateCallType, caller.Address(), addr, input, gas, nil)
evm.Config.Tracer.CaptureEnter(DelegateCallType, caller.Address(), addr, input, gas, nil)
defer func(startGas uint64) {
evm.Config.Tracer.CaptureExit(evm, ret, startGas-gas, err)
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
}(gas)
}

Expand Down Expand Up @@ -395,9 +395,9 @@ func (evm *EVM) StaticCall(caller ContractRef, addr common.Address, input []byte

// Invoke tracer hooks that signal entering/exiting a call frame
if evm.Config.Debug {
evm.Config.Tracer.CaptureEnter(evm, StaticCallType, caller.Address(), addr, input, gas, nil)
evm.Config.Tracer.CaptureEnter(StaticCallType, caller.Address(), addr, input, gas, nil)
defer func(startGas uint64) {
evm.Config.Tracer.CaptureExit(evm, ret, startGas-gas, err)
evm.Config.Tracer.CaptureExit(ret, startGas-gas, err)
}(gas)
}

Expand Down Expand Up @@ -482,7 +482,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
evm.Config.Tracer.CaptureStart(evm, caller.Address(), address, true, codeAndHash.code, gas, value)
} else if evm.Config.Debug && evm.depth > 0 {
// TODO: Make sure we should capture init code's call frame for the tracer
evm.Config.Tracer.CaptureEnter(evm, type_, caller.Address(), address, codeAndHash.code, gas, value)
evm.Config.Tracer.CaptureEnter(type_, caller.Address(), address, codeAndHash.code, gas, value)
}

start := time.Now()
Expand Down Expand Up @@ -525,7 +525,7 @@ func (evm *EVM) create(caller ContractRef, codeAndHash *codeAndHash, gas uint64,
if evm.Config.Debug && evm.depth == 0 {
evm.Config.Tracer.CaptureEnd(ret, gas-contract.Gas, time.Since(start), err)
} else if evm.Config.Debug && evm.depth > 0 {
evm.Config.Tracer.CaptureExit(evm, ret, gas-contract.Gas, err)
evm.Config.Tracer.CaptureExit(ret, gas-contract.Gas, err)
}
return ret, address, contract.Gas, err
}
Expand Down
8 changes: 4 additions & 4 deletions core/vm/logger.go
Expand Up @@ -138,8 +138,8 @@ type structFrameMarshaling struct {
type Tracer interface {
CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)
CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, rData []byte, depth int, err error)
CaptureEnter(env *EVM, type_ CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)
CaptureExit(env *EVM, output []byte, gasUsed uint64, err error)
CaptureEnter(type_ CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int)
CaptureExit(output []byte, gasUsed uint64, err error)
CaptureFault(env *EVM, pc uint64, op OpCode, gas, cost uint64, scope *ScopeContext, depth int, err error)
CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error)
}
Expand Down Expand Up @@ -260,15 +260,15 @@ func (l *StructLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration
}
}

func (l *StructLogger) CaptureEnter(env *EVM, type_ CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
func (l *StructLogger) CaptureEnter(type_ CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
in := make([]byte, len(input))
copy(in, input)
// TODO: should we honor `l.Cfg.Limit` for frames too?
frame := StructFrame{type_.String(), from, to, in, gas, new(big.Int).Set(value), 0, nil, nil}
l.frames = append(l.frames, frame)
}

func (l *StructLogger) CaptureExit(env *EVM, output []byte, gasUsed uint64, err error) {
func (l *StructLogger) CaptureExit(output []byte, gasUsed uint64, err error) {
frame := l.frames[len(l.frames)-1]
frame.GasUsed = gasUsed
out := make([]byte, len(output))
Expand Down
4 changes: 2 additions & 2 deletions core/vm/logger_json.go
Expand Up @@ -89,7 +89,7 @@ func (l *JSONLogger) CaptureEnd(output []byte, gasUsed uint64, t time.Duration,
l.encoder.Encode(endLog{common.Bytes2Hex(output), math.HexOrDecimal64(gasUsed), t, errMsg})
}

func (l *JSONLogger) CaptureEnter(env *EVM, type_ CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
func (l *JSONLogger) CaptureEnter(type_ CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
frame := StructFrame{
Type: type_.String(),
From: from,
Expand All @@ -101,7 +101,7 @@ func (l *JSONLogger) CaptureEnter(env *EVM, type_ CallFrameType, from common.Add
l.encoder.Encode(frame)
}

func (l *JSONLogger) CaptureExit(env *EVM, output []byte, gasUsed uint64, err error) {
func (l *JSONLogger) CaptureExit(output []byte, gasUsed uint64, err error) {
type exitLog struct {
Output hexutil.Bytes `json:"output"`
GasUsed math.HexOrDecimal64 `json:"gasUsed"`
Expand Down
6 changes: 2 additions & 4 deletions eth/tracers/tracer.go
Expand Up @@ -662,9 +662,7 @@ func (jst *Tracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, er
}
}

func (jst *Tracer) CaptureEnter(env *vm.EVM, type_ vm.CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
// TODO: Do we need env?

func (jst *Tracer) CaptureEnter(type_ vm.CallFrameType, from common.Address, to common.Address, input []byte, gas uint64, value *big.Int) {
if !jst.traceCallFrames {
return
}
Expand Down Expand Up @@ -692,7 +690,7 @@ func (jst *Tracer) CaptureEnter(env *vm.EVM, type_ vm.CallFrameType, from common
}
}

func (jst *Tracer) CaptureExit(env *vm.EVM, output []byte, gasUsed uint64, err error) {
func (jst *Tracer) CaptureExit(output []byte, gasUsed uint64, err error) {
if !jst.traceCallFrames {
return
}
Expand Down

0 comments on commit 6b5627c

Please sign in to comment.