Skip to content

Commit

Permalink
update to 200 ms
Browse files Browse the repository at this point in the history
  • Loading branch information
unclezoro committed Mar 16, 2021
1 parent 246c242 commit 1b34032
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 30 deletions.
2 changes: 1 addition & 1 deletion eth/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ var DefaultConfig = Config{
GasCeil: 8000000,
GasPrice: big.NewInt(params.GWei),
Recommit: 3 * time.Second,
DelayLeftOver: 100 * time.Millisecond,
DelayLeftOver: 200 * time.Millisecond,
},
TxPool: core.DefaultTxPoolConfig,
GPO: gasprice.Config{
Expand Down
55 changes: 26 additions & 29 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -354,15 +354,15 @@ 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() {
continue
}
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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
}
}
Expand Down Expand Up @@ -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)
}

Expand Down

0 comments on commit 1b34032

Please sign in to comment.