aboutsummaryrefslogtreecommitdiffstats
path: root/eth/api.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-08-23 19:17:12 +0800
committerGitHub <noreply@github.com>2018-08-23 19:17:12 +0800
commit67d6d0bb7d0e9b18334d45e2d811f00746320d65 (patch)
tree53d2c1847ad134bc88c059b70e7691396e2c5536 /eth/api.go
parent1df1187d831a1c62f61e8c90901dc78b5f86943a (diff)
parent1e63a015a56ae45825c842b5a2b17d2cf2ac1ac6 (diff)
downloaddexon-67d6d0bb7d0e9b18334d45e2d811f00746320d65.tar
dexon-67d6d0bb7d0e9b18334d45e2d811f00746320d65.tar.gz
dexon-67d6d0bb7d0e9b18334d45e2d811f00746320d65.tar.bz2
dexon-67d6d0bb7d0e9b18334d45e2d811f00746320d65.tar.lz
dexon-67d6d0bb7d0e9b18334d45e2d811f00746320d65.tar.xz
dexon-67d6d0bb7d0e9b18334d45e2d811f00746320d65.tar.zst
dexon-67d6d0bb7d0e9b18334d45e2d811f00746320d65.zip
Merge pull request #17492 from karalabe/eth-miner-threads-defaults
cmd, eth: clean up miner startup API, drop noop config field
Diffstat (limited to 'eth/api.go')
-rw-r--r--eth/api.go47
1 files changed, 11 insertions, 36 deletions
diff --git a/eth/api.go b/eth/api.go
index 4b0ba8edb..708f75a78 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -24,6 +24,7 @@ import (
"io"
"math/big"
"os"
+ "runtime"
"strings"
"time"
@@ -34,7 +35,6 @@ import (
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/internal/ethapi"
- "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/rlp"
"github.com/ethereum/go-ethereum/rpc"
@@ -94,47 +94,22 @@ func NewPrivateMinerAPI(e *Ethereum) *PrivateMinerAPI {
return &PrivateMinerAPI{e: e}
}
-// Start the miner with the given number of threads. If threads is nil the number
-// of workers started is equal to the number of logical CPUs that are usable by
-// this process. 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.
+// Start starts the miner with the given number of threads. If threads is nil,
+// the number of workers started is equal to the number of logical CPUs that are
+// usable by this process. 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.
func (api *PrivateMinerAPI) Start(threads *int) error {
- // Set the number of threads if the seal engine supports it
if threads == nil {
- threads = new(int)
- } else if *threads == 0 {
- *threads = -1 // Disable the miner from within
+ return api.e.StartMining(runtime.NumCPU())
}
- 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() {
- // Propagate the initial price point to the transaction pool
- api.e.lock.RLock()
- price := api.e.gasPrice
- api.e.lock.RUnlock()
- api.e.txPool.SetGasPrice(price)
- return api.e.StartMining(true)
- }
- return nil
+ return api.e.StartMining(*threads)
}
-// 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)
- }
+// Stop terminates the miner, both at the consensus engine level as well as at
+// the block creation level.
+func (api *PrivateMinerAPI) Stop() {
api.e.StopMining()
- return true
}
// SetExtra sets the extra data string that is included when this miner mines a block.