aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
Diffstat (limited to 'eth')
-rw-r--r--eth/api.go4
-rw-r--r--eth/backend.go11
-rw-r--r--eth/cpu_mining.go54
-rw-r--r--eth/gpu_mining.go102
4 files changed, 13 insertions, 158 deletions
diff --git a/eth/api.go b/eth/api.go
index c2fdbe99c..48f512b1b 100644
--- a/eth/api.go
+++ b/eth/api.go
@@ -102,7 +102,7 @@ func (s *PublicMinerAPI) SubmitWork(nonce rpc.HexNumber, solution, digest common
// result[2], 32 bytes hex encoded boundary condition ("target"), 2^256/difficulty
func (s *PublicMinerAPI) GetWork() (work [3]string, err error) {
if !s.e.IsMining() {
- if err := s.e.StartMining(0, ""); err != nil {
+ if err := s.e.StartMining(0); err != nil {
return work, err
}
}
@@ -141,7 +141,7 @@ func (s *PrivateMinerAPI) Start(threads *rpc.HexNumber) (bool, error) {
threads = rpc.NewHexNumber(runtime.NumCPU())
}
- err := s.e.StartMining(threads.Int(), "")
+ err := s.e.StartMining(threads.Int())
if err == nil {
return true, nil
}
diff --git a/eth/backend.go b/eth/backend.go
index c4a883c9e..24419d6d8 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -362,6 +362,17 @@ func (self *Ethereum) SetEtherbase(etherbase common.Address) {
self.miner.SetEtherbase(etherbase)
}
+func (s *Ethereum) StartMining(threads int) error {
+ eb, err := s.Etherbase()
+ if err != nil {
+ err = fmt.Errorf("Cannot start mining without etherbase address: %v", err)
+ glog.V(logger.Error).Infoln(err)
+ return err
+ }
+ go s.miner.Start(eb, threads)
+ return nil
+}
+
func (s *Ethereum) StopMining() { s.miner.Stop() }
func (s *Ethereum) IsMining() bool { return s.miner.Mining() }
func (s *Ethereum) Miner() *miner.Miner { return s.miner }
diff --git a/eth/cpu_mining.go b/eth/cpu_mining.go
deleted file mode 100644
index 3469d394e..000000000
--- a/eth/cpu_mining.go
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-// +build !opencl
-
-package eth
-
-import (
- "errors"
- "fmt"
-
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
-)
-
-const disabledInfo = "Set GO_OPENCL and re-build to enable."
-
-func (s *Ethereum) StartMining(threads int, gpus string) error {
- eb, err := s.Etherbase()
- if err != nil {
- err = fmt.Errorf("Cannot start mining without etherbase address: %v", err)
- glog.V(logger.Error).Infoln(err)
- return err
- }
-
- if gpus != "" {
- return errors.New("GPU mining disabled. " + disabledInfo)
- }
-
- // CPU mining
- go s.miner.Start(eb, threads)
- return nil
-}
-
-func GPUBench(gpuid uint64) {
- fmt.Println("GPU mining disabled. " + disabledInfo)
-}
-
-func PrintOpenCLDevices() {
- fmt.Println("OpenCL disabled. " + disabledInfo)
-}
diff --git a/eth/gpu_mining.go b/eth/gpu_mining.go
deleted file mode 100644
index 12fa74601..000000000
--- a/eth/gpu_mining.go
+++ /dev/null
@@ -1,102 +0,0 @@
-// Copyright 2015 The go-ethereum Authors
-// This file is part of the go-ethereum library.
-//
-// The go-ethereum library is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Lesser General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// The go-ethereum library is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Lesser General Public License for more details.
-//
-// You should have received a copy of the GNU Lesser General Public License
-// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
-
-// +build opencl
-
-package eth
-
-import (
- "fmt"
- "math/big"
- "strconv"
- "strings"
- "time"
-
- "github.com/ethereum/ethash"
- "github.com/ethereum/go-ethereum/common"
- "github.com/ethereum/go-ethereum/core/types"
- "github.com/ethereum/go-ethereum/logger"
- "github.com/ethereum/go-ethereum/logger/glog"
- "github.com/ethereum/go-ethereum/miner"
-)
-
-func (s *Ethereum) StartMining(threads int, gpus string) error {
- eb, err := s.Etherbase()
- if err != nil {
- err = fmt.Errorf("Cannot start mining without etherbase address: %v", err)
- glog.V(logger.Error).Infoln(err)
- return err
- }
-
- // GPU mining
- if gpus != "" {
- var ids []int
- for _, s := range strings.Split(gpus, ",") {
- i, err := strconv.Atoi(s)
- if err != nil {
- return fmt.Errorf("Invalid GPU id(s): %v", err)
- }
- if i < 0 {
- return fmt.Errorf("Invalid GPU id: %v", i)
- }
- ids = append(ids, i)
- }
-
- // TODO: re-creating miner is a bit ugly
- s.miner = miner.New(s, s.chainConfig, s.EventMux(), ethash.NewCL(ids))
- go s.miner.Start(eb, len(ids))
- return nil
- }
-
- // CPU mining
- go s.miner.Start(eb, threads)
- return nil
-}
-
-func GPUBench(gpuid uint64) {
- e := ethash.NewCL([]int{int(gpuid)})
-
- var h common.Hash
- bogoHeader := &types.Header{
- ParentHash: h,
- Number: big.NewInt(int64(42)),
- Difficulty: big.NewInt(int64(999999999999999)),
- }
- bogoBlock := types.NewBlock(bogoHeader, nil, nil, nil)
-
- err := ethash.InitCL(bogoBlock.NumberU64(), e)
- if err != nil {
- fmt.Println("OpenCL init error: ", err)
- return
- }
-
- stopChan := make(chan struct{})
- reportHashRate := func() {
- for {
- time.Sleep(3 * time.Second)
- fmt.Printf("hashes/s : %v\n", e.GetHashrate())
- }
- }
- fmt.Printf("Starting benchmark (%v seconds)\n", 60)
- go reportHashRate()
- go e.Search(bogoBlock, stopChan, 0)
- time.Sleep(60 * time.Second)
- fmt.Println("OK.")
-}
-
-func PrintOpenCLDevices() {
- ethash.PrintDevices()
-}