aboutsummaryrefslogtreecommitdiffstats
path: root/miner
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2015-03-12 06:35:34 +0800
committerFelix Lange <fjl@twurst.com>2015-03-12 06:43:27 +0800
commitd7b5a87b3bc4a19677877d3a8c8c925211eb25f1 (patch)
treef43c6b29c27dd29cc366788353650faa1d45e7bb /miner
parent5a9f712144058c576d14b0d27ff2d2d270cd6d27 (diff)
downloaddexon-d7b5a87b3bc4a19677877d3a8c8c925211eb25f1.tar
dexon-d7b5a87b3bc4a19677877d3a8c8c925211eb25f1.tar.gz
dexon-d7b5a87b3bc4a19677877d3a8c8c925211eb25f1.tar.bz2
dexon-d7b5a87b3bc4a19677877d3a8c8c925211eb25f1.tar.lz
dexon-d7b5a87b3bc4a19677877d3a8c8c925211eb25f1.tar.xz
dexon-d7b5a87b3bc4a19677877d3a8c8c925211eb25f1.tar.zst
dexon-d7b5a87b3bc4a19677877d3a8c8c925211eb25f1.zip
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.
Diffstat (limited to 'miner')
-rw-r--r--miner/miner.go30
1 files changed, 10 insertions, 20 deletions
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()