From d35ead2375c4218820be47ba09e07a5047023a62 Mon Sep 17 00:00:00 2001 From: qinglin89 <316032931@qq.com> Date: Wed, 22 Mar 2023 20:23:31 +0800 Subject: [PATCH] miner: no need to broadcast sidechain header mined by this validator --- miner/worker.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 37f458693e..f7d122a37e 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -666,20 +666,19 @@ func (w *worker) resultLoop() { w.recentMinedBlocks.Add(block.NumberU64(), []common.Hash{block.ParentHash()}) } - // 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.WriteBlockAndSetHead(block, receipts, logs, task.state, true) - if err != nil { - log.Error("Failed writing block to chain", "err", err) + status, err := w.chain.WriteBlockAndSetHead(block, receipts, logs, task.state, true) + if status != core.CanonStatTy { + log.Error("Failed writing block to chain", "err", err, "status", status) continue } writeBlockTimer.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())