From 0d25fbc37dbfbe7fca936d6ba22555f64dbc833a Mon Sep 17 00:00:00 2001 From: Sina Mahmoodi Date: Mon, 26 Jun 2023 11:21:27 +0200 Subject: [PATCH] pass logger to BC through vmConfig --- cmd/utils/flags.go | 8 ++++---- core/blockchain.go | 15 +++++++++------ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index e9cbe7f189..5df88ce008 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -2163,15 +2163,15 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh cache.TrieDirtyLimit = ctx.Int(CacheFlag.Name) * ctx.Int(CacheGCFlag.Name) / 100 } vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)} - + if ctx.IsSet(VMTraceFlag.Name) { + vmcfg.Tracer = tracers.NewPrinter() + } // Disable transaction indexing/unindexing by default. chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil) if err != nil { Fatalf("Can't create BlockChain: %v", err) } - if ctx.IsSet(VMTraceFlag.Name) { - chain.SetLogger(tracers.NewPrinter()) - } + return chain, chainDb } diff --git a/core/blockchain.go b/core/blockchain.go index cfc6cc7c51..becda25c4d 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -265,6 +265,14 @@ 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, @@ -282,6 +290,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis futureBlocks: lru.NewCache[common.Hash, *types.Block](maxFutureBlocks), engine: engine, vmConfig: vmConfig, + logger: logger, } bc.flushInterval.Store(int64(cacheConfig.TrieTimeLimit)) bc.forker = NewForkChoice(bc, shouldPreserve) @@ -453,12 +462,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis return bc, nil } -// TODO: need to move this to NewBlockchain to capture genesis block -func (bc *BlockChain) SetLogger(l BlockchainLogger) { - bc.logger = l - bc.vmConfig.Tracer = l -} - // empty returns an indicator whether the blockchain is empty. // Note, it's a special case that we connect a non-empty ancient // database with an empty node, so that we can plugin the ancient