From 0a9734a9cfee0a0725b22019af1dd9d9cd368705 Mon Sep 17 00:00:00 2001 From: Martin Holst Swende Date: Fri, 5 Nov 2021 15:27:32 +0100 Subject: [PATCH] miner, consensus/clique: avoid memory leak during block stasis --- consensus/clique/clique.go | 6 ++---- miner/worker.go | 3 +++ 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/consensus/clique/clique.go b/consensus/clique/clique.go index a6a16c84afc8..38597e15267a 100644 --- a/consensus/clique/clique.go +++ b/consensus/clique/clique.go @@ -600,8 +600,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res } // For 0-period chains, refuse to seal empty blocks (no reward but would spin sealing) if c.config.Period == 0 && len(block.Transactions()) == 0 { - log.Info("Sealing paused, waiting for transactions") - return nil + return errors.New("sealing paused while waiting for transactions") } // Don't hold the signer fields for the entire sealing procedure c.lock.RLock() @@ -621,8 +620,7 @@ func (c *Clique) Seal(chain consensus.ChainHeaderReader, block *types.Block, res if recent == signer { // Signer is among recents, only wait if the current block doesn't shift it out if limit := uint64(len(snap.Signers)/2 + 1); number < limit || seen > number-limit { - log.Info("Signed recently, must wait for others") - return nil + return errors.New("signed recently, must wait for others") } } } diff --git a/miner/worker.go b/miner/worker.go index 4ef2c8c0da38..77e868c2bf4f 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -593,6 +593,9 @@ func (w *worker) taskLoop() { if err := w.engine.Seal(w.chain, task.block, w.resultCh, stopCh); err != nil { log.Warn("Block sealing failed", "err", err) + w.pendingMu.Lock() + delete(w.pendingTasks, sealHash) + w.pendingMu.Unlock() } case <-w.exitCh: interrupt()