From f1991a5ae2a01731bd31a581e04fd0669b9e523d Mon Sep 17 00:00:00 2001 From: fudongbai <296179868@qq.com> Date: Mon, 15 Mar 2021 17:19:08 +0800 Subject: [PATCH] update to 200 ms --- eth/config.go | 2 +- miner/worker.go | 55 +++++++++++++++++++++++-------------------------- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/eth/config.go b/eth/config.go index 50444e9f67..05342a6306 100644 --- a/eth/config.go +++ b/eth/config.go @@ -58,7 +58,7 @@ var DefaultConfig = Config{ GasCeil: 8000000, GasPrice: big.NewInt(params.GWei), Recommit: 3 * time.Second, - DelayLeftOver: 100 * time.Millisecond, + DelayLeftOver: 50 * time.Millisecond, }, TxPool: core.DefaultTxPoolConfig, GPO: gasprice.Config{ diff --git a/miner/worker.go b/miner/worker.go index c82447a97f..ada34b7744 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -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 @@ -741,10 +741,10 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin delay := w.engine.Delay(w.chain, w.current.header) if delay != nil { stopTimer = time.NewTimer(*delay - w.config.DelayLeftOver) - log.Info("Time left for mining work", "left", (*delay - w.config.DelayLeftOver).String()) + log.Info("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 @@ -775,7 +775,7 @@ func (w *worker) commitTransactions(txs *types.TransactionsByPriceAndNonce, coin select { case <-stopTimer.C: log.Info("Not enough time for further transactions", "txs", len(w.current.txs)) - break + break LOOP default: } } @@ -952,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) }