Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update EVM trace log capturing #356

Closed
wants to merge 22 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 0 additions & 81 deletions cmd/evm/json_logger.go

This file was deleted.

28 changes: 14 additions & 14 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ import (
"bytes"
"encoding/json"
"fmt"
"github.com/tomochain/tomochain/core/rawdb"
"io/ioutil"
"os"
goruntime "runtime"
"runtime/pprof"
"time"

goruntime "runtime"

"github.com/tomochain/tomochain/cmd/evm/internal/compiler"
"github.com/tomochain/tomochain/cmd/utils"
"github.com/tomochain/tomochain/common"
"github.com/tomochain/tomochain/core"
"github.com/tomochain/tomochain/core/rawdb"
"github.com/tomochain/tomochain/core/state"
"github.com/tomochain/tomochain/core/vm"
"github.com/tomochain/tomochain/core/vm/runtime"
"github.com/tomochain/tomochain/eth/tracers/logger"
"github.com/tomochain/tomochain/log"
"github.com/tomochain/tomochain/params"
cli "gopkg.in/urfave/cli.v1"
Expand Down Expand Up @@ -73,26 +73,26 @@ func runCmd(ctx *cli.Context) error {
glogger := log.NewGlogHandler(log.StreamHandler(os.Stderr, log.TerminalFormat(false)))
glogger.Verbosity(log.Lvl(ctx.GlobalInt(VerbosityFlag.Name)))
log.Root().SetHandler(glogger)
logconfig := &vm.LogConfig{
DisableMemory: ctx.GlobalBool(DisableMemoryFlag.Name),
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
logconfig := &logger.Config{
EnableMemory: !ctx.GlobalBool(DisableMemoryFlag.Name),
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
}

var (
tracer vm.Tracer
debugLogger *vm.StructLogger
tracer vm.EVMLogger
debugLogger *logger.StructLogger
statedb *state.StateDB
chainConfig *params.ChainConfig
sender = common.StringToAddress("sender")
receiver = common.StringToAddress("receiver")
)
if ctx.GlobalBool(MachineFlag.Name) {
tracer = NewJSONLogger(logconfig, os.Stdout)
tracer = logger.NewJSONLogger(logconfig, os.Stdout)
} else if ctx.GlobalBool(DebugFlag.Name) {
debugLogger = vm.NewStructLogger(logconfig)
debugLogger = logger.NewStructLogger(logconfig)
tracer = debugLogger
} else {
debugLogger = vm.NewStructLogger(logconfig)
debugLogger = logger.NewStructLogger(logconfig)
}
if ctx.GlobalString(GenesisFlag.Name) != "" {
gen := readGenesis(ctx.GlobalString(GenesisFlag.Name))
Expand Down Expand Up @@ -216,10 +216,10 @@ func runCmd(ctx *cli.Context) error {
if ctx.GlobalBool(DebugFlag.Name) {
if debugLogger != nil {
fmt.Fprintln(os.Stderr, "#### TRACE ####")
vm.WriteTrace(os.Stderr, debugLogger.StructLogs())
logger.WriteTrace(os.Stderr, debugLogger.StructLogs())
}
fmt.Fprintln(os.Stderr, "#### LOGS ####")
vm.WriteLogs(os.Stderr, statedb.Logs())
logger.WriteLogs(os.Stderr, statedb.Logs())
}

if ctx.GlobalBool(StatDumpFlag.Name) {
Expand All @@ -235,7 +235,7 @@ Gas used: %d
`, execTime, mem.HeapObjects, mem.Alloc, mem.TotalAlloc, mem.NumGC, initialGas-leftOverGas)
}
if tracer != nil {
tracer.CaptureEnd(ret, initialGas-leftOverGas, execTime, err)
tracer.CaptureEnd(ret, initialGas-leftOverGas, err)
} else {
fmt.Printf("0x%x\n", ret)
if err != nil {
Expand Down
19 changes: 10 additions & 9 deletions cmd/evm/staterunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (

"github.com/tomochain/tomochain/core/state"
"github.com/tomochain/tomochain/core/vm"
"github.com/tomochain/tomochain/eth/tracers/logger"
"github.com/tomochain/tomochain/log"
"github.com/tomochain/tomochain/tests"

Expand Down Expand Up @@ -56,24 +57,24 @@ func stateTestCmd(ctx *cli.Context) error {
log.Root().SetHandler(glogger)

// Configure the EVM logger
config := &vm.LogConfig{
DisableMemory: ctx.GlobalBool(DisableMemoryFlag.Name),
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
config := &logger.Config{
EnableMemory: !ctx.GlobalBool(DisableMemoryFlag.Name),
DisableStack: ctx.GlobalBool(DisableStackFlag.Name),
}
var (
tracer vm.Tracer
debugger *vm.StructLogger
tracer vm.EVMLogger
debugger *logger.StructLogger
)
switch {
case ctx.GlobalBool(MachineFlag.Name):
tracer = NewJSONLogger(config, os.Stderr)
tracer = logger.NewJSONLogger(config, os.Stderr)

case ctx.GlobalBool(DebugFlag.Name):
debugger = vm.NewStructLogger(config)
debugger = logger.NewStructLogger(config)
tracer = debugger

default:
debugger = vm.NewStructLogger(config)
debugger = logger.NewStructLogger(config)
}
// Load the test content from the input file
src, err := ioutil.ReadFile(ctx.Args().First())
Expand Down Expand Up @@ -114,7 +115,7 @@ func stateTestCmd(ctx *cli.Context) error {
if ctx.GlobalBool(DebugFlag.Name) {
if debugger != nil {
fmt.Fprintln(os.Stderr, "#### TRACE ####")
vm.WriteTrace(os.Stderr, debugger.StructLogs())
logger.WriteTrace(os.Stderr, debugger.StructLogs())
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ The state transitioning model does all all the necessary work to work out a vali
3) Create a new state object if the recipient is \0*32
4) Value transfer
== If contract creation ==
4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object

4a) Attempt to run transaction data
4b) If valid, use result as code for the new state object

== end ==
5) Run Script section
6) Derive new state root
Expand Down Expand Up @@ -219,6 +221,12 @@ func (st *StateTransition) TransitionDb(owner common.Address) (ret []byte, usedG
if err = st.preCheck(); err != nil {
return
}

if tracer := st.evm.Config.Tracer; tracer != nil {
tracer.CaptureTxStart(st.initialGas)
// TODO(trinhdn): defer the CaptureTxEnd with remaining gas
}

msg := st.msg
sender := st.from() // err checked in preCheck

Expand Down
10 changes: 5 additions & 5 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ func enable1884(jt *JumpTable) {
}
}

func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
balance := interpreter.intPool.get().Set(interpreter.evm.StateDB.GetBalance(callContext.contract.Address()))
callContext.stack.push(balance)
func opSelfBalance(pc *uint64, interpreter *EVMInterpreter, callContext *CallCtx) ([]byte, error) {
balance := interpreter.intPool.get().Set(interpreter.evm.StateDB.GetBalance(callContext.Contract.Address()))
callContext.Stack.push(balance)
return nil, nil
}

Expand All @@ -79,9 +79,9 @@ func enable1344(jt *JumpTable) {
}

// opChainID implements CHAINID opcode
func opChainID(pc *uint64, interpreter *EVMInterpreter, callContext *callCtx) ([]byte, error) {
func opChainID(pc *uint64, interpreter *EVMInterpreter, callContext *CallCtx) ([]byte, error) {
chainId := interpreter.intPool.get().Set(interpreter.evm.chainConfig.ChainId)
callContext.stack.push(chainId)
callContext.Stack.push(chainId)
return nil, nil
}

Expand Down
Loading