mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
miner: commit new work when consensus engine is started
This commit is contained in:
parent
41a32a9475
commit
a218f37bec
3 changed files with 17 additions and 2 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -114,7 +114,6 @@ func (self *Miner) Start(coinbase common.Address) {
|
|||
}
|
||||
if !self.worker.isRunning() {
|
||||
self.worker.start()
|
||||
self.worker.commitNewWork()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue