From 118862f1ba058fa90414ab9ec6deb1ab5aac6590 Mon Sep 17 00:00:00 2001 From: zelig Date: Sun, 14 Dec 2014 18:10:48 +0000 Subject: adapt miner to new backend. use events to broadcast new mined blocks --- miner/miner.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index dc69dddc0..6ba3b1eba 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -27,7 +27,7 @@ import ( "math/big" "sort" - "github.com/ethereum/go-ethereum" + "github.com/ethereum/go-ethereum/eth" "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/pow/ezp" @@ -36,7 +36,6 @@ import ( "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/wire" ) type LocalTx struct { @@ -217,7 +216,7 @@ func (self *Miner) mine() { if err != nil { minerlogger.Infoln(err) } else { - self.eth.Broadcast(wire.MsgBlockTy, []interface{}{block.Value().Val}) + self.eth.EventMux().Post(core.NewMinedBlockEvent{block}) minerlogger.Infof("🔨 Mined block %x\n", block.Hash()) minerlogger.Infoln(block) @@ -246,7 +245,7 @@ func (self *Miner) finiliseTxs() types.Transactions { } // Faster than append - for _, tx := range self.eth.TxPool().CurrentTransactions() { + for _, tx := range self.eth.TxPool().GetTransactions() { if tx.GasPrice.Cmp(self.MinAcceptedGasPrice) >= 0 { txs[actualSize] = tx actualSize++ -- cgit v1.2.3 From 4cd79d8ddd7608d60344b13fe4bda7315429d1d9 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 23 Dec 2014 13:48:44 +0100 Subject: Refactored block & Transaction * Includes new rlp decoder --- miner/miner.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index d909c228b..c9a6922bb 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -56,7 +56,7 @@ type Miner struct { eth *eth.Ethereum events event.Subscription - uncles types.Blocks + uncles []*types.Header localTxs map[int]*LocalTx localTxId int @@ -184,9 +184,9 @@ func (self *Miner) mine() { block.SetUncles(self.uncles) } - parent := chainMan.GetBlock(block.PrevHash) - coinbase := block.State().GetOrNewStateObject(block.Coinbase) - coinbase.SetGasPool(block.CalcGasLimit(parent)) + parent := chainMan.GetBlock(block.ParentHash()) + coinbase := block.State().GetOrNewStateObject(block.Coinbase()) + coinbase.SetGasPool(core.CalcGasLimit(parent, block)) transactions := self.finiliseTxs() @@ -211,7 +211,7 @@ func (self *Miner) mine() { // Find a valid nonce nonce := self.pow.Search(block, self.powQuitCh) if nonce != nil { - block.Nonce = nonce + block.Header().Nonce = nonce err := chainMan.InsertChain(types.Blocks{block}) if err != nil { minerlogger.Infoln(err) -- cgit v1.2.3 From ce68ac695981523aca5cf83e051597f46070547d Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 30 Dec 2014 13:18:19 +0100 Subject: Updated miner to new block api --- miner/miner.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index c9a6922bb..aefcadab8 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -190,9 +190,11 @@ func (self *Miner) mine() { transactions := self.finiliseTxs() + state := block.State() + // Accumulate all valid transactions and apply them to the new state // Error may be ignored. It's not important during mining - receipts, txs, _, erroneous, err := blockManager.ApplyTransactions(coinbase, block.State(), block, transactions, true) + receipts, txs, _, erroneous, err := blockManager.ApplyTransactions(coinbase, state, block, transactions, true) if err != nil { minerlogger.Debugln(err) } @@ -202,9 +204,10 @@ func (self *Miner) mine() { block.SetReceipts(receipts) // Accumulate the rewards included for this block - blockManager.AccumelateRewards(block.State(), block, parent) + blockManager.AccumelateRewards(state, block, parent) - block.State().Update(ethutil.Big0) + state.Update(ethutil.Big0) + block.SetRoot(state.Root()) minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions)) -- cgit v1.2.3 From c1dee151445d1d9700e0c623916299370868490c Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 5 Jan 2015 00:18:44 +0100 Subject: BlockManager => BlockProcessor --- miner/miner.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index aefcadab8..949227d98 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -174,9 +174,9 @@ func (self *Miner) reset() { func (self *Miner) mine() { var ( - blockManager = self.eth.BlockManager() - chainMan = self.eth.ChainManager() - block = chainMan.NewBlock(self.Coinbase) + blockProcessor = self.eth.BlockProcessor() + chainMan = self.eth.ChainManager() + block = chainMan.NewBlock(self.Coinbase) ) // Apply uncles @@ -194,7 +194,7 @@ func (self *Miner) mine() { // Accumulate all valid transactions and apply them to the new state // Error may be ignored. It's not important during mining - receipts, txs, _, erroneous, err := blockManager.ApplyTransactions(coinbase, state, block, transactions, true) + receipts, txs, _, erroneous, err := blockProcessor.ApplyTransactions(coinbase, state, block, transactions, true) if err != nil { minerlogger.Debugln(err) } @@ -204,7 +204,7 @@ func (self *Miner) mine() { block.SetReceipts(receipts) // Accumulate the rewards included for this block - blockManager.AccumelateRewards(state, block, parent) + blockProcessor.AccumelateRewards(state, block, parent) state.Update(ethutil.Big0) block.SetRoot(state.Root()) -- cgit v1.2.3 From 47e6b2cef8ee0164e82d119c6a9359b55259d645 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 6 Jan 2015 00:19:07 +0100 Subject: Allow extra to be set for mined blocks --- miner/miner.go | 2 ++ 1 file changed, 2 insertions(+) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index 949227d98..f80ae51c6 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -69,6 +69,7 @@ type Miner struct { mining bool MinAcceptedGasPrice *big.Int + Extra string } func New(coinbase []byte, eth *eth.Ethereum) *Miner { @@ -178,6 +179,7 @@ func (self *Miner) mine() { chainMan = self.eth.ChainManager() block = chainMan.NewBlock(self.Coinbase) ) + block.Header().Extra = self.Extra // Apply uncles if len(self.uncles) > 0 { -- cgit v1.2.3 From fed3e6a808921fb8274b50043c5c39a24a1bbccf Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 7 Jan 2015 13:17:48 +0100 Subject: Refactored ethutil.Config.Db out --- miner/miner.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index f80ae51c6..52dd5687d 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -31,6 +31,7 @@ import ( "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/pow" "github.com/ethereum/go-ethereum/pow/ezp" + "github.com/ethereum/go-ethereum/state" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" @@ -178,6 +179,7 @@ func (self *Miner) mine() { blockProcessor = self.eth.BlockProcessor() chainMan = self.eth.ChainManager() block = chainMan.NewBlock(self.Coinbase) + state = state.New(block.Root(), self.eth.Db()) ) block.Header().Extra = self.Extra @@ -187,13 +189,11 @@ func (self *Miner) mine() { } parent := chainMan.GetBlock(block.ParentHash()) - coinbase := block.State().GetOrNewStateObject(block.Coinbase()) + coinbase := state.GetOrNewStateObject(block.Coinbase()) coinbase.SetGasPool(core.CalcGasLimit(parent, block)) transactions := self.finiliseTxs() - state := block.State() - // Accumulate all valid transactions and apply them to the new state // Error may be ignored. It's not important during mining receipts, txs, _, erroneous, err := blockProcessor.ApplyTransactions(coinbase, state, block, transactions, true) -- cgit v1.2.3 From 697c2b5dc16653228c5264d01c08163cebda3aeb Mon Sep 17 00:00:00 2001 From: Gustav Simonsson Date: Tue, 3 Feb 2015 23:09:39 +0100 Subject: Correct block parent timestamp check and typos --- miner/miner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index 52dd5687d..7ebf00d6a 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -206,7 +206,7 @@ func (self *Miner) mine() { block.SetReceipts(receipts) // Accumulate the rewards included for this block - blockProcessor.AccumelateRewards(state, block, parent) + blockProcessor.AccumulateRewards(state, block, parent) state.Update(ethutil.Big0) block.SetRoot(state.Root()) -- cgit v1.2.3 From a1b4547a53c4c738e435c1968c1e606935912e47 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 4 Feb 2015 18:26:23 -0800 Subject: set uncles regardless of empty uncle list. Fixes invalid blocks being mined --- miner/miner.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index 52dd5687d..11d09d953 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -184,9 +184,7 @@ func (self *Miner) mine() { block.Header().Extra = self.Extra // Apply uncles - if len(self.uncles) > 0 { - block.SetUncles(self.uncles) - } + block.SetUncles(self.uncles) parent := chainMan.GetBlock(block.ParentHash()) coinbase := state.GetOrNewStateObject(block.Coinbase()) -- cgit v1.2.3 From 9d2166a964d83c09481dea6ef30889f260249295 Mon Sep 17 00:00:00 2001 From: obscuren Date: Thu, 5 Feb 2015 08:29:41 -0800 Subject: wip --- miner/miner.go | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index 52dd5687d..8044ef073 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -24,21 +24,43 @@ package miner import ( + "fmt" "math/big" "sort" - "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/pow" - "github.com/ethereum/go-ethereum/pow/ezp" - "github.com/ethereum/go-ethereum/state" - + "github.com/ethereum/c-ethash/go-ethash" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" + "github.com/ethereum/go-ethereum/crypto" + "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/ethutil" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" + "github.com/ethereum/go-ethereum/pow" + "github.com/ethereum/go-ethereum/state" ) +var dx = []byte{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42} +var dy = []byte{0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43} + +const epochLen = uint64(1000) + +func getSeed(chainMan *core.ChainManager, block *types.Block) (x []byte, y []byte) { + if block.Number().Uint64() == 0 { + return dx, dy + } else if block.Number().Uint64()%epochLen == 0 { + x, y = getSeed(chainMan, chainMan.GetBlock(block.ParentHash())) + if (block.Number().Uint64()/epochLen)%2 > 0 { + y = crypto.Sha3(append(y, block.ParentHash()...)) + } else { + x = crypto.Sha3(append(x, block.ParentHash()...)) + } + return x, y + } else { + return getSeed(chainMan, chainMan.GetBlock(block.ParentHash())) + } +} + type LocalTx struct { To []byte `json:"to"` Data []byte `json:"data"` @@ -77,7 +99,6 @@ func New(coinbase []byte, eth *eth.Ethereum) *Miner { return &Miner{ eth: eth, powQuitCh: make(chan struct{}), - pow: ezp.New(), mining: false, localTxs: make(map[int]*LocalTx), MinAcceptedGasPrice: big.NewInt(10000000000000), @@ -213,6 +234,13 @@ func (self *Miner) mine() { minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions)) + x, y := getSeed(chainMan, block) + self.pow, err = ethash.New(append(x, y...), block) + if err != nil { + fmt.Println("err", err) + return + } + // Find a valid nonce nonce := self.pow.Search(block, self.powQuitCh) if nonce != nil { -- cgit v1.2.3 From da2fae0e437f9467a943acfe0571a8a24e8e76fd Mon Sep 17 00:00:00 2001 From: obscuren Date: Mon, 9 Feb 2015 16:20:34 +0100 Subject: Basic structure miner --- miner/miner.go | 284 ++++++--------------------------------------------------- 1 file changed, 30 insertions(+), 254 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index 1f4fc2170..f184042dc 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -1,291 +1,67 @@ -/* - This file is part of go-ethereum - - go-ethereum 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. - - go-ethereum 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 General Public License for more details. - - You should have received a copy of the GNU Lesser General Public License - along with go-ethereum. If not, see . -*/ -/** - * @authors - * Jeffrey Wilcke - * @date 2014 - * - */ - package miner import ( - "fmt" "math/big" - "sort" - "github.com/ethereum/c-ethash/go-ethash" - "github.com/ethereum/go-ethereum/core" - "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/eth" - "github.com/ethereum/go-ethereum/ethutil" - "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" - "github.com/ethereum/go-ethereum/pow" - "github.com/ethereum/go-ethereum/state" + "github.com/ethereum/go-ethereum/pow/ezp" ) -var dx = []byte{0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42} -var dy = []byte{0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43, 0x43} - -const epochLen = uint64(1000) - -func getSeed(chainMan *core.ChainManager, block *types.Block) (x []byte, y []byte) { - if block.Number().Uint64() == 0 { - return dx, dy - } else if block.Number().Uint64()%epochLen == 0 { - x, y = getSeed(chainMan, chainMan.GetBlock(block.ParentHash())) - if (block.Number().Uint64()/epochLen)%2 > 0 { - y = crypto.Sha3(append(y, block.ParentHash()...)) - } else { - x = crypto.Sha3(append(x, block.ParentHash()...)) - } - return x, y - } else { - return getSeed(chainMan, chainMan.GetBlock(block.ParentHash())) - } -} - -type LocalTx struct { - To []byte `json:"to"` - Data []byte `json:"data"` - Gas string `json:"gas"` - GasPrice string `json:"gasPrice"` - Value string `json:"value"` -} - -func (self *LocalTx) Sign(key []byte) *types.Transaction { - return nil -} - var minerlogger = logger.NewLogger("MINER") type Miner struct { - eth *eth.Ethereum - events event.Subscription - - uncles []*types.Header - localTxs map[int]*LocalTx - localTxId int - - pow pow.PoW - quitCh chan struct{} - powQuitCh chan struct{} - - Coinbase []byte - - mining bool + worker *worker MinAcceptedGasPrice *big.Int Extra string -} - -func New(coinbase []byte, eth *eth.Ethereum) *Miner { - return &Miner{ - eth: eth, - powQuitCh: make(chan struct{}), - mining: false, - localTxs: make(map[int]*LocalTx), - MinAcceptedGasPrice: big.NewInt(10000000000000), - Coinbase: coinbase, - } -} - -func (self *Miner) GetPow() pow.PoW { - return self.pow -} - -func (self *Miner) AddLocalTx(tx *LocalTx) int { - minerlogger.Infof("Added local tx (%x %v / %v)\n", tx.To[0:4], tx.GasPrice, tx.Value) - - self.localTxId++ - self.localTxs[self.localTxId] = tx - self.eth.EventMux().Post(tx) - return self.localTxId + coinbase []byte + mining bool } -func (self *Miner) RemoveLocalTx(id int) { - if tx := self.localTxs[id]; tx != nil { - minerlogger.Infof("Removed local tx (%x %v / %v)\n", tx.To[0:4], tx.GasPrice, tx.Value) +func New(coinbase []byte, eth *eth.Ethereum) *Miner { + miner := &Miner{ + coinbase: coinbase, + worker: newWorker(coinbase, eth), } - self.eth.EventMux().Post(&LocalTx{}) - - delete(self.localTxs, id) -} -func (self *Miner) Start() { - if self.mining { - return + for i := 0; i < 4; i++ { + miner.worker.register(NewCpuMiner(i, ezp.New())) } - minerlogger.Infoln("Starting mining operations") - self.mining = true - self.quitCh = make(chan struct{}) - self.powQuitCh = make(chan struct{}) - - mux := self.eth.EventMux() - self.events = mux.Subscribe(core.NewBlockEvent{}, core.TxPreEvent{}, &LocalTx{}) - - go self.update() - go self.mine() -} - -func (self *Miner) Stop() { - if !self.mining { - return - } - - self.mining = false - - minerlogger.Infoln("Stopping mining operations") - - self.events.Unsubscribe() - - close(self.quitCh) - close(self.powQuitCh) + return miner } func (self *Miner) Mining() bool { return self.mining } -func (self *Miner) update() { -out: - for { - select { - case event := <-self.events.Chan(): - switch event := event.(type) { - case core.NewBlockEvent: - block := event.Block - if self.eth.ChainManager().HasBlock(block.Hash()) { - self.reset() - self.eth.TxPool().RemoveSet(block.Transactions()) - go self.mine() - } else if true { - // do uncle stuff - } - case core.TxPreEvent, *LocalTx: - self.reset() - go self.mine() - } - case <-self.quitCh: - break out - } - } -} - -func (self *Miner) reset() { - close(self.powQuitCh) - self.powQuitCh = make(chan struct{}) -} - -func (self *Miner) mine() { - var ( - blockProcessor = self.eth.BlockProcessor() - chainMan = self.eth.ChainManager() - block = chainMan.NewBlock(self.Coinbase) - state = state.New(block.Root(), self.eth.Db()) - ) - block.Header().Extra = self.Extra - - // Apply uncles - block.SetUncles(self.uncles) - - parent := chainMan.GetBlock(block.ParentHash()) - coinbase := state.GetOrNewStateObject(block.Coinbase()) - coinbase.SetGasPool(core.CalcGasLimit(parent, block)) - - transactions := self.finiliseTxs() - - // Accumulate all valid transactions and apply them to the new state - // Error may be ignored. It's not important during mining - receipts, txs, _, erroneous, err := blockProcessor.ApplyTransactions(coinbase, state, block, transactions, true) - if err != nil { - minerlogger.Debugln(err) - } - self.eth.TxPool().RemoveSet(erroneous) - - block.SetTransactions(txs) - block.SetReceipts(receipts) - - // Accumulate the rewards included for this block - blockProcessor.AccumulateRewards(state, block, parent) - - state.Update(ethutil.Big0) - block.SetRoot(state.Root()) - - minerlogger.Infof("Mining on block. Includes %v transactions", len(transactions)) - - x, _ := getSeed(chainMan, block) - self.pow, err = ethash.New(x, block) - if err != nil { - fmt.Println("miner gave back err", err) - return - } +func (self *Miner) Start() { + self.worker.start() - // Find a valid nonce - nonce := self.pow.Search(block, self.powQuitCh) - if nonce != nil { - block.Header().Nonce = nonce - err := chainMan.InsertChain(types.Blocks{block}) - if err != nil { - minerlogger.Infoln(err) - } else { - self.eth.EventMux().Post(core.NewMinedBlockEvent{block}) + self.worker.commitNewWork() - minerlogger.Infof("🔨 Mined block %x\n", block.Hash()) - minerlogger.Infoln(block) + /* + timer := time.NewTicker(time.Second) + for { + select { + case <-timer.C: + fmt.Printf("%d workers. %d/Khash\n", len(self.worker.agents), self.HashRate()) + } } - - go self.mine() - } + */ } -func (self *Miner) finiliseTxs() types.Transactions { - // Sort the transactions by nonce in case of odd network propagation - actualSize := len(self.localTxs) // See copy below - txs := make(types.Transactions, actualSize+self.eth.TxPool().Size()) - - state := self.eth.ChainManager().TransState() - // XXX This has to change. Coinbase is, for new, same as key. - key := self.eth.KeyManager() - for i, ltx := range self.localTxs { - tx := types.NewTransactionMessage(ltx.To, ethutil.Big(ltx.Value), ethutil.Big(ltx.Gas), ethutil.Big(ltx.GasPrice), ltx.Data) - tx.SetNonce(state.GetNonce(self.Coinbase)) - state.SetNonce(self.Coinbase, tx.Nonce()+1) - - tx.Sign(key.PrivateKey()) - - txs[i] = tx - } +func (self *Miner) Stop() { + self.worker.stop() +} - // Faster than append - for _, tx := range self.eth.TxPool().GetTransactions() { - if tx.GasPrice().Cmp(self.MinAcceptedGasPrice) >= 0 { - txs[actualSize] = tx - actualSize++ - } +func (self *Miner) HashRate() int64 { + var tot int64 + for _, agent := range self.worker.agents { + tot += agent.Pow().GetHashrate() } - newTransactions := make(types.Transactions, actualSize) - copy(newTransactions, txs[:actualSize]) - sort.Sort(types.TxByNonce{newTransactions}) - - return newTransactions + return tot } -- cgit v1.2.3 From 8a0f23915e4feb9aabe21bd075416bc0f32bbc43 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 13 Feb 2015 17:23:09 +0100 Subject: Fixed a few issues in the miner and updated hash rate title * Sometimes old nonces were set by "old" agents * Added the hash rate to the miner --- miner/miner.go | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index f184042dc..e3e7bead2 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -38,22 +38,16 @@ func (self *Miner) Mining() bool { } func (self *Miner) Start() { + self.mining = true + self.worker.start() self.worker.commitNewWork() - - /* - timer := time.NewTicker(time.Second) - for { - select { - case <-timer.C: - fmt.Printf("%d workers. %d/Khash\n", len(self.worker.agents), self.HashRate()) - } - } - */ } func (self *Miner) Stop() { + self.mining = false + self.worker.stop() } -- cgit v1.2.3 From 8135752a32837748e6d4a986912131736b1a0aa0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 17 Feb 2015 12:24:51 +0100 Subject: "centralised" mining to backend. Closes #323 --- miner/miner.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index e3e7bead2..27afcf684 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -3,7 +3,7 @@ package miner import ( "math/big" - "github.com/ethereum/go-ethereum/eth" + "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/pow/ezp" ) @@ -16,13 +16,13 @@ type Miner struct { MinAcceptedGasPrice *big.Int Extra string - coinbase []byte + Coinbase []byte mining bool } -func New(coinbase []byte, eth *eth.Ethereum) *Miner { +func New(coinbase []byte, eth core.Backend) *Miner { miner := &Miner{ - coinbase: coinbase, + Coinbase: coinbase, worker: newWorker(coinbase, eth), } -- cgit v1.2.3 From 5aff8bfb5918e53ba2590b25e6c17e1875870f6a Mon Sep 17 00:00:00 2001 From: Maran Date: Thu, 19 Feb 2015 10:38:36 +0100 Subject: Implement command line argument to set the amount of agents created by the miner Defaults to the amount of cores available on the CPU --- miner/miner.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'miner/miner.go') diff --git a/miner/miner.go b/miner/miner.go index 27afcf684..0cc2361c8 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -20,13 +20,13 @@ type Miner struct { mining bool } -func New(coinbase []byte, eth core.Backend) *Miner { +func New(coinbase []byte, eth core.Backend, minerThreads int) *Miner { miner := &Miner{ Coinbase: coinbase, worker: newWorker(coinbase, eth), } - for i := 0; i < 4; i++ { + for i := 0; i < minerThreads; i++ { miner.worker.register(NewCpuMiner(i, ezp.New())) } -- cgit v1.2.3