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

Native tracers step 10 - remove duplicate SelfDestruct capture, clean up #6440

Merged
merged 3 commits into from
Dec 26, 2022
Merged
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
5 changes: 3 additions & 2 deletions cmd/evm/internal/t8ntool/transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/crypto"
"github.com/ledgerwatch/erigon/eth/tracers/logger"
"github.com/ledgerwatch/erigon/params"
"github.com/ledgerwatch/erigon/rlp"
"github.com/ledgerwatch/erigon/tests"
Expand Down Expand Up @@ -109,7 +110,7 @@ func Main(ctx *cli.Context) error {
}
if ctx.Bool(TraceFlag.Name) {
// Configure the EVM logger
logConfig := &vm.LogConfig{
logConfig := &logger.LogConfig{
DisableStack: ctx.Bool(TraceDisableStackFlag.Name),
DisableMemory: ctx.Bool(TraceDisableMemoryFlag.Name),
DisableReturnData: ctx.Bool(TraceDisableReturnDataFlag.Name),
Expand All @@ -131,7 +132,7 @@ func Main(ctx *cli.Context) error {
return nil, NewError(ErrorIO, fmt.Errorf("failed creating trace-file: %v", err2))
}
prevFile = traceFile
return vm.NewJSONLogger(logConfig, traceFile), nil
return logger.NewJSONLogger(logConfig, traceFile), nil
}
} else {
getTracer = func(txIndex int, txHash common.Hash) (tracer vm.EVMLogger, err error) {
Expand Down
15 changes: 8 additions & 7 deletions cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import (
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/core/vm/runtime"
"github.com/ledgerwatch/erigon/eth/tracers/logger"
"github.com/ledgerwatch/erigon/params"
)

Expand Down Expand Up @@ -117,7 +118,7 @@ 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{
logconfig := &logger.LogConfig{
DisableMemory: ctx.Bool(DisableMemoryFlag.Name),
DisableStack: ctx.Bool(DisableStackFlag.Name),
DisableStorage: ctx.Bool(DisableStorageFlag.Name),
Expand All @@ -127,20 +128,20 @@ func runCmd(ctx *cli.Context) error {

var (
tracer vm.EVMLogger
debugLogger *vm.StructLogger
debugLogger *logger.StructLogger
statedb *state.IntraBlockState
chainConfig *params.ChainConfig
sender = common.BytesToAddress([]byte("sender"))
receiver = common.BytesToAddress([]byte("receiver"))
genesisConfig *core.Genesis
)
if ctx.Bool(MachineFlag.Name) {
tracer = vm.NewJSONLogger(logconfig, os.Stdout)
tracer = logger.NewJSONLogger(logconfig, os.Stdout)
} else if ctx.Bool(DebugFlag.Name) {
debugLogger = vm.NewStructLogger(logconfig)
debugLogger = logger.NewStructLogger(logconfig)
tracer = debugLogger
} else {
debugLogger = vm.NewStructLogger(logconfig)
debugLogger = logger.NewStructLogger(logconfig)
}
db := memdb.New()
if ctx.String(GenesisFlag.Name) != "" {
Expand Down Expand Up @@ -317,13 +318,13 @@ func runCmd(ctx *cli.Context) error {
if printErr != nil {
log.Warn("Failed to print to stderr", "err", printErr)
}
vm.WriteTrace(os.Stderr, debugLogger.StructLogs())
logger.WriteTrace(os.Stderr, debugLogger.StructLogs())
}
_, printErr := fmt.Fprintln(os.Stderr, "#### LOGS ####")
if printErr != nil {
log.Warn("Failed to print to stderr", "err", printErr)
}
vm.WriteLogs(os.Stderr, statedb.Logs())
logger.WriteLogs(os.Stderr, statedb.Logs())
}

if bench || ctx.Bool(StatDumpFlag.Name) {
Expand Down
15 changes: 8 additions & 7 deletions cmd/evm/staterunner.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"github.com/ledgerwatch/erigon/common"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/eth/tracers/logger"
"github.com/ledgerwatch/erigon/tests"
"github.com/ledgerwatch/erigon/turbo/trie"
)
Expand Down Expand Up @@ -60,26 +61,26 @@ func stateTestCmd(ctx *cli.Context) error {
log.Root().SetHandler(log.LvlFilterHandler(log.LvlDebug, log.StderrHandler))

// Configure the EVM logger
config := &vm.LogConfig{
config := &logger.LogConfig{
DisableMemory: ctx.Bool(DisableMemoryFlag.Name),
DisableStack: ctx.Bool(DisableStackFlag.Name),
DisableStorage: ctx.Bool(DisableStorageFlag.Name),
DisableReturnData: ctx.Bool(DisableReturnDataFlag.Name),
}
var (
tracer vm.EVMLogger
debugger *vm.StructLogger
debugger *logger.StructLogger
)
switch {
case ctx.Bool(MachineFlag.Name):
tracer = vm.NewJSONLogger(config, os.Stderr)
tracer = logger.NewJSONLogger(config, os.Stderr)

case ctx.Bool(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 := os.ReadFile(ctx.Args().First())
Expand All @@ -106,7 +107,7 @@ func aggregateResultsFromStateTests(
ctx *cli.Context,
stateTests map[string]tests.StateTest,
tracer vm.EVMLogger,
debugger *vm.StructLogger,
debugger *logger.StructLogger,
) ([]StatetestResult, error) {
// Iterate over all the stateTests, run them and aggregate the results
cfg := vm.Config{
Expand Down Expand Up @@ -175,7 +176,7 @@ func aggregateResultsFromStateTests(
if printErr != nil {
log.Warn("Failed to write to stderr", "err", printErr)
}
vm.WriteTrace(os.Stderr, debugger.StructLogs())
logger.WriteTrace(os.Stderr, debugger.StructLogs())
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/integration/commands/state_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ import (
"github.com/ledgerwatch/erigon/core/rawdb"
"github.com/ledgerwatch/erigon/core/state"
"github.com/ledgerwatch/erigon/core/types"
"github.com/ledgerwatch/erigon/core/vm"
"github.com/ledgerwatch/erigon/eth/ethconfig"
"github.com/ledgerwatch/erigon/eth/integrity"
"github.com/ledgerwatch/erigon/eth/stagedsync"
"github.com/ledgerwatch/erigon/eth/stagedsync/stages"
"github.com/ledgerwatch/erigon/eth/tracers/logger"
"github.com/ledgerwatch/erigon/node/nodecfg"
"github.com/ledgerwatch/erigon/params"
erigoncli "github.com/ledgerwatch/erigon/turbo/cli"
Expand Down Expand Up @@ -218,7 +218,7 @@ func syncBySmallSteps(db kv.RwDB, miningConfig params.MiningConfig, ctx context.
}

traceStart := func() {
vmConfig.Tracer = vm.NewStructLogger(&vm.LogConfig{})
vmConfig.Tracer = logger.NewStructLogger(&logger.LogConfig{})
vmConfig.Debug = true
}
traceStop := func(id int) {
Expand All @@ -231,7 +231,7 @@ func syncBySmallSteps(db kv.RwDB, miningConfig params.MiningConfig, ctx context.
}
encoder := json.NewEncoder(w)
encoder.SetIndent(" ", " ")
for _, l := range vm.FormatLogs(vmConfig.Tracer.(*vm.StructLogger).StructLogs()) {
for _, l := range logger.FormatLogs(vmConfig.Tracer.(*logger.StructLogger).StructLogs()) {
if err2 := encoder.Encode(l); err2 != nil {
panic(err2)
}
Expand Down
11 changes: 0 additions & 11 deletions cmd/rpcdaemon/commands/otterscan_default_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,3 @@ func (t *DefaultTracer) CaptureEnd(output []byte, usedGas uint64, err error) {

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

func (t *DefaultTracer) CaptureSelfDestruct(from common.Address, to common.Address, value *uint256.Int) {
}

func (t *DefaultTracer) CaptureAccountRead(account common.Address) error {
return nil
}

func (t *DefaultTracer) CaptureAccountWrite(account common.Address) error {
return nil
}
7 changes: 3 additions & 4 deletions cmd/rpcdaemon/commands/otterscan_trace_operations.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ func (t *OperationsTracer) CaptureEnter(typ vm.OpCode, from common.Address, to c
if typ == vm.CREATE2 {
t.Results = append(t.Results, &InternalOperation{OP_CREATE2, from, to, (*hexutil.Big)(value.ToBig())})
}
}

func (l *OperationsTracer) CaptureSelfDestruct(from common.Address, to common.Address, value *uint256.Int) {
l.Results = append(l.Results, &InternalOperation{OP_SELF_DESTRUCT, from, to, (*hexutil.Big)(value.ToBig())})
if typ == vm.SELFDESTRUCT {
t.Results = append(t.Results, &InternalOperation{OP_SELF_DESTRUCT, from, to, (*hexutil.Big)(value.ToBig())})
}
}
10 changes: 5 additions & 5 deletions cmd/rpcdaemon/commands/otterscan_trace_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ func (t *TransactionTracer) captureStartOrEnter(typ vm.OpCode, from, to common.A
t.Results = append(t.Results, &TraceEntry{"CREATE2", t.depth, from, to, (*hexutil.Big)(value.ToBig()), inputCopy})
return
}

if typ == vm.SELFDESTRUCT {
last := t.Results[len(t.Results)-1]
t.Results = append(t.Results, &TraceEntry{"SELFDESTRUCT", last.Depth + 1, from, to, (*hexutil.Big)(value.ToBig()), nil})
}
}

func (t *TransactionTracer) CaptureStart(env *vm.EVM, from common.Address, to common.Address, precompile bool, create bool, input []byte, gas uint64, value *uint256.Int, code []byte) {
Expand All @@ -98,8 +103,3 @@ func (t *TransactionTracer) CaptureEnter(typ vm.OpCode, from common.Address, to
func (t *TransactionTracer) CaptureExit(output []byte, usedGas uint64, err error) {
t.depth--
}

func (l *TransactionTracer) CaptureSelfDestruct(from common.Address, to common.Address, value *uint256.Int) {
last := l.Results[len(l.Results)-1]
l.Results = append(l.Results, &TraceEntry{"SELFDESTRUCT", last.Depth + 1, from, to, (*hexutil.Big)(value.ToBig()), nil})
}
40 changes: 15 additions & 25 deletions cmd/rpcdaemon/commands/trace_adhoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,21 @@ func (ot *OeTracer) captureStartOrEnter(deep bool, typ vm.OpCode, from common.Ad
action.Init = common.CopyBytes(input)
action.Value.ToInt().Set(value.ToBig())
trace.Action = &action
} else if typ == vm.SELFDESTRUCT {
trace := &ParityTrace{}
trace.Type = SUICIDE
action := &SuicideTraceAction{}
action.Address = from
action.RefundAddress = to
action.Balance.ToInt().Set(value.ToBig())
trace.Action = action
topTrace := ot.traceStack[len(ot.traceStack)-1]
traceIdx := topTrace.Subtraces
ot.traceAddr = append(ot.traceAddr, traceIdx)
topTrace.Subtraces++
trace.TraceAddress = make([]int, len(ot.traceAddr))
copy(trace.TraceAddress, ot.traceAddr)
ot.traceAddr = ot.traceAddr[:len(ot.traceAddr)-1]
} else {
action := CallTraceAction{}
switch typ {
Expand Down Expand Up @@ -568,31 +583,6 @@ func (ot *OeTracer) CaptureState(pc uint64, op vm.OpCode, gas, cost uint64, scop
func (ot *OeTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64, scope *vm.ScopeContext, opDepth int, err error) {
}

func (ot *OeTracer) CaptureSelfDestruct(from common.Address, to common.Address, value *uint256.Int) {
trace := &ParityTrace{}
trace.Type = SUICIDE
action := &SuicideTraceAction{}
action.Address = from
action.RefundAddress = to
action.Balance.ToInt().Set(value.ToBig())
trace.Action = action
topTrace := ot.traceStack[len(ot.traceStack)-1]
traceIdx := topTrace.Subtraces
ot.traceAddr = append(ot.traceAddr, traceIdx)
topTrace.Subtraces++
trace.TraceAddress = make([]int, len(ot.traceAddr))
copy(trace.TraceAddress, ot.traceAddr)
ot.traceAddr = ot.traceAddr[:len(ot.traceAddr)-1]
ot.r.Trace = append(ot.r.Trace, trace)
}

func (ot *OeTracer) CaptureAccountRead(account common.Address) error {
return nil
}
func (ot *OeTracer) CaptureAccountWrite(account common.Address) error {
return nil
}

// Implements core/state/StateWriter to provide state diffs
type StateDiff struct {
sdMap map[common.Address]*StateDiffAccount
Expand Down
10 changes: 0 additions & 10 deletions cmd/state/commands/opcode_tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,15 +384,6 @@ func (ot *opcodeTracer) CaptureFault(pc uint64, op vm.OpCode, gas, cost uint64,

}

func (ot *opcodeTracer) CaptureSelfDestruct(from common.Address, to common.Address, value *uint256.Int) {
}
func (ot *opcodeTracer) CaptureAccountRead(account common.Address) error {
return nil
}
func (ot *opcodeTracer) CaptureAccountWrite(account common.Address) error {
return nil
}

type segPrefix struct {
BlockNum uint64
NumTxs uint
Expand Down Expand Up @@ -580,7 +571,6 @@ func OpcodeTracer(genesis *core.Genesis, blockNum uint64, chaindata string, numB

dbstate := state.NewPlainState(historyTx, block.NumberU64(), systemcontracts.SystemContractCodeLookup[chainConfig.ChainName])
intraBlockState := state.New(dbstate)
intraBlockState.SetTracer(ot)

getHeader := func(hash common.Hash, number uint64) *types.Header { return rawdb.ReadHeader(historyTx, hash, number) }
receipts, err1 := runBlock(ethash.NewFullFaker(), intraBlockState, noOpWriter, noOpWriter, chainConfig, getHeader, block, vmConfig, false)
Expand Down
10 changes: 0 additions & 10 deletions cmd/state/exec3/calltracer22.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,3 @@ func (ct *CallTracer) CaptureEnd(output []byte, usedGas uint64, err error) {
}
func (ct *CallTracer) CaptureExit(output []byte, usedGas uint64, err error) {
}
func (ct *CallTracer) CaptureSelfDestruct(from common.Address, to common.Address, value *uint256.Int) {
ct.froms[from] = struct{}{}
ct.tos[to] = struct{}{}
}
func (ct *CallTracer) CaptureAccountRead(account common.Address) error {
return nil
}
func (ct *CallTracer) CaptureAccountWrite(account common.Address) error {
return nil
}
Loading