Skip to content

Commit f1794ba

Browse files
authored
miner: eliminate the dead loop possibility for newWorkLoop and mainLoop (#28677)
discard the intervalAdjust message if the channel is full
1 parent 0f74aad commit f1794ba

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

miner/worker.go

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,7 +1074,7 @@ func (w *worker) commitWork(interrupt *atomic.Int32, timestamp int64) {
10741074
case err == nil:
10751075
// The entire block is filled, decrease resubmit interval in case
10761076
// of current interval is larger than the user-specified one.
1077-
w.resubmitAdjustCh <- &intervalAdjust{inc: false}
1077+
w.adjustResubmitInterval(&intervalAdjust{inc: false})
10781078

10791079
case errors.Is(err, errBlockInterruptedByRecommit):
10801080
// Notify resubmit loop to increase resubmitting interval if the
@@ -1084,10 +1084,10 @@ func (w *worker) commitWork(interrupt *atomic.Int32, timestamp int64) {
10841084
if ratio < 0.1 {
10851085
ratio = 0.1
10861086
}
1087-
w.resubmitAdjustCh <- &intervalAdjust{
1087+
w.adjustResubmitInterval(&intervalAdjust{
10881088
ratio: ratio,
10891089
inc: true,
1090-
}
1090+
})
10911091

10921092
case errors.Is(err, errBlockInterruptedByNewHead):
10931093
// If the block building is interrupted by newhead event, discard it
@@ -1169,6 +1169,15 @@ func (w *worker) isTTDReached(header *types.Header) bool {
11691169
return td != nil && ttd != nil && td.Cmp(ttd) >= 0
11701170
}
11711171

1172+
// adjustResubmitInterval adjusts the resubmit interval.
1173+
func (w *worker) adjustResubmitInterval(message *intervalAdjust) {
1174+
select {
1175+
case w.resubmitAdjustCh <- message:
1176+
default:
1177+
log.Warn("the resubmitAdjustCh is full, discard the message")
1178+
}
1179+
}
1180+
11721181
// copyReceipts makes a deep copy of the given receipts.
11731182
func copyReceipts(receipts []*types.Receipt) []*types.Receipt {
11741183
result := make([]*types.Receipt, len(receipts))

0 commit comments

Comments
 (0)