diff options
author | Péter Szilágyi <peterke@gmail.com> | 2017-04-09 01:40:54 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-04-09 01:40:54 +0800 |
commit | badbaf66b6efe454ac02d0a6ce1ae964f7fa67c0 (patch) | |
tree | ffa8ffe28b6e7539cfd9baa6aa0b3c48522b91fc /eth | |
parent | cc13d576f07fb6803e09fb42880591a67b8b0ef6 (diff) | |
parent | b801be99d47ba09121a3e7d14aa028f828525b61 (diff) | |
download | dexon-badbaf66b6efe454ac02d0a6ce1ae964f7fa67c0.tar dexon-badbaf66b6efe454ac02d0a6ce1ae964f7fa67c0.tar.gz dexon-badbaf66b6efe454ac02d0a6ce1ae964f7fa67c0.tar.bz2 dexon-badbaf66b6efe454ac02d0a6ce1ae964f7fa67c0.tar.lz dexon-badbaf66b6efe454ac02d0a6ce1ae964f7fa67c0.tar.xz dexon-badbaf66b6efe454ac02d0a6ce1ae964f7fa67c0.tar.zst dexon-badbaf66b6efe454ac02d0a6ce1ae964f7fa67c0.zip |
Merge pull request #13880 from karalabe/remote-miner-fix
consensus/ethash, eth: don't mine if 0 threads are set
Diffstat (limited to 'eth')
-rw-r--r-- | eth/api.go | 27 | ||||
-rw-r--r-- | eth/backend.go | 4 |
2 files changed, 20 insertions, 11 deletions
diff --git a/eth/api.go b/eth/api.go index 041ccd397..947070515 100644 --- a/eth/api.go +++ b/eth/api.go @@ -139,16 +139,17 @@ func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI { // threads allowed to use. func (api *PrivateMinerAPI) Start(threads *int) error { // Set the number of threads if the seal engine supports it - if threads != nil { - type threaded interface { - SetThreads(threads int) - } - if th, ok := api.e.engine.(threaded); ok { - log.Info("Updated mining threads", "threads", *threads) - th.SetThreads(*threads) - } else { - log.Warn("Current seal engine isn't threaded") - } + if threads == nil { + threads = new(int) + } else if *threads == 0 { + *threads = -1 // Disable the miner from within + } + type threaded interface { + SetThreads(threads int) + } + if th, ok := api.e.engine.(threaded); ok { + log.Info("Updated mining threads", "threads", *threads) + th.SetThreads(*threads) } // Start the miner and return if !api.e.IsMining() { @@ -159,6 +160,12 @@ func (api *PrivateMinerAPI) Start(threads *int) error { // Stop the miner func (api *PrivateMinerAPI) Stop() bool { + type threaded interface { + SetThreads(threads int) + } + if th, ok := api.e.engine.(threaded); ok { + th.SetThreads(-1) + } api.e.StopMining() return true } diff --git a/eth/backend.go b/eth/backend.go index f241d5f34..df5460201 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -240,8 +240,10 @@ func CreateConsensusEngine(ctx *node.ServiceContext, config *Config, chainConfig log.Warn("Ethash used in shared mode") return ethash.NewShared() default: - return ethash.New(ctx.ResolvePath(config.EthashCacheDir), config.EthashCachesInMem, config.EthashCachesOnDisk, + engine := ethash.New(ctx.ResolvePath(config.EthashCacheDir), config.EthashCachesInMem, config.EthashCachesOnDisk, config.EthashDatasetDir, config.EthashDatasetsInMem, config.EthashDatasetsOnDisk) + engine.SetThreads(-1) // Disable CPU mining + return engine } } |