miner: eliminate the dead loop possibility for `newWorkLoop` and `mainLoop` (#28677)

discard the intervalAdjust message if the channel is full
pull/28685/head
FletcherMan 11 months ago committed by GitHub
parent 0f74aad641
commit f1794ba278
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 15
      miner/worker.go

@ -1074,7 +1074,7 @@ func (w *worker) commitWork(interrupt *atomic.Int32, timestamp int64) {
case err == nil: case err == nil:
// The entire block is filled, decrease resubmit interval in case // The entire block is filled, decrease resubmit interval in case
// of current interval is larger than the user-specified one. // 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): case errors.Is(err, errBlockInterruptedByRecommit):
// Notify resubmit loop to increase resubmitting interval if the // 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 { if ratio < 0.1 {
ratio = 0.1 ratio = 0.1
} }
w.resubmitAdjustCh <- &intervalAdjust{ w.adjustResubmitInterval(&intervalAdjust{
ratio: ratio, ratio: ratio,
inc: true, inc: true,
} })
case errors.Is(err, errBlockInterruptedByNewHead): case errors.Is(err, errBlockInterruptedByNewHead):
// If the block building is interrupted by newhead event, discard it // 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 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. // copyReceipts makes a deep copy of the given receipts.
func copyReceipts(receipts []*types.Receipt) []*types.Receipt { func copyReceipts(receipts []*types.Receipt) []*types.Receipt {
result := make([]*types.Receipt, len(receipts)) result := make([]*types.Receipt, len(receipts))

Loading…
Cancel
Save