cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 14:56:11 +03:00
|
|
|
// Copyright 2017 The go-ethereum Authors
|
|
|
|
// This file is part of the go-ethereum library.
|
|
|
|
//
|
|
|
|
// The go-ethereum 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 go-ethereum 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 go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
2021-11-09 14:09:35 +03:00
|
|
|
// Package tracers is a manager for transaction tracing engines.
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 14:56:11 +03:00
|
|
|
package tracers
|
|
|
|
|
|
|
|
import (
|
2021-11-05 13:48:21 +03:00
|
|
|
"encoding/json"
|
2021-11-09 14:09:35 +03:00
|
|
|
"errors"
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 14:56:11 +03:00
|
|
|
|
2021-11-09 14:09:35 +03:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
2021-11-05 13:48:21 +03:00
|
|
|
"github.com/ethereum/go-ethereum/core/vm"
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 14:56:11 +03:00
|
|
|
)
|
|
|
|
|
2021-11-09 14:09:35 +03:00
|
|
|
// Context contains some contextual infos for a transaction execution that is not
|
|
|
|
// available from within the EVM object.
|
|
|
|
type Context struct {
|
|
|
|
BlockHash common.Hash // Hash of the block the tx is contained within (zero if dangling tx or call)
|
|
|
|
TxIndex int // Index of the transaction within a block (zero if dangling tx or call)
|
|
|
|
TxHash common.Hash // Hash of the transaction being traced (zero if dangling call)
|
|
|
|
}
|
|
|
|
|
2021-11-05 13:48:21 +03:00
|
|
|
// Tracer interface extends vm.EVMLogger and additionally
|
|
|
|
// allows collecting the tracing result.
|
|
|
|
type Tracer interface {
|
|
|
|
vm.EVMLogger
|
|
|
|
GetResult() (json.RawMessage, error)
|
|
|
|
// Stop terminates execution of the tracer at the first opportune moment.
|
|
|
|
Stop(err error)
|
|
|
|
}
|
|
|
|
|
2022-08-09 12:04:57 +03:00
|
|
|
type lookupFunc func(string, *Context, json.RawMessage) (Tracer, error)
|
2021-11-09 14:09:35 +03:00
|
|
|
|
2021-11-05 13:48:21 +03:00
|
|
|
var (
|
2021-11-09 14:09:35 +03:00
|
|
|
lookups []lookupFunc
|
2021-11-05 13:48:21 +03:00
|
|
|
)
|
|
|
|
|
2021-11-09 14:09:35 +03:00
|
|
|
// RegisterLookup registers a method as a lookup for tracers, meaning that
|
|
|
|
// users can invoke a named tracer through that lookup. If 'wildcard' is true,
|
|
|
|
// then the lookup will be placed last. This is typically meant for interpreted
|
|
|
|
// engines (js) which can evaluate dynamic user-supplied code.
|
|
|
|
func RegisterLookup(wildcard bool, lookup lookupFunc) {
|
|
|
|
if wildcard {
|
|
|
|
lookups = append(lookups, lookup)
|
|
|
|
} else {
|
|
|
|
lookups = append([]lookupFunc{lookup}, lookups...)
|
2021-11-05 13:48:21 +03:00
|
|
|
}
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 14:56:11 +03:00
|
|
|
|
2021-11-09 14:09:35 +03:00
|
|
|
// New returns a new instance of a tracer, by iterating through the
|
|
|
|
// registered lookups.
|
2022-08-09 12:04:57 +03:00
|
|
|
func New(code string, ctx *Context, cfg json.RawMessage) (Tracer, error) {
|
2021-11-09 14:09:35 +03:00
|
|
|
for _, lookup := range lookups {
|
2022-08-09 12:04:57 +03:00
|
|
|
if tracer, err := lookup(code, ctx, cfg); err == nil {
|
2021-11-09 14:09:35 +03:00
|
|
|
return tracer, nil
|
|
|
|
}
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 14:56:11 +03:00
|
|
|
}
|
2021-11-09 14:09:35 +03:00
|
|
|
return nil, errors.New("tracer not found")
|
cmd, core, eth/tracers: support fancier js tracing (#15516)
* cmd, core, eth/tracers: support fancier js tracing
* eth, internal/web3ext: rework trace API, concurrency, chain tracing
* eth/tracers: add three more JavaScript tracers
* eth/tracers, vendor: swap ottovm to duktape for tracing
* core, eth, internal: finalize call tracer and needed extras
* eth, tests: prestate tracer, call test suite, rewinding
* vendor: fix windows builds for tracer js engine
* vendor: temporary duktape fix
* eth/tracers: fix up 4byte and evmdis tracer
* vendor: pull in latest duktape with my upstream fixes
* eth: fix some review comments
* eth: rename rewind to reexec to make it more obvious
* core/vm: terminate tracing using defers
2017-12-21 14:56:11 +03:00
|
|
|
}
|