aboutsummaryrefslogtreecommitdiffstats
path: root/eth/api.go
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2018-08-23 18:02:36 +0800
committerPéter Szilágyi <peterke@gmail.com>2018-08-23 19:09:45 +0800
commit92381ee00999398d0d0928d2c4be82b3334b912b (patch)
treea0bdcae53eace4fbf158c706b8c3cd33831edc8c /eth/api.go
parentf34f361ca6635690f6dd81d6f3bddfff498e9fd6 (diff)
downloaddexon-92381ee00999398d0d0928d2c4be82b3334b912b.tar
dexon-92381ee00999398d0d0928d2c4be82b3334b912b.tar.gz
dexon-92381ee00999398d0d0928d2c4be82b3334b912b.tar.bz2
dexon-92381ee00999398d0d0928d2c4be82b3334b912b.tar.lz
dexon-92381ee00999398d0d0928d2c4be82b3334b912b.tar.xz
dexon-92381ee00999398d0d0928d2c4be82b3334b912b.tar.zst
dexon-92381ee00999398d0d0928d2c4be82b3334b912b.zip
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.