mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
core: bc.logger is duplicate with bc.vmconfig.tracer, use function instead
Signed-off-by: jsvisa <delweng@gmail.com>
This commit is contained in:
parent
80b529ea71
commit
3a9b93e3f3
1 changed files with 31 additions and 24 deletions
|
|
@ -258,7 +258,6 @@ type BlockChain struct {
|
||||||
prefetcher Prefetcher
|
prefetcher Prefetcher
|
||||||
processor Processor // Block transaction processor interface
|
processor Processor // Block transaction processor interface
|
||||||
vmConfig vm.Config
|
vmConfig vm.Config
|
||||||
logger *tracing.Hooks
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewBlockChain returns a fully initialised block chain using information
|
// NewBlockChain returns a fully initialised block chain using information
|
||||||
|
|
@ -301,7 +300,6 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
|
||||||
txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
|
txLookupCache: lru.NewCache[common.Hash, txLookup](txLookupCacheLimit),
|
||||||
engine: engine,
|
engine: engine,
|
||||||
vmConfig: vmConfig,
|
vmConfig: vmConfig,
|
||||||
logger: vmConfig.Tracer,
|
|
||||||
}
|
}
|
||||||
var err error
|
var err error
|
||||||
bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.insertStopped)
|
bc.hc, err = NewHeaderChain(db, chainConfig, engine, bc.insertStopped)
|
||||||
|
|
@ -411,10 +409,11 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
|
||||||
// it in advance.
|
// it in advance.
|
||||||
bc.engine.VerifyHeader(bc, bc.CurrentHeader())
|
bc.engine.VerifyHeader(bc, bc.CurrentHeader())
|
||||||
|
|
||||||
if bc.logger != nil && bc.logger.OnBlockchainInit != nil {
|
logger := bc.logger()
|
||||||
bc.logger.OnBlockchainInit(chainConfig)
|
if logger != nil && logger.OnBlockchainInit != nil {
|
||||||
|
logger.OnBlockchainInit(chainConfig)
|
||||||
}
|
}
|
||||||
if bc.logger != nil && bc.logger.OnGenesisBlock != nil {
|
if logger != nil && logger.OnGenesisBlock != nil {
|
||||||
if block := bc.CurrentBlock(); block.Number.Uint64() == 0 {
|
if block := bc.CurrentBlock(); block.Number.Uint64() == 0 {
|
||||||
alloc, err := getGenesisState(bc.db, block.Hash())
|
alloc, err := getGenesisState(bc.db, block.Hash())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -423,7 +422,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, genesis *Genesis
|
||||||
if alloc == nil {
|
if alloc == nil {
|
||||||
return nil, errors.New("live blockchain tracer requires genesis alloc to be set")
|
return nil, errors.New("live blockchain tracer requires genesis alloc to be set")
|
||||||
}
|
}
|
||||||
bc.logger.OnGenesisBlock(bc.genesisBlock, alloc)
|
logger.OnGenesisBlock(bc.genesisBlock, alloc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1156,8 +1155,8 @@ func (bc *BlockChain) Stop() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Allow tracers to clean-up and release resources.
|
// Allow tracers to clean-up and release resources.
|
||||||
if bc.logger != nil && bc.logger.OnClose != nil {
|
if logger := bc.logger(); logger != nil && logger.OnClose != nil {
|
||||||
bc.logger.OnClose()
|
logger.OnClose()
|
||||||
}
|
}
|
||||||
// Close the trie database, release all the held resources as the last step.
|
// Close the trie database, release all the held resources as the last step.
|
||||||
if err := bc.triedb.Close(); err != nil {
|
if err := bc.triedb.Close(); err != nil {
|
||||||
|
|
@ -1714,6 +1713,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness
|
||||||
// Track the singleton witness from this chain insertion (if any)
|
// Track the singleton witness from this chain insertion (if any)
|
||||||
var witness *stateless.Witness
|
var witness *stateless.Witness
|
||||||
|
|
||||||
|
bclogger := bc.logger()
|
||||||
for ; block != nil && err == nil || errors.Is(err, ErrKnownBlock); block, err = it.next() {
|
for ; block != nil && err == nil || errors.Is(err, ErrKnownBlock); block, err = it.next() {
|
||||||
// If the chain is terminating, stop processing blocks
|
// If the chain is terminating, stop processing blocks
|
||||||
if bc.insertStopped() {
|
if bc.insertStopped() {
|
||||||
|
|
@ -1753,8 +1753,8 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness
|
||||||
return nil, it.index, err
|
return nil, it.index, err
|
||||||
}
|
}
|
||||||
stats.processed++
|
stats.processed++
|
||||||
if bc.logger != nil && bc.logger.OnSkippedBlock != nil {
|
if bclogger != nil && bclogger.OnSkippedBlock != nil {
|
||||||
bc.logger.OnSkippedBlock(tracing.BlockEvent{
|
bclogger.OnSkippedBlock(tracing.BlockEvent{
|
||||||
Block: block,
|
Block: block,
|
||||||
TD: bc.GetTd(block.ParentHash(), block.NumberU64()-1),
|
TD: bc.GetTd(block.ParentHash(), block.NumberU64()-1),
|
||||||
Finalized: bc.CurrentFinalBlock(),
|
Finalized: bc.CurrentFinalBlock(),
|
||||||
|
|
@ -1776,7 +1776,7 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool, makeWitness
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, it.index, err
|
return nil, it.index, err
|
||||||
}
|
}
|
||||||
statedb.SetLogger(bc.logger)
|
statedb.SetLogger(bclogger)
|
||||||
|
|
||||||
// If we are past Byzantium, enable prefetching to pull in trie node paths
|
// If we are past Byzantium, enable prefetching to pull in trie node paths
|
||||||
// while processing transactions. Before Byzantium the prefetcher is mostly
|
// while processing transactions. Before Byzantium the prefetcher is mostly
|
||||||
|
|
@ -1881,20 +1881,22 @@ type blockProcessingResult struct {
|
||||||
// processBlock executes and validates the given block. If there was no error
|
// processBlock executes and validates the given block. If there was no error
|
||||||
// it writes the block and associated state to database.
|
// it writes the block and associated state to database.
|
||||||
func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, start time.Time, setHead bool) (_ *blockProcessingResult, blockEndErr error) {
|
func (bc *BlockChain) processBlock(block *types.Block, statedb *state.StateDB, start time.Time, setHead bool) (_ *blockProcessingResult, blockEndErr error) {
|
||||||
if bc.logger != nil && bc.logger.OnBlockStart != nil {
|
if logger := bc.logger(); logger != nil {
|
||||||
|
if logger.OnBlockStart != nil {
|
||||||
td := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
|
td := bc.GetTd(block.ParentHash(), block.NumberU64()-1)
|
||||||
bc.logger.OnBlockStart(tracing.BlockEvent{
|
logger.OnBlockStart(tracing.BlockEvent{
|
||||||
Block: block,
|
Block: block,
|
||||||
TD: td,
|
TD: td,
|
||||||
Finalized: bc.CurrentFinalBlock(),
|
Finalized: bc.CurrentFinalBlock(),
|
||||||
Safe: bc.CurrentSafeBlock(),
|
Safe: bc.CurrentSafeBlock(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
if bc.logger != nil && bc.logger.OnBlockEnd != nil {
|
if logger.OnBlockEnd != nil {
|
||||||
defer func() {
|
defer func() {
|
||||||
bc.logger.OnBlockEnd(blockEndErr)
|
logger.OnBlockEnd(blockEndErr)
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Process block using the parent state as reference point
|
// Process block using the parent state as reference point
|
||||||
pstart := time.Now()
|
pstart := time.Now()
|
||||||
|
|
@ -2537,3 +2539,8 @@ func (bc *BlockChain) SetTrieFlushInterval(interval time.Duration) {
|
||||||
func (bc *BlockChain) GetTrieFlushInterval() time.Duration {
|
func (bc *BlockChain) GetTrieFlushInterval() time.Duration {
|
||||||
return time.Duration(bc.flushInterval.Load())
|
return time.Duration(bc.flushInterval.Load())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// logger returns the tracing logger
|
||||||
|
func (bc *BlockChain) logger() *tracing.Hooks {
|
||||||
|
return bc.vmConfig.Tracer
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue