aboutsummaryrefslogtreecommitdiffstats
path: root/eth/api.go
diff options
context:
space:
mode:
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.