mirror of https://github.com/status-im/op-geth.git
miner: removed default timer & update dag when threads > 0
This commit is contained in:
parent
ed07ffcde5
commit
2c1a6a349b
|
@ -16,9 +16,10 @@ type Miner struct {
|
||||||
|
|
||||||
MinAcceptedGasPrice *big.Int
|
MinAcceptedGasPrice *big.Int
|
||||||
|
|
||||||
mining bool
|
threads int
|
||||||
eth core.Backend
|
mining bool
|
||||||
pow pow.PoW
|
eth core.Backend
|
||||||
|
pow pow.PoW
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(eth core.Backend, pow pow.PoW, minerThreads int) *Miner {
|
func New(eth core.Backend, pow pow.PoW, minerThreads int) *Miner {
|
||||||
|
@ -28,6 +29,7 @@ func New(eth core.Backend, pow pow.PoW, minerThreads int) *Miner {
|
||||||
for i := 0; i < minerThreads; i++ {
|
for i := 0; i < minerThreads; i++ {
|
||||||
miner.worker.register(NewCpuMiner(i, pow))
|
miner.worker.register(NewCpuMiner(i, pow))
|
||||||
}
|
}
|
||||||
|
miner.threads = minerThreads
|
||||||
|
|
||||||
return miner
|
return miner
|
||||||
}
|
}
|
||||||
|
@ -40,7 +42,9 @@ func (self *Miner) Start(coinbase common.Address) {
|
||||||
self.mining = true
|
self.mining = true
|
||||||
self.worker.coinbase = coinbase
|
self.worker.coinbase = coinbase
|
||||||
|
|
||||||
self.pow.(*ethash.Ethash).UpdateDAG()
|
if self.threads > 0 {
|
||||||
|
self.pow.(*ethash.Ethash).UpdateDAG()
|
||||||
|
}
|
||||||
|
|
||||||
self.worker.start()
|
self.worker.start()
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,6 @@ import (
|
||||||
"sort"
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/ethereum/go-ethereum/core"
|
"github.com/ethereum/go-ethereum/core"
|
||||||
|
@ -151,8 +150,6 @@ func (self *worker) register(agent Agent) {
|
||||||
func (self *worker) update() {
|
func (self *worker) update() {
|
||||||
events := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
|
events := self.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
|
||||||
|
|
||||||
timer := time.NewTicker(2 * time.Second)
|
|
||||||
|
|
||||||
out:
|
out:
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
|
@ -171,15 +168,6 @@ out:
|
||||||
}
|
}
|
||||||
case <-self.quit:
|
case <-self.quit:
|
||||||
break out
|
break out
|
||||||
case <-timer.C:
|
|
||||||
if glog.V(logger.Detail) && atomic.LoadInt64(&self.mining) == 1 {
|
|
||||||
glog.Infoln("Hash rate:", self.HashRate(), "Khash")
|
|
||||||
}
|
|
||||||
|
|
||||||
// XXX In case all mined a possible uncle
|
|
||||||
if atomic.LoadInt64(&self.atWork) == 0 && atomic.LoadInt64(&self.mining) == 1 {
|
|
||||||
self.commitNewWork()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue