Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
s1na committed Mar 30, 2022
1 parent 3f09581 commit b7d6ba0
Show file tree
Hide file tree
Showing 10 changed files with 32 additions and 23 deletions.
6 changes: 2 additions & 4 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
return nil, err
}

var err error
if st.evm.Config.Debug {
st.evm.Config.Tracer.CaptureTxStart(st.initialGas)
defer func() {
st.evm.Config.Tracer.CaptureTxEnd(st.gas, err)
st.evm.Config.Tracer.CaptureTxEnd(st.gas)
}()
}

Expand All @@ -301,11 +300,10 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
sender = vm.AccountRef(msg.From())
rules = st.evm.ChainConfig().Rules(st.evm.Context.BlockNumber, st.evm.Context.Random != nil)
contractCreation = msg.To() == nil
gas uint64
)

// Check clauses 4-5, subtract intrinsic gas if everything is correct
gas, err = IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, rules.IsHomestead, rules.IsIstanbul)
gas, err := IntrinsicGas(st.data, st.msg.AccessList(), contractCreation, rules.IsHomestead, rules.IsIstanbul)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion core/vm/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
type EVMLogger interface {
// Transaction level
CaptureTxStart(gasLimit uint64)
CaptureTxEnd(remainingGas uint64, err error)
CaptureTxEnd(restGas uint64)
// Top call frame
CaptureStart(env *EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int)
CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error)
Expand Down
11 changes: 8 additions & 3 deletions eth/tracers/js/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,18 @@ func wrapError(context string, err error) error {
return fmt.Errorf("%v in server-side tracer function '%v'", err, context)
}

// CaptureTxStart implements the Tracer interface and is invoked at the beginning of
// transaction processing.
func (jst *jsTracer) CaptureTxStart(gasLimit uint64) {
jst.gasLimit = gasLimit
}

func (*jsTracer) CaptureTxEnd(remainingGas uint64, _ error) {}
// CaptureTxStart implements the Tracer interface and is invoked at the end of
// transaction processing.
func (*jsTracer) CaptureTxEnd(restGas uint64) {}

// CaptureStart implements the Tracer interface to initialize the tracing operation.
// CaptureStart implements the Tracer interface and is invoked before executing the
// top-level call frame of a transaction.
func (jst *jsTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) {
jst.env = env
jst.ctx["type"] = "CALL"
Expand Down Expand Up @@ -760,7 +765,7 @@ func (jst *jsTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, sco
}
}

// CaptureEnd is called after the call finishes to finalize the tracing.
// CaptureEnd is called after the top-level call finishes.
func (jst *jsTracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) {
jst.ctx["output"] = output
jst.ctx["time"] = t.String()
Expand Down
5 changes: 3 additions & 2 deletions eth/tracers/logger/access_list_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,9 @@ func (*AccessListTracer) CaptureEnter(typ vm.OpCode, from common.Address, to com

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

func (*AccessListTracer) CaptureTxStart(_ uint64) {}
func (*AccessListTracer) CaptureTxEnd(_ uint64, _ error) {}
func (*AccessListTracer) CaptureTxStart(gasLimit uint64) {}

func (*AccessListTracer) CaptureTxEnd(restGas uint64) {}

// AccessList returns the current accesslist maintained by the tracer.
func (a *AccessListTracer) AccessList() types.AccessList {
Expand Down
10 changes: 6 additions & 4 deletions eth/tracers/logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ func (l *StructLogger) CaptureEnter(typ vm.OpCode, from common.Address, to commo

func (l *StructLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}

func (*StructLogger) CaptureTxStart(_ uint64) {}
func (*StructLogger) CaptureTxEnd(_ uint64, _ error) {}
func (*StructLogger) CaptureTxStart(gasLimit uint64) {}

func (*StructLogger) CaptureTxEnd(restGas uint64) {}

// StructLogs returns the captured log entries.
func (l *StructLogger) StructLogs() []StructLog { return l.logs }
Expand Down Expand Up @@ -351,5 +352,6 @@ func (t *mdLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.Ad

func (t *mdLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}

func (*mdLogger) CaptureTxStart(_ uint64) {}
func (*mdLogger) CaptureTxEnd(_ uint64, _ error) {}
func (*mdLogger) CaptureTxStart(gasLimit uint64) {}

func (*mdLogger) CaptureTxEnd(restGas uint64) {}
5 changes: 3 additions & 2 deletions eth/tracers/logger/logger_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,6 @@ func (l *JSONLogger) CaptureEnter(typ vm.OpCode, from common.Address, to common.

func (l *JSONLogger) CaptureExit(output []byte, gasUsed uint64, err error) {}

func (*JSONLogger) CaptureTxStart(_ uint64) {}
func (*JSONLogger) CaptureTxEnd(_ uint64, _ error) {}
func (l *JSONLogger) CaptureTxStart(gasLimit uint64) {}

func (l *JSONLogger) CaptureTxEnd(restGas uint64) {}
5 changes: 3 additions & 2 deletions eth/tracers/native/4byte.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ func (t *fourByteTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64,
func (t *fourByteTracer) CaptureEnd(output []byte, gasUsed uint64, _ time.Duration, err error) {
}

func (*fourByteTracer) CaptureTxStart(_ uint64) {}
func (*fourByteTracer) CaptureTxEnd(_ uint64, _ error) {}
func (*fourByteTracer) CaptureTxStart(gasLimit uint64) {}

func (*fourByteTracer) CaptureTxEnd(restGas uint64) {}

// GetResult returns the json-encoded nested list of call traces, and any
// error arising from the encoding or forceful termination (via `Stop`).
Expand Down
5 changes: 3 additions & 2 deletions eth/tracers/native/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,9 @@ func (t *callTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
t.callstack[size-1].Calls = append(t.callstack[size-1].Calls, call)
}

func (*callTracer) CaptureTxStart(_ uint64) {}
func (*callTracer) CaptureTxEnd(_ uint64, _ error) {}
func (*callTracer) CaptureTxStart(gasLimit uint64) {}

func (*callTracer) CaptureTxEnd(restGas uint64) {}

// GetResult returns the json-encoded nested list of call traces, and any
// error arising from the encoding or forceful termination (via `Stop`).
Expand Down
4 changes: 2 additions & 2 deletions eth/tracers/native/noop.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ func (t *noopTracer) CaptureEnter(typ vm.OpCode, from common.Address, to common.
func (t *noopTracer) CaptureExit(output []byte, gasUsed uint64, err error) {
}

func (*noopTracer) CaptureTxStart(_ uint64) {}
func (*noopTracer) CaptureTxStart(gasLimit uint64) {}

func (*noopTracer) CaptureTxEnd(_ uint64, _ error) {}
func (*noopTracer) CaptureTxEnd(restGas uint64) {}

// GetResult returns an empty json object.
func (t *noopTracer) GetResult() (json.RawMessage, error) {
Expand Down
2 changes: 1 addition & 1 deletion eth/tracers/native/prestate.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (t *prestateTracer) CaptureTxStart(gasLimit uint64) {
t.gasLimit = gasLimit
}

func (t *prestateTracer) CaptureTxEnd(restGas uint64, err error) {}
func (t *prestateTracer) CaptureTxEnd(restGas uint64) {}

// GetResult returns the json-encoded nested list of call traces, and any
// error arising from the encoding or forceful termination (via `Stop`).
Expand Down

0 comments on commit b7d6ba0

Please sign in to comment.