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 authored and brilliant-lx committed Nov 16, 2022
1 parent fe1c862 commit 086a99b
Showing 1 changed file with 2 additions and 28 deletions.
30 changes: 2 additions & 28 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ const (
)

var (
commitTxsTimer = metrics.NewRegisteredTimer("worker/committxs", nil)
writeBlockTimer = metrics.NewRegisteredTimer("worker/writeblock", nil)
finalizeBlockTimer = metrics.NewRegisteredTimer("worker/finalizeblock", nil)
)
Expand Down Expand Up @@ -542,33 +541,7 @@ 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 {
if w.isRunning() {
// 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.
Expand All @@ -577,6 +550,7 @@ func (w *worker) mainLoop() {
w.commitWork(nil, true, time.Now().Unix())
}
}

atomic.AddInt32(&w.newTxs, int32(len(ev.Txs)))

// System stopped
Expand Down

0 comments on commit 086a99b

Please sign in to comment.