-
Notifications
You must be signed in to change notification settings - Fork 7
/
tracer.go
109 lines (91 loc) · 3.53 KB
/
tracer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Copyright 2021 Evmos Foundation
// This file is part of Evmos' Ethermint library.
//
// The Ethermint library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The Ethermint library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the Ethermint library. If not, see https://github.com/planq-network/planq/v2/blob/main/LICENSE
package types
import (
"math/big"
"os"
"time"
"github.com/ethereum/go-ethereum/eth/tracers/logger"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/params"
)
const (
TracerAccessList = "access_list"
TracerJSON = "json"
TracerStruct = "struct"
TracerMarkdown = "markdown"
)
// NewTracer creates a new Logger tracer to collect execution traces from an
// EVM transaction.
func NewTracer(tracer string, msg core.Message, cfg *params.ChainConfig, height int64) vm.EVMLogger {
// TODO: enable additional log configuration
logCfg := &logger.Config{
Debug: true,
}
switch tracer {
case TracerAccessList:
preCompiles := vm.ActivePrecompiles(cfg.Rules(big.NewInt(height), cfg.MergeNetsplitBlock != nil))
return logger.NewAccessListTracer(msg.AccessList(), msg.From(), *msg.To(), preCompiles)
case TracerJSON:
return logger.NewJSONLogger(logCfg, os.Stderr)
case TracerMarkdown:
return logger.NewMarkdownLogger(logCfg, os.Stdout) // TODO: Stderr ?
case TracerStruct:
return logger.NewStructLogger(logCfg)
default:
return NewNoOpTracer()
}
}
// TxTraceResult is the result of a single transaction trace during a block trace.
type TxTraceResult struct {
Result interface{} `json:"result,omitempty"` // Trace results produced by the tracer
Error string `json:"error,omitempty"` // Trace failure produced by the tracer
}
var _ vm.EVMLogger = &NoOpTracer{}
// NoOpTracer is an empty implementation of vm.Tracer interface
type NoOpTracer struct{}
// NewNoOpTracer creates a no-op vm.Tracer
func NewNoOpTracer() *NoOpTracer {
return &NoOpTracer{}
}
// CaptureStart implements vm.Tracer interface
func (dt NoOpTracer) CaptureStart(_ *vm.EVM,
_ common.Address,
_ common.Address,
_ bool,
_ []byte,
_ uint64,
_ *big.Int) {
}
// CaptureState implements vm.Tracer interface
func (dt NoOpTracer) CaptureState(_ uint64, _ vm.OpCode, _, _ uint64, _ *vm.ScopeContext, _ []byte, _ int, _ error) {
}
// CaptureFault implements vm.Tracer interface
func (dt NoOpTracer) CaptureFault(_ uint64, _ vm.OpCode, _, _ uint64, _ *vm.ScopeContext, _ int, _ error) {
}
// CaptureEnd implements vm.Tracer interface
func (dt NoOpTracer) CaptureEnd(_ []byte, _ uint64, _ time.Duration, _ error) {}
// CaptureEnter implements vm.Tracer interface
func (dt NoOpTracer) CaptureEnter(_ vm.OpCode, _ common.Address, _ common.Address, _ []byte, _ uint64, _ *big.Int) {
}
// CaptureExit implements vm.Tracer interface
func (dt NoOpTracer) CaptureExit(_ []byte, _ uint64, _ error) {}
// CaptureTxStart implements vm.Tracer interface
func (dt NoOpTracer) CaptureTxStart(_ uint64) {}
// CaptureTxEnd implements vm.Tracer interface
func (dt NoOpTracer) CaptureTxEnd(_ uint64) {}