mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 21:56:43 +00:00
Poll-based miner
This commit is contained in:
parent
b2d29f9e9a
commit
5b0255f05d
1 changed files with 56 additions and 36 deletions
|
|
@ -21,6 +21,7 @@ import (
|
|||
"fmt"
|
||||
"math/big"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/core"
|
||||
|
|
@ -103,7 +104,26 @@ func (m *Miner) SetGasPrice(price *big.Int) {
|
|||
|
||||
func (self *Miner) Start(coinbase common.Address, threads int) {
|
||||
self.sub = self.mux.Subscribe(core.TxPreEvent{}, core.NewBlockEvent{}, core.NewMinedBlockEvent{})
|
||||
go self.filterLoop(coinbase, threads)
|
||||
//go self.filterLoop(coinbase, threads)
|
||||
go self.runLoop(coinbase, threads)
|
||||
|
||||
}
|
||||
|
||||
func (self *Miner) runLoop(coinbase common.Address, threads int) {
|
||||
for true {
|
||||
if len(self.worker.txQueue) == 0 {
|
||||
if self.Mining() {
|
||||
glog.V(logger.Info).Infoln("Nothing to do. The miner sleeps.")
|
||||
self.Stop()
|
||||
}
|
||||
} else {
|
||||
if self.Mining() == false {
|
||||
glog.V(logger.Info).Infoln("A transaction awaits! Waking up miner.")
|
||||
self.Start(coinbase, threads)
|
||||
}
|
||||
time.Sleep(3000 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func (self *Miner) filterLoop(coinbase common.Address, threads int) {
|
||||
|
|
@ -149,8 +169,8 @@ func (self *Miner) actuallyStart(coinbase common.Address, threads int) {
|
|||
}
|
||||
|
||||
func (self *Miner) Stop() {
|
||||
if(self.sub != nil) {
|
||||
self.sub.Unsubscribe();
|
||||
if self.sub != nil {
|
||||
self.sub.Unsubscribe()
|
||||
}
|
||||
self.worker.stop()
|
||||
atomic.StoreInt32(&self.mining, 0)
|
||||
|
|
|
|||
Loading…
Reference in a new issue