aboutsummaryrefslogtreecommitdiffstats
path: root/eth
diff options
context:
space:
mode:
Diffstat (limited to 'eth')
-rw-r--r--eth/backend.go15
-rw-r--r--eth/cpu_mining.go54
-rw-r--r--eth/gpu_mining.go103
-rw-r--r--eth/handler_test.go5
-rw-r--r--eth/helper_test.go3
5 files changed, 164 insertions, 16 deletions
diff --git a/eth/backend.go b/eth/backend.go
index f703b4ac0..9ec3c1440 100644
--- a/eth/backend.go
+++ b/eth/backend.go
@@ -393,7 +393,8 @@ func New(config *Config) (*Ethereum, error) {
return nil, err
}
- eth.txPool = core.NewTxPool(eth.EventMux(), eth.blockchain.State, eth.blockchain.GasLimit)
+ newPool := core.NewTxPool(eth.EventMux(), eth.blockchain.State, eth.blockchain.GasLimit)
+ eth.txPool = newPool
eth.blockProcessor = core.NewBlockProcessor(chainDb, eth.pow, eth.blockchain, eth.EventMux())
eth.blockchain.SetProcessor(eth.blockProcessor)
@@ -501,18 +502,6 @@ func (s *Ethereum) ResetWithGenesisBlock(gb *types.Block) {
s.blockchain.ResetWithGenesisBlock(gb)
}
-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) Etherbase() (eb common.Address, err error) {
eb = s.etherbase
if (eb == common.Address{}) {
diff --git a/eth/cpu_mining.go b/eth/cpu_mining.go
new file mode 100644
index 000000000..f8795fd0c
--- /dev/null
+++ b/eth/cpu_mining.go
@@ -0,0 +1,54 @@
+// Copyright 2014 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
new file mode 100644
index 000000000..c351c2bdd
--- /dev/null
+++ b/eth/gpu_mining.go
@@ -0,0 +1,103 @@
+// Copyright 2014 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
+ cl := ethash.NewCL(ids)
+ s.miner = miner.New(s, s.EventMux(), cl)
+ 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()
+}
diff --git a/eth/handler_test.go b/eth/handler_test.go
index 2b8c6168a..dde2ecbd5 100644
--- a/eth/handler_test.go
+++ b/eth/handler_test.go
@@ -443,10 +443,11 @@ func testGetNodeData(t *testing.T, protocol int) {
}
accounts := []common.Address{testBankAddress, acc1Addr, acc2Addr}
for i := uint64(0); i <= pm.blockchain.CurrentBlock().NumberU64(); i++ {
- trie := state.New(pm.blockchain.GetBlockByNumber(i).Root(), statedb)
+ trie, _ := state.New(pm.blockchain.GetBlockByNumber(i).Root(), statedb)
for j, acc := range accounts {
- bw := pm.blockchain.State().GetBalance(acc)
+ state, _ := pm.blockchain.State()
+ bw := state.GetBalance(acc)
bh := trie.GetBalance(acc)
if (bw != nil && bh == nil) || (bw == nil && bh != nil) {
diff --git a/eth/helper_test.go b/eth/helper_test.go
index e42fa1f82..9314884ef 100644
--- a/eth/helper_test.go
+++ b/eth/helper_test.go
@@ -38,7 +38,8 @@ func newTestProtocolManager(blocks int, generator func(int, *core.BlockGen), new
blockproc = core.NewBlockProcessor(db, pow, blockchain, evmux)
)
blockchain.SetProcessor(blockproc)
- if _, err := blockchain.InsertChain(core.GenerateChain(genesis, db, blocks, generator)); err != nil {
+ chain := core.GenerateChain(genesis, db, blocks, generator)
+ if _, err := blockchain.InsertChain(chain); err != nil {
panic(err)
}
pm := NewProtocolManager(NetworkId, evmux, &testTxPool{added: newtx}, pow, blockchain, db)