Skip to content

Commit

Permalink
miner: no need to broadcast sidechain header mined by this validator (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
qinglin89 authored Mar 28, 2023
1 parent ce60933 commit ece84d4
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -666,20 +666,23 @@ 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 {
if err != nil {
log.Error("Failed writing block to chain", "err", err, "status", status)
} else {
log.Info("Written block as SideChain and avoid broadcasting", "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())
Expand Down

0 comments on commit ece84d4

Please sign in to comment.