Skip to content

Commit

Permalink
miner: fetch the pending transaction only once
Browse files Browse the repository at this point in the history
  • Loading branch information
cp-jhjin authored and sadoci committed Jan 25, 2023
1 parent 7b3df44 commit 95bf414
Showing 1 changed file with 10 additions and 21 deletions.
31 changes: 10 additions & 21 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -1219,24 +1219,15 @@ func (w *worker) throttleMining(ts []int64) (int64, int64) {
}

func (w *worker) commitTransactionsEx(env *environment, interrupt *int32, tstart time.Time) bool {
interval := 10 * time.Millisecond

// committed transactions in this round
// committed transactions
committedTxs := map[common.Hash]*types.Transaction{}
round := 0
for {
round++

// Fill the block with all available pending transactions.
pending := w.eth.TxPool().Pending(true)
// Short circuit if there is no available pending transactions
if len(pending) == 0 {
if time.Until(*env.till) <= 0 {
break
}
time.Sleep(interval)
continue
}
// Fill the block with all available pending transactions.
pending := w.eth.TxPool().Pending(true)

// Short circuit if there is no available pending transactions
if len(pending) != 0 {

// using new simple round-robin ordering instead of old one.
if params.PrefetchCount == 0 {
Expand Down Expand Up @@ -1268,13 +1259,11 @@ func (w *worker) commitTransactionsEx(env *environment, interrupt *int32, tstart
}
}

if time.Until(*env.till) <= 0 {
break
}
time.Sleep(interval)
round++
}
log.Debug("Block", "number", env.header.Number.Int64(), "elapsed", common.PrettyDuration(time.Since(tstart)), "txs", len(committedTxs), "round", round)

time.Sleep(time.Until(*env.till))

log.Debug("Block", "number", env.header.Number.Int64(), "elapsed", common.PrettyDuration(time.Since(tstart)), "txs", len(committedTxs))

return false
}
Expand Down

0 comments on commit 95bf414

Please # to comment.