From 21e52efdfed19c4376b830f8ad0e52a9e599f633 Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 11 May 2015 15:43:14 +0200 Subject: 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) --- miner/miner.go | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'miner/miner.go') 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() } -- cgit