diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 5df88ce008..84820cfb3e 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1741,6 +1741,9 @@ 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) diff --git a/core/blockchain.go b/core/blockchain.go index becda25c4d..f7af512435 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -250,11 +250,19 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis Journal: cacheConfig.TrieCleanJournal, Preimages: cacheConfig.Preimages, }) + var logger BlockchainLogger + if vmConfig.Tracer != nil { + l, ok := vmConfig.Tracer.(BlockchainLogger) + if !ok { + return nil, fmt.Errorf("only extended tracers are supported for live mode") + } + logger = l + } // Setup the genesis block, commit the provided genesis specification // to database if the genesis block is not present yet, or load the // stored one from database. // TODO: pass in blockchainLogger here to catch genesis block and allocs - chainConfig, genesisHash, genesisErr := SetupGenesisBlockWithOverride(db, triedb, genesis, overrides, nil) + chainConfig, genesisHash, genesisErr := SetupGenesisBlockWithOverride(db, triedb, genesis, overrides, logger) if _, ok := genesisErr.(*params.ConfigCompatError); genesisErr != nil && !ok { return nil, genesisErr } @@ -265,14 +273,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis } log.Info(strings.Repeat("-", 153)) log.Info("") - var logger BlockchainLogger - if vmConfig.Tracer != nil { - l, ok := vmConfig.Tracer.(BlockchainLogger) - if !ok { - return nil, fmt.Errorf("only extended tracers are supported for live mode") - } - logger = l - } bc := &BlockChain{ chainConfig: chainConfig, diff --git a/eth/backend.go b/eth/backend.go index b3338918be..c8d9c16507 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -42,6 +42,7 @@ 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" @@ -192,6 +193,9 @@ 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 a98d9ee4aa..c61cb26861 100644 --- a/eth/ethconfig/config.go +++ b/eth/ethconfig/config.go @@ -147,6 +147,9 @@ 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:"-"`