From 6742fc526f3e1ae985d82a1781df4267485e2c70 Mon Sep 17 00:00:00 2001 From: Yohann Leon Date: Wed, 22 Mar 2017 15:32:51 +0100 Subject: [PATCH] core/vm: use uint64 instead of *big.Int in tracer (#3805) --- core/vm/interpreter.go | 8 ++------ core/vm/logger.go | 10 +++++----- core/vm/logger_test.go | 6 +++--- internal/ethapi/api.go | 4 ++-- internal/ethapi/tracer.go | 6 +++--- internal/ethapi/tracer_test.go | 4 ++-- 6 files changed, 17 insertions(+), 21 deletions(-) diff --git a/core/vm/interpreter.go b/core/vm/interpreter.go index 7d12ebc059..8ee9d3ca79 100644 --- a/core/vm/interpreter.go +++ b/core/vm/interpreter.go @@ -18,7 +18,6 @@ package vm import ( "fmt" - "math/big" "sync/atomic" "time" @@ -117,9 +116,7 @@ func (evm *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err e if err != nil && evm.cfg.Debug { // XXX For debugging //fmt.Printf("%04d: %8v cost = %-8d stack = %-8d ERR = %v\n", pc, op, cost, stack.len(), err) - // TODO update the tracer - g, c := new(big.Int).SetUint64(contract.Gas), new(big.Int).SetUint64(cost) - evm.cfg.Tracer.CaptureState(evm.env, pc, op, g, c, mem, stack, contract, evm.env.depth, err) + evm.cfg.Tracer.CaptureState(evm.env, pc, op, contract.Gas, cost, mem, stack, contract, evm.env.depth, err) } }() @@ -177,8 +174,7 @@ func (evm *Interpreter) Run(contract *Contract, input []byte) (ret []byte, err e } if evm.cfg.Debug { - g, c := new(big.Int).SetUint64(contract.Gas), new(big.Int).SetUint64(cost) - evm.cfg.Tracer.CaptureState(evm.env, pc, op, g, c, mem, stack, contract, evm.env.depth, err) + evm.cfg.Tracer.CaptureState(evm.env, pc, op, contract.Gas, cost, mem, stack, contract, evm.env.depth, err) } // XXX For debugging //fmt.Printf("%04d: %8v cost = %-8d stack = %-8d\n", pc, op, cost, stack.len()) diff --git a/core/vm/logger.go b/core/vm/logger.go index 3d7e1c95fe..825025b05f 100644 --- a/core/vm/logger.go +++ b/core/vm/logger.go @@ -52,8 +52,8 @@ type LogConfig struct { type StructLog struct { Pc uint64 Op OpCode - Gas *big.Int - GasCost *big.Int + Gas uint64 + GasCost uint64 Memory []byte Stack []*big.Int Storage map[common.Hash]common.Hash @@ -67,7 +67,7 @@ type StructLog struct { // Note that reference types are actual VM data structures; make copies // if you need to retain them beyond the current call. type Tracer interface { - CaptureState(env *EVM, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error + CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error } // StructLogger is an EVM state logger and implements Tracer. @@ -96,7 +96,7 @@ func NewStructLogger(cfg *LogConfig) *StructLogger { // captureState logs a new structured log message and pushes it out to the environment // // captureState also tracks SSTORE ops to track dirty values. -func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost *big.Int, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error { +func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost uint64, memory *Memory, stack *Stack, contract *Contract, depth int, err error) error { // check if already accumulated the specified number of logs if l.cfg.Limit != 0 && l.cfg.Limit <= len(l.logs) { return ErrTraceLimitReached @@ -158,7 +158,7 @@ func (l *StructLogger) CaptureState(env *EVM, pc uint64, op OpCode, gas, cost *b } } // create a new snaptshot of the EVM. - log := StructLog{pc, op, new(big.Int).Set(gas), cost, mem, stck, storage, env.depth, err} + log := StructLog{pc, op, gas, cost, mem, stck, storage, env.depth, err} l.logs = append(l.logs, log) return nil diff --git a/core/vm/logger_test.go b/core/vm/logger_test.go index e755a18e2a..b6fa31132a 100644 --- a/core/vm/logger_test.go +++ b/core/vm/logger_test.go @@ -59,7 +59,7 @@ func TestStoreCapture(t *testing.T) { var index common.Hash - logger.CaptureState(env, 0, SSTORE, new(big.Int), new(big.Int), mem, stack, contract, 0, nil) + logger.CaptureState(env, 0, SSTORE, 0, 0, mem, stack, contract, 0, nil) if len(logger.changedValues[contract.Address()]) == 0 { t.Fatalf("expected exactly 1 changed value on address %x, got %d", contract.Address(), len(logger.changedValues[contract.Address()])) } @@ -81,13 +81,13 @@ func TestStorageCapture(t *testing.T) { stack = newstack() ) - logger.CaptureState(env, 0, STOP, new(big.Int), new(big.Int), mem, stack, contract, 0, nil) + logger.CaptureState(env, 0, STOP, 0, 0, mem, stack, contract, 0, nil) if ref.calledForEach { t.Error("didn't expect for each to be called") } logger = NewStructLogger(&LogConfig{FullStorage: true}) - logger.CaptureState(env, 0, STOP, new(big.Int), new(big.Int), mem, stack, contract, 0, nil) + logger.CaptureState(env, 0, STOP, 0, 0, mem, stack, contract, 0, nil) if !ref.calledForEach { t.Error("expected for each to be called") } diff --git a/internal/ethapi/api.go b/internal/ethapi/api.go index c8374fe18e..0928c973f4 100644 --- a/internal/ethapi/api.go +++ b/internal/ethapi/api.go @@ -695,8 +695,8 @@ type ExecutionResult struct { type StructLogRes struct { Pc uint64 `json:"pc"` Op string `json:"op"` - Gas *big.Int `json:"gas"` - GasCost *big.Int `json:"gasCost"` + Gas uint64 `json:"gas"` + GasCost uint64 `json:"gasCost"` Depth int `json:"depth"` Error error `json:"error"` Stack []string `json:"stack"` diff --git a/internal/ethapi/tracer.go b/internal/ethapi/tracer.go index ef107fc42f..fe26853753 100644 --- a/internal/ethapi/tracer.go +++ b/internal/ethapi/tracer.go @@ -278,7 +278,7 @@ func wrapError(context string, err error) error { } // CaptureState implements the Tracer interface to trace a single step of VM execution -func (jst *JavascriptTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost *big.Int, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { +func (jst *JavascriptTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost uint64, memory *vm.Memory, stack *vm.Stack, contract *vm.Contract, depth int, err error) error { if jst.err == nil { jst.memory.memory = memory jst.stack.stack = stack @@ -288,8 +288,8 @@ func (jst *JavascriptTracer) CaptureState(env *vm.EVM, pc uint64, op vm.OpCode, jst.log["pc"] = pc jst.log["op"] = ocw.toValue(jst.vm) - jst.log["gas"] = gas.Int64() - jst.log["gasPrice"] = cost.Int64() + jst.log["gas"] = gas + jst.log["gasPrice"] = cost jst.log["memory"] = jst.memvalue jst.log["stack"] = jst.stackvalue jst.log["depth"] = depth diff --git a/internal/ethapi/tracer_test.go b/internal/ethapi/tracer_test.go index 693afe802f..0ef450ce32 100644 --- a/internal/ethapi/tracer_test.go +++ b/internal/ethapi/tracer_test.go @@ -136,10 +136,10 @@ func TestHaltBetweenSteps(t *testing.T) { env := vm.NewEVM(vm.Context{}, nil, params.TestChainConfig, vm.Config{Debug: true, Tracer: tracer}) contract := vm.NewContract(&account{}, &account{}, big.NewInt(0), 0) - tracer.CaptureState(env, 0, 0, big.NewInt(0), big.NewInt(0), nil, nil, contract, 0, nil) + tracer.CaptureState(env, 0, 0, 0, 0, nil, nil, contract, 0, nil) timeout := errors.New("stahp") tracer.Stop(timeout) - tracer.CaptureState(env, 0, 0, big.NewInt(0), big.NewInt(0), nil, nil, contract, 0, nil) + tracer.CaptureState(env, 0, 0, 0, 0, nil, nil, contract, 0, nil) if _, err := tracer.GetResult(); err.Error() != "stahp in server-side tracer function 'step'" { t.Errorf("Expected timeout error, got %v", err)