From d7b5a87b3bc4a19677877d3a8c8c925211eb25f1 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Wed, 11 Mar 2015 23:35:34 +0100 Subject: miner: provide coinbase when starting the miner This avoids having to query the coinbase when creating the miner, which in turn eliminates the dreaded startup error when no accounts are set up. Later, this will also allow us to simply restart the miner when the user picks a different coinbase. This causes a lot of changes in other packages. These are included in this commit because they're impossible to separate. --- miner/miner.go | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index d3b1f578a..7bf67a6ec 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -17,44 +17,34 @@ type Miner struct { MinAcceptedGasPrice *big.Int Extra string - Coinbase []byte - mining bool - - pow pow.PoW + mining bool + eth core.Backend + pow pow.PoW } -func New(coinbase []byte, eth core.Backend, pow pow.PoW, minerThreads int) *Miner { - miner := &Miner{ - Coinbase: coinbase, - worker: newWorker(coinbase, eth), - pow: pow, - } - - minerThreads = 1 - for i := 0; i < minerThreads; i++ { - miner.worker.register(NewCpuMiner(i, miner.pow)) - } - - return miner +func New(eth core.Backend, pow pow.PoW, minerThreads int) *Miner { + // note: minerThreads is currently ignored because + // ethash is not thread safe. + return &Miner{eth: eth, pow: pow} } func (self *Miner) Mining() bool { return self.mining } -func (self *Miner) Start() { +func (self *Miner) Start(coinbase []byte) { self.mining = true + self.worker = newWorker(coinbase, self.eth) + self.worker.register(NewCpuMiner(0, self.pow)) self.pow.(*ethash.Ethash).UpdateDAG() self.worker.start() - self.worker.commitNewWork() } func (self *Miner) Stop() { self.mining = false - self.worker.stop() //self.pow.(*ethash.Ethash).Stop() -- cgit