From 3fff291c992f48fa7caa063a0fdd48b9e271d910 Mon Sep 17 00:00:00 2001 From: gop Date: Fri, 27 Sep 2024 17:05:29 -0500 Subject: [PATCH] Removed the unnecessary start function from miner --- core/miner.go | 37 ------------------------------------- core/worker.go | 2 ++ 2 files changed, 2 insertions(+), 37 deletions(-) diff --git a/core/miner.go b/core/miner.go index 9b1538f26f..0e19b49b5a 100644 --- a/core/miner.go +++ b/core/miner.go @@ -20,7 +20,6 @@ package core import ( "fmt" "runtime" - "runtime/debug" "time" "github.com/dominant-strategies/go-quai/common" @@ -56,48 +55,12 @@ func New(hc *HeaderChain, txPool *TxPool, config *Config, db ethdb.Database, cha primaryCoinbase: config.PrimaryCoinbase, secondaryCoinbase: config.SecondaryCoinbase, } - go miner.update() - miner.Start(miner.primaryCoinbase, miner.secondaryCoinbase) miner.SetExtra(miner.MakeExtraData(config.ExtraData)) return miner } -// update keeps track of the downloader events. Please be aware that this is a one shot type of update loop. -// It's entered once and as soon as `Done` or `Failed` has been broadcasted the events are unregistered and -// the loop is exited. This to prevent a major security vuln where external parties can DOS you with blocks -// and halt your mining operation for as long as the DOS continues. -func (miner *Miner) update() { - defer func() { - if r := recover(); r != nil { - miner.logger.WithFields(log.Fields{ - "error": r, - "stacktrace": string(debug.Stack()), - }).Fatal("Go-Quai Panicked") - } - }() - canStart := true - for { - select { - case addr := <-miner.startCh: - miner.SetPrimaryCoinbase(addr[0]) - miner.SetSecondaryCoinbase(addr[1]) - if canStart { - miner.worker.start() - } - case <-miner.stopCh: - miner.worker.stop() - miner.worker.close() - return - } - } -} - -func (miner *Miner) Start(primaryCoinbase, secondaryCoinbase common.Address) { - miner.startCh <- []common.Address{primaryCoinbase, secondaryCoinbase} -} - func (miner *Miner) Stop() { miner.stopCh <- struct{}{} } diff --git a/core/worker.go b/core/worker.go index 5c0a977383..0165b5627f 100644 --- a/core/worker.go +++ b/core/worker.go @@ -300,6 +300,8 @@ func newWorker(config *Config, chainConfig *params.ChainConfig, db ethdb.Databas worker.ephemeralKey, _ = secp256k1.GeneratePrivateKey() + worker.start() + return worker }