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 1/3] 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()) From 1d654dd0594073098f6469a49c0e5b3c511b2a91 Mon Sep 17 00:00:00 2001 From: qinglin89 <316032931@qq.com> Date: Tue, 28 Mar 2023 15:22:55 +0800 Subject: [PATCH 2/3] miner/worker: udpate logs more clear --- miner/worker.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/miner/worker.go b/miner/worker.go index f7d122a37e..fc809d64ad 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -671,7 +671,11 @@ func (w *worker) resultLoop() { start := time.Now() 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) + if err != nil { + log.Error("Failed writing block to chain", "err", err, "status", status) + } else { + log.Info("Writen block as SideChain and avoid broadcasting", "status", status) + } continue } writeBlockTimer.UpdateSince(start) From 63b32cc4706abcf660ec17f86ee36d6fab2c4685 Mon Sep 17 00:00:00 2001 From: qinglin89 <316032931@qq.com> Date: Tue, 28 Mar 2023 15:29:35 +0800 Subject: [PATCH 3/3] miner/worker: typo --- miner/worker.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/miner/worker.go b/miner/worker.go index fc809d64ad..9f4cce2988 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -674,7 +674,7 @@ func (w *worker) resultLoop() { if err != nil { log.Error("Failed writing block to chain", "err", err, "status", status) } else { - log.Info("Writen block as SideChain and avoid broadcasting", "status", status) + log.Info("Written block as SideChain and avoid broadcasting", "status", status) } continue }