Skip to content

Commit 476fb56

Browse files
authored
miner, consensus/clique: avoid memory leak during block stasis (#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 8d7e606 commit 476fb56

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
@@ -600,8 +600,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
600600
}
601601
// For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing)
602602
if c.config.Period == 0 && len(block.Transactions()) == 0 {
603-
log.Info("Sealing paused, waiting for transactions")
604-
return nil
603+
return errors.New("sealing paused while waiting for transactions")
605604
}
606605
// Don't hold the signer fields for the entire sealing procedure
607606
c.lock.RLock()
@@ -621,8 +620,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res
621620
if recent == signer {
622621
// Signer is among recents, only wait if the current block doesn't shift it out
623622
if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit {
624-
log.Info("Signed recently, must wait for others")
625-
return nil
623+
return errors.New("signed recently, must wait for others")
626624
}
627625
}
628626
}

miner/worker.go

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

594594
if err := w.engine.Seal(w.chain, task.block, w.resultCh, stopCh); err != nil {
595595
log.Warn("Block sealing failed", "err", err)
596+
w.pendingMu.Lock()
597+
delete(w.pendingTasks, sealHash)
598+
w.pendingMu.Unlock()
596599
}
597600
case <-w.exitCh:
598601
interrupt()

0 commit comments

Comments
 (0)