File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ func (miner *Miner) update() {
8888 defer events .Unsubscribe ()
8989
9090 shouldStart := false
91+ canStart := true
9192 for {
9293 select {
9394 case ev := <- events .Chan ():
@@ -98,21 +99,27 @@ func (miner *Miner) update() {
9899 case downloader.StartEvent :
99100 wasMining := miner .Mining ()
100101 miner .worker .stop ()
102+ canStart = false
101103 if wasMining {
102104 // Resume mining after sync was finished
103105 shouldStart = true
104106 log .Info ("Mining aborted due to sync" )
105107 }
106108 case downloader.DoneEvent , downloader.FailedEvent :
109+ canStart = true
107110 if shouldStart {
108111 miner .SetEtherbase (miner .coinbase )
109112 miner .worker .start ()
110113 }
111114 }
112115 case addr := <- miner .startCh :
113- miner .SetEtherbase (addr )
114- miner .worker .start ()
116+ if canStart {
117+ miner .SetEtherbase (addr )
118+ miner .worker .start ()
119+ }
120+ shouldStart = true
115121 case <- miner .stopCh :
122+ shouldStart = false
116123 miner .worker .stop ()
117124 case <- miner .exitCh :
118125 miner .worker .close ()
Original file line number Diff line number Diff line change @@ -97,6 +97,19 @@ func TestMiner(t *testing.T) {
9797 waitForMiningState (t , miner , true )
9898}
9999
100+ func TestStartWhileDownload (t * testing.T ) {
101+ miner , mux := createMiner (t )
102+ waitForMiningState (t , miner , false )
103+ miner .Start (common .HexToAddress ("0x12345" ))
104+ waitForMiningState (t , miner , true )
105+ // Stop the downloader and wait for the update loop to run
106+ mux .Post (downloader.StartEvent {})
107+ waitForMiningState (t , miner , false )
108+ // Starting the miner after the downloader should not work
109+ miner .Start (common .HexToAddress ("0x12345" ))
110+ waitForMiningState (t , miner , false )
111+ }
112+
100113func TestStartStopMiner (t * testing.T ) {
101114 miner , _ := createMiner (t )
102115 waitForMiningState (t , miner , false )
You can’t perform that action at this time.
0 commit comments