From b801be99d47ba09121a3e7d14aa028f828525b61 Mon Sep 17 00:00:00 2001 From: Péter Szilágyi Date: Fri, 7 Apr 2017 17:22:06 +0300 Subject: consensus, eth: don't CPU mine by default during remote mining --- consensus/ethash/ethash.go | 9 ++++++++- consensus/ethash/sealer.go | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) (limited to 'consensus/ethash') diff --git a/consensus/ethash/ethash.go b/consensus/ethash/ethash.go index aa5b2d8a0..d284e7b00 100644 --- a/consensus/ethash/ethash.go +++ b/consensus/ethash/ethash.go @@ -555,11 +555,18 @@ func (ethash *Ethash) Threads() int { // SetThreads updates the number of mining threads currently enabled. Calling // this method does not start mining, only sets the thread count. If zero is -// specified, the miner will use all cores of the machine. +// specified, the miner will use all cores of the machine. Setting a thread +// count below zero is allowed and will cause the miner to idle, without any +// work being done. func (ethash *Ethash) SetThreads(threads int) { ethash.lock.Lock() defer ethash.lock.Unlock() + // If we're running a shared PoW, set the thread count on that instead + if ethash.shared != nil { + ethash.shared.SetThreads(threads) + return + } // Update the threads and ping any running seal to pull in any changes ethash.threads = threads select { diff --git a/consensus/ethash/sealer.go b/consensus/ethash/sealer.go index 9a000ed31..784e8f649 100644 --- a/consensus/ethash/sealer.go +++ b/consensus/ethash/sealer.go @@ -61,6 +61,9 @@ func (ethash *Ethash) Seal(chain consensus.ChainReader, block *types.Block, stop if threads == 0 { threads = runtime.NumCPU() } + if threads < 0 { + threads = 0 // Allows disabling local mining without extra logic around local/remote + } var pend sync.WaitGroup for i := 0; i < threads; i++ { pend.Add(1) -- cgit