mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
miner: fix regression, add test for starting while download (#21547)
Fixes a regression introduced in #21536
This commit is contained in:
parent
ca6b1bcea5
commit
0cc7aba2b7
@ -93,6 +93,7 @@ func (miner *Miner) update() {
|
||||
defer events.Unsubscribe()
|
||||
|
||||
shouldStart := false
|
||||
canStart := true
|
||||
for {
|
||||
select {
|
||||
case ev := <-events.Chan():
|
||||
@ -103,21 +104,27 @@ func (miner *Miner) update() {
|
||||
case downloader.StartEvent:
|
||||
wasMining := miner.Mining()
|
||||
miner.worker.stop()
|
||||
canStart = false
|
||||
if wasMining {
|
||||
// Resume mining after sync was finished
|
||||
shouldStart = true
|
||||
log.Info("Mining aborted due to sync")
|
||||
}
|
||||
case downloader.DoneEvent, downloader.FailedEvent:
|
||||
canStart = true
|
||||
if shouldStart {
|
||||
miner.SetEtherbase(miner.coinbase)
|
||||
miner.worker.start()
|
||||
}
|
||||
}
|
||||
case addr := <-miner.startCh:
|
||||
miner.SetEtherbase(addr)
|
||||
miner.worker.start()
|
||||
if canStart {
|
||||
miner.SetEtherbase(addr)
|
||||
miner.worker.start()
|
||||
}
|
||||
shouldStart = true
|
||||
case <-miner.stopCh:
|
||||
shouldStart = false
|
||||
miner.worker.stop()
|
||||
case <-miner.exitCh:
|
||||
miner.worker.close()
|
||||
|
@ -97,6 +97,19 @@ func TestMiner(t *testing.T) {
|
||||
waitForMiningState(t, miner, true)
|
||||
}
|
||||
|
||||
func TestStartWhileDownload(t *testing.T) {
|
||||
miner, mux := createMiner(t)
|
||||
waitForMiningState(t, miner, false)
|
||||
miner.Start(common.HexToAddress("0x12345"))
|
||||
waitForMiningState(t, miner, true)
|
||||
// Stop the downloader and wait for the update loop to run
|
||||
mux.Post(downloader.StartEvent{})
|
||||
waitForMiningState(t, miner, false)
|
||||
// Starting the miner after the downloader should not work
|
||||
miner.Start(common.HexToAddress("0x12345"))
|
||||
waitForMiningState(t, miner, false)
|
||||
}
|
||||
|
||||
func TestStartStopMiner(t *testing.T) {
|
||||
miner, _ := createMiner(t)
|
||||
waitForMiningState(t, miner, false)
|
||||
|
Loading…
Reference in New Issue
Block a user