StartMining¶
| Source (upstream pre-purge) | Current | |
|---|---|---|
| File | eth/backend.go |
backend_mining_pow.go |
| Symbol | Ethereum.StartMining |
Ethereum.StartMining |
| Ref | dde2da0ef~1 |
etc/v1.17.3-full-node |
Sets ethash threads, resolves etherbase, starts miner. Also includes StopMining, IsMining, Etherbase, SetEtherbase, and minerUpdate (downloader event coordination moved from miner to avoid import cycle).
3-way merge — purge → getc ← upstream¶
pre-purgecore-gethfork-only
// StartMining starts the PoW mining process with the given number of threads.
// If threads is 0, the engine decides the thread count internally.
↗func (s *Ethereum) StartMining(threads int) error {
// Update the thread count within the consensus engine
type threaded interface {
SetThreads(threads int)
}
if th, ok := s.engine.(threaded); ok {
log.Info("Updated mining threads", "threads", threads)
if threads == 0 {
threads = -1 // Disable the miner from within
}
th.SetThreads(threads)
}
// If the miner was not running, initialize it
if !s.IsMining() {
// Propagate the initial price point to the transaction pool
s.lock.RLock()
price := s.gasPrice
s.lock.RUnlock()
↗ s.txPool.SetGasTip(price)
↗ // Configure the local mining address
eb, err := s.Etherbase()
if err != nil {
log.Error("Cannot start mining without etherbase", "err", err)
return fmt.Errorf("etherbase missing: %v", err)
}
s.miner.SetEtherbase(eb)
s.miner.StartMining()
↗ }
return nil
}
core-geth validation — +4 -24
| | | |---|---| | File | [`backend.go`](https://github.com/etclabscore/core-geth/blob/v1.12.20/eth/backend.go) | | Symbol | `Ethereum.StartMining` | | Ref | `v1.12.20` |--- a/core-geth/eth/backend.go
+++ b/etc/eth/backend_mining_pow.go
@@ -1,6 +1,5 @@
-// StartMining starts the miner with the given number of CPU threads. If mining
-// is already running, this method adjust the number of threads allowed to use
-// and updates the minimum price required by the transaction pool.
+// StartMining starts the PoW mining process with the given number of threads.
+// If threads is 0, the engine decides the thread count internally.
func (s *Ethereum) StartMining(threads int) error {
// Update the thread count within the consensus engine
type threaded interface {
@@ -27,27 +26,8 @@
log.Error("Cannot start mining without etherbase", "err", err)
return fmt.Errorf("etherbase missing: %v", err)
}
- var cli *clique.Clique
- if c, ok := s.engine.(*clique.Clique); ok {
- cli = c
- } else if cl, ok := s.engine.(*beacon.Beacon); ok {
- if c, ok := cl.InnerEngine().(*clique.Clique); ok {
- cli = c
- }
- }
- if cli != nil {
- wallet, err := s.accountManager.Find(accounts.Account{Address: eb})
- if wallet == nil || err != nil {
- log.Error("Etherbase account unavailable locally", "err", err)
- return fmt.Errorf("signer missing: %v", err)
- }
- cli.Authorize(eb, wallet.SignData)
- }
- // If mining is started, we can disable the transaction rejection mechanism
- // introduced to speed sync times.
- s.handler.enableSyncedFeatures()
-
- go s.miner.Start()
+ s.miner.SetEtherbase(eb)
+ s.miner.StartMining()
}
return nil
}