miner: commit new work when consensus engine is started

This commit is contained in:
rjl493456442 2018-05-03 14:16:34 +08:00
parent 41a32a9475
commit a218f37bec
3 changed files with 17 additions and 2 deletions

View file

@ -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 {

View file

@ -114,7 +114,6 @@ func (self *Miner) Start(coinbase common.Address) {
}
if !self.worker.isRunning() {
self.worker.start()
self.worker.commitNewWork()
}
}

View file

@ -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