Skip to content

Commit abbf0d9

Browse files
holimanzzyalbert
authored andcommitted
miner, consensus/clique: avoid memory leak during block stasis (ethereum#23861)
This PR fixes a problem which arises on clique networks when there is a network stall. Previously, the worker packages were tracked, even if the sealing engine decided not to seal the block (due to clique rules about recent signing). These tracked-but-not-sealed blocks kept building up in memory. This PR changes the situation so the sealing engine instead returns an error, and the worker can thus un-track the package.
1 parent 6a551cc commit abbf0d9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

consensus/clique/clique.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -602,8 +602,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
602602
}
603603
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
604604
if c.config.Period == 0 && len(block.Transactions()) == 0 {
605-
log.Info("Sealing paused, waiting for transactions")
606-
return nil
605+
return errors.New("sealing paused while waiting for transactions")
607606
}
608607
// Don't hold the signer fields for the entire sealing procedure
609608
c.lock.RLock()
@@ -623,8 +622,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
623622
if recent == signer {
624623
// Signer is among recents, only wait if the current block doesn't shift it out
625624
if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit {
626-
log.Info("Signed recently, must wait for others")
627-
return nil
625+
return errors.New("signed recently, must wait for others")
628626
}
629627
}
630628
}

miner/worker.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,9 @@ func (w *worker) taskLoop() {
603603

604604
if err := w.engine.Seal(w.chain, task.block, w.resultCh, stopCh); err != nil {
605605
log.Warn("Block sealing failed", "err", err)
606+
w.pendingMu.Lock()
607+
delete(w.pendingTasks, sealHash)
608+
w.pendingMu.Unlock()
606609
}
607610
case <-w.exitCh:
608611
interrupt()

0 commit comments

Comments
 (0)