diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index c05e76e1a5..c8d77192b8 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -54,6 +54,7 @@ import ( "github.com/ethereum/go-ethereum/eth/filters" "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/eth/tracers" + liveTracers "github.com/ethereum/go-ethereum/eth/tracers/live" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb/remotedb" "github.com/ethereum/go-ethereum/ethstats" @@ -518,9 +519,9 @@ var ( Usage: "Record information useful for VM and contract debugging", Category: flags.VMCategory, } - VMTraceFlag = &cli.BoolFlag{ + VMTraceFlag = &cli.StringFlag{ Name: "vmtrace", - Usage: "Record internal VM operations (costly)", + Usage: "Name of tracer which should record internal VM operations (costly)", Category: flags.VMCategory, } @@ -1723,9 +1724,6 @@ func SetEthConfig(ctx *cli.Context, stack *node.Node, cfg *ethconfig.Config) { // TODO(fjl): force-enable this in --dev mode cfg.EnablePreimageRecording = ctx.Bool(VMEnableDebugFlag.Name) } - if ctx.IsSet(VMTraceFlag.Name) { - cfg.LiveTrace = ctx.Bool(VMTraceFlag.Name) - } if ctx.IsSet(RPCGlobalGasCapFlag.Name) { cfg.RPCGasCap = ctx.Uint64(RPCGlobalGasCapFlag.Name) @@ -2143,7 +2141,13 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh } vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)} if ctx.IsSet(VMTraceFlag.Name) { - vmcfg.Tracer = tracers.NewPrinter() + if name := ctx.String(VMTraceFlag.Name); name != "" { + t, err := liveTracers.New(name) + if err != nil { + Fatalf("Failed to create tracer %q: %v", name, err) + } + vmcfg.Tracer = t + } } // Disable transaction indexing/unindexing by default. chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil) diff --git a/eth/backend.go b/eth/backend.go index 6cb5611d32..667200bced 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -44,7 +44,6 @@ import ( "github.com/ethereum/go-ethereum/eth/gasprice" "github.com/ethereum/go-ethereum/eth/protocols/eth" "github.com/ethereum/go-ethereum/eth/protocols/snap" - "github.com/ethereum/go-ethereum/eth/tracers" "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/internal/ethapi" @@ -194,9 +193,6 @@ func New(stack *node.Node, config *ethconfig.Config) (*Ethereum, error) { Preimages: config.Preimages, } ) - if config.LiveTrace { - vmConfig.Tracer = tracers.NewPrinter() - } // Override the chain config with provided settings. var overrides core.ChainOverrides if config.OverrideCancun != nil { diff --git a/eth/ethconfig/config.go b/eth/ethconfig/config.go index 55dd56316e..4bc8b8dc6c 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -140,9 +140,6 @@ type Config struct { // Enables tracking of SHA3 preimages in the VM EnablePreimageRecording bool - // LiveTrace will enable tracing during normal chain processing. - LiveTrace bool - // Miscellaneous options DocRoot string `toml:"-"` diff --git a/eth/tracers/printer.go b/eth/tracers/live/printer.go similarity index 95% rename from eth/tracers/printer.go rename to eth/tracers/live/printer.go index a07a7ea02b..8d9952fb5f 100644 --- a/eth/tracers/printer.go +++ b/eth/tracers/live/printer.go @@ -1,4 +1,4 @@ -package tracers +package live import ( "encoding/json" @@ -8,14 +8,19 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" ) +func init() { + register("printer", newPrinter) +} + type Printer struct{} -func NewPrinter() *Printer { - return &Printer{} +func newPrinter() (core.BlockchainLogger, error) { + return &Printer{}, nil } // CaptureStart implements the EVMLogger interface to initialize the tracing operation. @@ -91,7 +96,7 @@ func (p *Printer) OnGenesisBlock(b *types.Block, alloc core.GenesisAlloc) { fmt.Printf("OnGenesisBlock: b=%v, allocLength=%d\n", b.NumberU64(), len(alloc)) } -func (p *Printer) OnBalanceChange(a common.Address, prev, new *big.Int) { +func (p *Printer) OnBalanceChange(a common.Address, prev, new *big.Int, reason state.BalanceChangeReason) { fmt.Printf("OnBalanceChange: a=%v, prev=%v, new=%v\n", a, prev, new) }