Skip to content

Commit

Permalink
worker: no need to add more transaction if not mining
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
setunapo committed Nov 15, 2022
1 parent c80586c commit 6fab891
Showing 1 changed file with 7 additions and 34 deletions.
41 changes: 7 additions & 34 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 6fab891

Please sign in to comment.