diff options
author | Felix Lange <fjl@twurst.com> | 2015-03-12 06:35:34 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2015-03-12 06:43:27 +0800 |
commit | d7b5a87b3bc4a19677877d3a8c8c925211eb25f1 (patch) | |
tree | f43c6b29c27dd29cc366788353650faa1d45e7bb /eth/backend.go | |
parent | 5a9f712144058c576d14b0d27ff2d2d270cd6d27 (diff) | |
download | dexon-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 'eth/backend.go')
-rw-r--r-- | eth/backend.go | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/eth/backend.go b/eth/backend.go index 9e365161d..9c497a586 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -166,18 +166,13 @@ func New(config *Config) (*Ethereum, error) { DataDir: config.DataDir, } - cb, err := eth.accountManager.Coinbase() - if err != nil { - return nil, err - } - eth.chainManager = core.NewChainManager(blockDb, stateDb, eth.EventMux()) pow := ethash.New(eth.chainManager) eth.txPool = core.NewTxPool(eth.EventMux()) eth.blockProcessor = core.NewBlockProcessor(stateDb, pow, eth.txPool, eth.chainManager, eth.EventMux()) eth.chainManager.SetProcessor(eth.blockProcessor) eth.whisper = whisper.New() - eth.miner = miner.New(cb, eth, pow, config.MinerThreads) + eth.miner = miner.New(eth, pow, config.MinerThreads) hasBlock := eth.chainManager.HasBlock insertChain := eth.chainManager.InsertChain @@ -211,6 +206,19 @@ func New(config *Config) (*Ethereum, error) { return eth, nil } +func (s *Ethereum) StartMining() error { + cb, err := s.accountManager.Coinbase() + if err != nil { + servlogger.Errorf("Cannot start mining without coinbase: %v\n", err) + return fmt.Errorf("no coinbase: %v", err) + } + s.miner.Start(cb) + return nil +} + +func (s *Ethereum) StopMining() { s.miner.Stop() } +func (s *Ethereum) IsMining() bool { return s.miner.Mining() } + func (s *Ethereum) Logger() logger.LogSystem { return s.logger } func (s *Ethereum) Name() string { return s.net.Name } func (s *Ethereum) AccountManager() *accounts.Manager { return s.accountManager } @@ -222,7 +230,6 @@ func (s *Ethereum) Whisper() *whisper.Whisper { return s.whisper } func (s *Ethereum) EventMux() *event.TypeMux { return s.eventMux } func (s *Ethereum) BlockDb() ethutil.Database { return s.blockDb } func (s *Ethereum) StateDb() ethutil.Database { return s.stateDb } -func (s *Ethereum) Miner() *miner.Miner { return s.miner } func (s *Ethereum) IsListening() bool { return true } // Always listening func (s *Ethereum) PeerCount() int { return s.net.PeerCount() } func (s *Ethereum) Peers() []*p2p.Peer { return s.net.Peers() } @@ -261,7 +268,7 @@ func (s *Ethereum) Start() error { } func (s *Ethereum) StartForTest() { - jsonlogger.LogJson(&logger.LogStarting{ + jsonlogger.LogJson(&logger.LogStarting{ ClientString: s.net.Name, ProtocolVersion: ProtocolVersion, }) |