|
|
@@ -354,7 +354,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
|
|
|
case <-w.startCh:
|
|
|
clearPending(w.chain.CurrentBlock().NumberU64())
|
|
|
timestamp = time.Now().Unix()
|
|
|
- commit(false, commitInterruptNewHead)
|
|
|
+ commit(true, commitInterruptNewHead)
|
|
|
|
|
|
case head := <-w.chainHeadCh:
|
|
|
if !w.isRunning() {
|
|
|
@@ -362,7 +362,7 @@ func (w *worker) newWorkLoop(recommit time.Duration) {
|
|
|
}
|
|
|
clearPending(head.Block.NumberU64())
|
|
|
timestamp = time.Now().Unix()
|
|
|
- commit(false, commitInterruptNewHead)
|
|
|
+ commit(true, commitInterruptNewHead)
|
|
|
|
|
|
case <-timer.C:
|
|
|
// If mining is running resubmit a new work cycle periodically to pull in
|
|
|
@@ -737,7 +737,14 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
|
|
|
}
|
|
|
|
|
|
var coalescedLogs []*types.Log
|
|
|
-
|
|
|
+ var stopTimer *time.Timer
|
|
|
+ delay := w.engine.Delay(w.chain, w.current.header)
|
|
|
+ if delay != nil {
|
|
|
+ stopTimer = time.NewTimer(*delay - w.config.DelayLeftOver)
|
|
|
+ log.Debug("Time left for mining work", "left", (*delay - w.config.DelayLeftOver).String(), "leftover", w.config.DelayLeftOver)
|
|
|
+ defer stopTimer.Stop()
|
|
|
+ }
|
|
|
+LOOP:
|
|
|
for {
|
|
|
// In the following three cases, we will interrupt the execution of the transaction.
|
|
|
// (1) new head block event arrival, the interrupt signal is 1
|
|
|
@@ -764,6 +771,14 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin
|
|
|
log.Trace("Not enough gas for further transactions", "have", w.current.gasPool, "want", params.TxGas)
|
|
|
break
|
|
|
}
|
|
|
+ if stopTimer != nil {
|
|
|
+ select {
|
|
|
+ case <-stopTimer.C:
|
|
|
+ log.Info("Not enough time for further transactions", "txs", len(w.current.txs))
|
|
|
+ break LOOP
|
|
|
+ default:
|
|
|
+ }
|
|
|
+ }
|
|
|
// Retrieve the next transaction and abort if all done
|
|
|
tx := txs.Peek()
|
|
|
if tx == nil {
|
|
|
@@ -937,36 +952,33 @@ func (w *worker) commitNewWork(interrupt *int32, noempty bool, timestamp int64)
|
|
|
pending, err := w.eth.TxPool().Pending()
|
|
|
if err != nil {
|
|
|
log.Error("Failed to fetch pending transactions", "err", err)
|
|
|
- return
|
|
|
}
|
|
|
// Short circuit if there is no available pending transactions
|
|
|
- if len(pending) == 0 {
|
|
|
- w.updateSnapshot()
|
|
|
- return
|
|
|
- }
|
|
|
- start := time.Now()
|
|
|
- // Split the pending transactions into locals and remotes
|
|
|
- localTxs, remoteTxs := make(map[common.Address]types.Transactions), pending
|
|
|
- for _, account := range w.eth.TxPool().Locals() {
|
|
|
- if txs := remoteTxs[account]; len(txs) > 0 {
|
|
|
- delete(remoteTxs, account)
|
|
|
- localTxs[account] = txs
|
|
|
+ if len(pending) != 0 {
|
|
|
+ start := time.Now()
|
|
|
+ // Split the pending transactions into locals and remotes
|
|
|
+ localTxs, remoteTxs := make(map[common.Address]types.Transactions), pending
|
|
|
+ for _, account := range w.eth.TxPool().Locals() {
|
|
|
+ if txs := remoteTxs[account]; len(txs) > 0 {
|
|
|
+ delete(remoteTxs, account)
|
|
|
+ localTxs[account] = txs
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if len(localTxs) > 0 {
|
|
|
- txs := types.NewTransactionsByPriceAndNonce(w.current.signer, localTxs)
|
|
|
- if w.commitTransactions(txs, w.coinbase, interrupt) {
|
|
|
- return
|
|
|
+ if len(localTxs) > 0 {
|
|
|
+ txs := types.NewTransactionsByPriceAndNonce(w.current.signer, localTxs)
|
|
|
+ if w.commitTransactions(txs, w.coinbase, interrupt) {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
- }
|
|
|
- if len(remoteTxs) > 0 {
|
|
|
- txs := types.NewTransactionsByPriceAndNonce(w.current.signer, remoteTxs)
|
|
|
- if w.commitTransactions(txs, w.coinbase, interrupt) {
|
|
|
- return
|
|
|
+ if len(remoteTxs) > 0 {
|
|
|
+ txs := types.NewTransactionsByPriceAndNonce(w.current.signer, remoteTxs)
|
|
|
+ if w.commitTransactions(txs, w.coinbase, interrupt) {
|
|
|
+ return
|
|
|
+ }
|
|
|
}
|
|
|
+ commitTxsTimer.UpdateSince(start)
|
|
|
+ log.Info("Gas pool", "height", header.Number.String(), "pool", w.current.gasPool.String())
|
|
|
}
|
|
|
- commitTxsTimer.UpdateSince(start)
|
|
|
- log.Info("Gas pool", "height", header.Number.String(), "pool", w.current.gasPool.String())
|
|
|
w.commit(uncles, w.fullTaskHook, true, tstart)
|
|
|
}
|
|
|
|