Skip to content

Commit

Permalink
core: more detailed metrics for block processing (ethereum#18119)
Browse files Browse the repository at this point in the history
  • Loading branch information
gzliudan authored and JukLee0ira committed Jan 1, 2025
1 parent cdd760c commit e8f448e
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions core/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,18 @@ import (
)

var (
blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil)
CheckpointCh = make(chan int)
ErrNoGenesis = errors.New("Genesis not found in chain")
blockInsertTimer = metrics.NewRegisteredTimer("chain/inserts", nil)
blockValidationTimer = metrics.NewRegisteredTimer("chain/validation", nil)
blockExecutionTimer = metrics.NewRegisteredTimer("chain/execution", nil)
blockWriteTimer = metrics.NewRegisteredTimer("chain/write", nil)

blockReorgMeter = metrics.NewRegisteredMeter("chain/reorg/executes", nil)
blockReorgAddMeter = metrics.NewRegisteredMeter("chain/reorg/add", nil)
blockReorgDropMeter = metrics.NewRegisteredMeter("chain/reorg/drop", nil)

CheckpointCh = make(chan int)

ErrNoGenesis = errors.New("Genesis not found in chain")
)

const (
Expand Down Expand Up @@ -1658,7 +1663,9 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
}
feeCapacity := state.GetTRC21FeeCapacityFromStateWithCache(parent.Root(), statedb)
// Process block using the parent state as reference point.
t0 := time.Now()
receipts, logs, usedGas, err := bc.processor.Process(block, statedb, tradingState, bc.vmConfig, feeCapacity)
t1 := time.Now()
if err != nil {
bc.reportBlock(block, receipts, err)
return i, events, coalescedLogs, err
Expand All @@ -1669,19 +1676,27 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
bc.reportBlock(block, receipts, err)
return i, events, coalescedLogs, err
}
t2 := time.Now()
proctime := time.Since(bstart)

// Write the block to the chain and get the status.
status, err := bc.WriteBlockWithState(block, receipts, statedb, tradingState, lendingState)
t3 := time.Now()
if err != nil {
return i, events, coalescedLogs, err
}

blockInsertTimer.UpdateSince(bstart)
blockExecutionTimer.Update(t1.Sub(t0))
blockValidationTimer.Update(t2.Sub(t1))
blockWriteTimer.Update(t3.Sub(t2))

switch status {
case CanonStatTy:
log.Debug("Inserted new block from downloader", "number", block.Number(), "hash", block.Hash(), "uncles", len(block.Uncles()),
"txs", len(block.Transactions()), "gas", block.GasUsed(), "elapsed", common.PrettyDuration(time.Since(bstart)))

coalescedLogs = append(coalescedLogs, logs...)
blockInsertTimer.UpdateSince(bstart)
events = append(events, ChainEvent{block, block.Hash(), logs})
lastCanon = block

Expand All @@ -1695,8 +1710,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, []
case SideStatTy:
log.Debug("Inserted forked block from downloader", "number", block.Number(), "hash", block.Hash(), "diff", block.Difficulty(), "elapsed",
common.PrettyDuration(time.Since(bstart)), "txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()))

blockInsertTimer.UpdateSince(bstart)
events = append(events, ChainSideEvent{block})
bc.UpdateBlocksHashCache(block)
}
Expand Down Expand Up @@ -2015,7 +2028,6 @@ func (bc *BlockChain) insertBlock(block *types.Block) ([]interface{}, []*types.L
"txs", len(block.Transactions()), "gas", block.GasUsed(), "elapsed", common.PrettyDuration(time.Since(block.ReceivedAt)))
coalescedLogs = append(coalescedLogs, result.logs...)
events = append(events, ChainEvent{block, block.Hash(), result.logs})

// Only count canonical blocks for GC processing time
bc.gcproc += result.proctime
bc.UpdateBlocksHashCache(block)
Expand All @@ -2026,10 +2038,8 @@ func (bc *BlockChain) insertBlock(block *types.Block) ([]interface{}, []*types.L
case SideStatTy:
log.Debug("Inserted forked block from fetcher", "number", block.Number(), "hash", block.Hash(), "diff", block.Difficulty(), "elapsed",
common.PrettyDuration(time.Since(block.ReceivedAt)), "txs", len(block.Transactions()), "gas", block.GasUsed(), "uncles", len(block.Uncles()))

blockInsertTimer.Update(result.proctime)
events = append(events, ChainSideEvent{block})

bc.UpdateBlocksHashCache(block)
}
stats.processed++
Expand Down

0 comments on commit e8f448e

Please sign in to comment.