aboutsummaryrefslogtreecommitdiffstats
path: root/miner/miner.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-11 21:43:14 +0800
committerobscuren <geffobscura@gmail.com>2015-05-11 23:21:22 +0800
commit21e52efdfed19c4376b830f8ad0e52a9e599f633 (patch)
treea3d6f2be23c64881461892572adc9d1b55cd4b39 /miner/miner.go
parent064cf1609987bb0f6c59c1e790b7811d9a783fef (diff)
downloadgo-tangerine-21e52efdfed19c4376b830f8ad0e52a9e599f633.tar
go-tangerine-21e52efdfed19c4376b830f8ad0e52a9e599f633.tar.gz
go-tangerine-21e52efdfed19c4376b830f8ad0e52a9e599f633.tar.bz2
go-tangerine-21e52efdfed19c4376b830f8ad0e52a9e599f633.tar.lz
go-tangerine-21e52efdfed19c4376b830f8ad0e52a9e599f633.tar.xz
go-tangerine-21e52efdfed19c4376b830f8ad0e52a9e599f633.tar.zst
go-tangerine-21e52efdfed19c4376b830f8ad0e52a9e599f633.zip
cmd/geth, miner, backend, xeth: Fixed miner threads to be settable
Miner threads are now settable through the admin interface (closes #897) and specify 0 CPU worker threads when eth_getWork is called (closes #916)
Diffstat (limited to 'miner/miner.go')
-rw-r--r--miner/miner.go33
1 files changed, 16 insertions, 17 deletions
diff --git a/miner/miner.go b/miner/miner.go
index efe6d3051..09342e250 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -23,16 +23,8 @@ type Miner struct {
pow pow.PoW
}
-func New(eth core.Backend, pow pow.PoW, minerThreads int) *Miner {
- // note: minerThreads is currently ignored because
- // ethash is not thread safe.
- miner := &Miner{eth: eth, pow: pow, worker: newWorker(common.Address{}, eth)}
- for i := 0; i < minerThreads; i++ {
- miner.worker.register(NewCpuMiner(i, pow))
- }
- miner.threads = minerThreads
-
- return miner
+func New(eth core.Backend, pow pow.PoW) *Miner {
+ return &Miner{eth: eth, pow: pow, worker: newWorker(common.Address{}, eth)}
}
func (self *Miner) Mining() bool {
@@ -48,15 +40,27 @@ func (m *Miner) SetGasPrice(price *big.Int) {
m.worker.gasPrice = price
}
-func (self *Miner) Start(coinbase common.Address) {
- glog.V(logger.Info).Infoln("Starting mining operation")
+func (self *Miner) Start(coinbase common.Address, threads int) {
self.mining = true
+
+ for i := 0; i < threads; i++ {
+ self.worker.register(NewCpuAgent(i, self.pow))
+ }
+ self.threads = threads
+
+ glog.V(logger.Info).Infof("Starting mining operation (CPU=%d TOT=%d)\n", threads, len(self.worker.agents))
+
self.worker.coinbase = coinbase
self.worker.start()
self.worker.commitNewWork()
}
+func (self *Miner) Stop() {
+ self.worker.stop()
+ self.mining = false
+}
+
func (self *Miner) Register(agent Agent) {
if self.mining {
agent.Start()
@@ -65,11 +69,6 @@ func (self *Miner) Register(agent Agent) {
self.worker.register(agent)
}
-func (self *Miner) Stop() {
- self.mining = false
- self.worker.stop()
-}
-
func (self *Miner) HashRate() int64 {
return self.worker.HashRate()
}