From 6fab8910ee4a26e5f04e6d79209b12c3db16bbe7 Mon Sep 17 00:00:00 2001 From: setunapo Date: Tue, 15 Nov 2022 17:30:49 +0800 Subject: [PATCH] worker: no need to add more transaction if not mining It could be a very old PoW logic, which try to add more transaction into the pending block when mining is stopped. Mining can be stopped when: 1.download started. 2.manually stopped by RPC. It is unnecessary to add more transaction into the pending block if a validator is stopped. And updateSnapshot() is not needed as well, it is to get the pending mining snapshot. --- miner/worker.go | 41 +++++++---------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/miner/worker.go b/miner/worker.go index 8b646d35cf..47156be6b2 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -542,41 +542,14 @@ func (w *worker) mainLoop() { } case ev := <-w.txsCh: - // Apply transactions to the pending state if we're not sealing - // - // Note all transactions received may not be continuous with transactions - // already included in the current sealing block. These transactions will - // be automatically eliminated. - if !w.isRunning() && w.current != nil { - start := time.Now() - // If block is already full, abort - if gp := w.current.gasPool; gp != nil && gp.Gas() < params.TxGas { - continue - } - txs := make(map[common.Address]types.Transactions) - for _, tx := range ev.Txs { - acc, _ := types.Sender(w.current.signer, tx) - txs[acc] = append(txs[acc], tx) - } - txset := types.NewTransactionsByPriceAndNonce(w.current.signer, txs, w.current.header.BaseFee) - tcount := w.current.tcount - w.commitTransactions(w.current, txset, nil, nil) - commitTxsTimer.UpdateSince(start) - - // Only update the snapshot if any new transactions were added - // to the pending block - if tcount != w.current.tcount { - w.updateSnapshot(w.current) - } - } else { - // Special case, if the consensus engine is 0 period clique(dev mode), - // submit sealing work here since all empty submission will be rejected - // by clique. Of course the advance sealing(empty submission) is disabled. - if (w.chainConfig.Clique != nil && w.chainConfig.Clique.Period == 0) || - (w.chainConfig.Parlia != nil && w.chainConfig.Parlia.Period == 0) { - w.commitWork(nil, true, time.Now().Unix()) - } + // Special case, if the consensus engine is 0 period clique(dev mode), + // submit sealing work here since all empty submission will be rejected + // by clique. Of course the advance sealing(empty submission) is disabled. + if (w.chainConfig.Clique != nil && w.chainConfig.Clique.Period == 0) || + (w.chainConfig.Parlia != nil && w.chainConfig.Parlia.Period == 0) { + w.commitWork(nil, true, time.Now().Unix()) } + atomic.AddInt32(&w.newTxs, int32(len(ev.Txs))) // System stopped