diff --git a/miner/worker.go b/miner/worker.go index 863726cf47..dc4dc52c33 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -81,7 +81,9 @@ const ( ) var ( - commitTxsTimer = metrics.NewRegisteredTimer("worker/committxs", nil) + commitTxsTimer = metrics.NewRegisteredTimer("worker/committxs", nil) + commitBlockTimer = metrics.NewRegisteredTimer("worker/commitblock", nil) + finalizeBlockTimer = metrics.NewRegisteredTimer("worker/finalizeblock", nil) ) // environment is the worker's current environment and holds all of the current state information. @@ -635,19 +637,22 @@ func (w *worker) resultLoop() { } logs = append(logs, receipt.Logs...) } + + // Broadcast the block and announce chain insertion event + w.mux.Post(core.NewMinedBlockEvent{Block: block}) + // Commit block and state to database. task.state.SetExpectedStateRoot(block.Root()) + start := time.Now() _, err := w.chain.WriteBlockWithState(block, receipts, logs, task.state, true) if err != nil { log.Error("Failed writing block to chain", "err", err) continue } + commitBlockTimer.UpdateSince(start) log.Info("Successfully sealed new block", "number", block.Number(), "sealhash", sealhash, "hash", hash, "elapsed", common.PrettyDuration(time.Since(task.createdAt))) - // Broadcast the block and announce chain insertion event - w.mux.Post(core.NewMinedBlockEvent{Block: block}) - // Insert the block into the set of pending ones to resultLoop for confirmations w.unconfirmed.Insert(block.NumberU64(), block.Hash()) @@ -1017,10 +1022,12 @@ func (w *worker) commit(uncles []*types.Header, interval func(), update bool, st s.CorrectAccountsRoot(w.chain.CurrentBlock().Root()) + finalizeStart := time.Now() block, receipts, err := w.engine.FinalizeAndAssemble(w.chain, types.CopyHeader(w.current.header), s, w.current.txs, uncles, w.current.receipts) if err != nil { return err } + finalizeBlockTimer.UpdateSince(finalizeStart) if w.isRunning() { if interval != nil { interval()