diff --git a/miner/agent.go b/miner/agent.go index 4f1ea3f65c..beaf30556a 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -18,10 +18,10 @@ package miner import ( "sync" + "sync/atomic" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/log" - "sync/atomic" ) type CpuAgent struct { diff --git a/miner/miner.go b/miner/miner.go index 0da233dd74..e7add025de 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -114,7 +114,6 @@ func (self *Miner) Start(coinbase common.Address) { } if !self.worker.isRunning() { self.worker.start() - self.worker.commitNewWork() } } diff --git a/miner/worker.go b/miner/worker.go index 1dcf2c9b1e..ba39cb83dd 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -251,6 +251,11 @@ func (self *worker) update() { defer self.chainHeadSub.Unsubscribe() defer self.chainSideSub.Unsubscribe() + ticker := time.NewTicker(500 * time.Millisecond) + defer ticker.Stop() + + var started bool // Indication whether consensus engine is started + for { // A real event arrived, process interesting content select { @@ -289,6 +294,17 @@ func (self *worker) update() { } } + // Commit new work when consensus engine is started. + case <-ticker.C: + if self.engine.IsRunning() { + if !started { + self.commitNewWork() + started = true + } + } else { + started = false + } + // System stopped case <-self.txsSub.Err(): return