From f1794ba2788baf34489847bfa9ca00e067507db0 Mon Sep 17 00:00:00 2001 From: FletcherMan Date: Fri, 15 Dec 2023 11:48:55 +0800 Subject: [PATCH] miner: eliminate the dead loop possibility for `newWorkLoop` and `mainLoop` (#28677) discard the intervalAdjust message if the channel is full --- miner/worker.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index f68070281..2ed91cc18 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -1074,7 +1074,7 @@ func (w *worker) commitWork(interrupt *atomic.Int32, timestamp int64) { case err == nil: // The entire block is filled, decrease resubmit interval in case // of current interval is larger than the user-specified one. - w.resubmitAdjustCh <- &intervalAdjust{inc: false} + w.adjustResubmitInterval(&intervalAdjust{inc: false}) case errors.Is(err, errBlockInterruptedByRecommit): // Notify resubmit loop to increase resubmitting interval if the @@ -1084,10 +1084,10 @@ func (w *worker) commitWork(interrupt *atomic.Int32, timestamp int64) { if ratio < 0.1 { ratio = 0.1 } - w.resubmitAdjustCh <- &intervalAdjust{ + w.adjustResubmitInterval(&intervalAdjust{ ratio: ratio, inc: true, - } + }) case errors.Is(err, errBlockInterruptedByNewHead): // If the block building is interrupted by newhead event, discard it @@ -1169,6 +1169,15 @@ func (w *worker) isTTDReached(header *types.Header) bool { return td != nil && ttd != nil && td.Cmp(ttd) >= 0 } +// adjustResubmitInterval adjusts the resubmit interval. +func (w *worker) adjustResubmitInterval(message *intervalAdjust) { + select { + case w.resubmitAdjustCh <- message: + default: + log.Warn("the resubmitAdjustCh is full, discard the message") + } +} + // copyReceipts makes a deep copy of the given receipts. func copyReceipts(receipts []*types.Receipt) []*types.Receipt { result := make([]*types.Receipt, len(receipts))