Skip to content

Commit

Permalink
miner: eliminate the dead loop possibility for newWorkLoop and `mai…
Browse files Browse the repository at this point in the history
…nLoop` (ethereum#28677)

discard the intervalAdjust message if the channel is full
  • Loading branch information
FletcherMan authored and Doozers committed Dec 22, 2023
1 parent d3f4ad3 commit ce47ab5
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit ce47ab5

Please sign in to comment.