From 0a1eeca41e6ba5920ba65d9b41654768299bc7e3 Mon Sep 17 00:00:00 2001 From: obscuren Date: Wed, 18 Mar 2015 13:00:01 +0100 Subject: conversions. -compilable- --- miner/miner.go | 3 ++- miner/worker.go | 27 ++++++++++++++------------- 2 files changed, 16 insertions(+), 14 deletions(-) (limited to 'miner') diff --git a/miner/miner.go b/miner/miner.go index 7bf67a6ec..ccc19c754 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -4,6 +4,7 @@ import ( "math/big" "github.com/ethereum/ethash" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/pow" @@ -32,7 +33,7 @@ func (self *Miner) Mining() bool { return self.mining } -func (self *Miner) Start(coinbase []byte) { +func (self *Miner) Start(coinbase common.Address) { self.mining = true self.worker = newWorker(coinbase, self.eth) self.worker.register(NewCpuMiner(0, self.pow)) diff --git a/miner/worker.go b/miner/worker.go index 10fc6f508..63d1bfa0b 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -7,9 +7,9 @@ import ( "sync" "time" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" - "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/event" "github.com/ethereum/go-ethereum/logger" "github.com/ethereum/go-ethereum/pow" @@ -39,7 +39,7 @@ func env(block *types.Block, eth core.Backend) *environment { coinbase: state.GetOrNewStateObject(block.Coinbase()), } for _, ancestor := range eth.ChainManager().GetAncestors(block, 7) { - env.ancestors.Add(string(ancestor.Hash())) + env.ancestors.Add(ancestor.Hash()) } return env @@ -71,14 +71,14 @@ type worker struct { eth core.Backend chain *core.ChainManager proc *core.BlockProcessor - coinbase []byte + coinbase common.Address current *environment mining bool } -func newWorker(coinbase []byte, eth core.Backend) *worker { +func newWorker(coinbase common.Address, eth core.Backend) *worker { return &worker{ eth: eth, mux: eth.EventMux(), @@ -152,13 +152,13 @@ func (self *worker) wait() { block := self.current.block if block.Number().Uint64() == work.Number && block.Nonce() == 0 { self.current.block.SetNonce(work.Nonce) - self.current.block.Header().MixDigest = work.MixDigest + self.current.block.Header().MixDigest = common.BytesToHash(work.MixDigest) jsonlogger.LogJson(&logger.EthMinerNewBlock{ - BlockHash: common.Bytes2Hex(block.Hash()), + BlockHash: block.Hash().Hex(), BlockNumber: block.Number(), - ChainHeadHash: common.Bytes2Hex(block.ParentHeaderHash), - BlockPrevHash: common.Bytes2Hex(block.ParentHeaderHash), + ChainHeadHash: block.ParentHeaderHash.Hex(), + BlockPrevHash: block.ParentHeaderHash.Hex(), }) if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil { @@ -208,9 +208,10 @@ gasLimit: fallthrough case core.IsInvalidTxErr(err): // Remove invalid transactions - self.chain.TxState().RemoveNonce(tx.From(), tx.Nonce()) + from, _ := tx.From() + self.chain.TxState().RemoveNonce(from, tx.Nonce()) remove = append(remove, tx) - minerlogger.Infof("TX (%x) failed. Transaction will be removed\n", tx.Hash()[:4]) + minerlogger.Infof("TX (%x) failed. Transaction will be removed\n", tx.Hash().Bytes()[:4]) case state.IsGasLimitErr(err): minerlogger.Infof("Gas limit reached for block. %d TXs included in this block\n", i) // Break on gas limit @@ -232,13 +233,13 @@ var ( ) func (self *worker) commitUncle(uncle *types.Header) error { - if self.current.uncles.Has(string(uncle.Hash())) { + if self.current.uncles.Has(uncle.Hash()) { // Error not unique return core.UncleError("Uncle not unique") } - self.current.uncles.Add(string(uncle.Hash())) + self.current.uncles.Add(uncle.Hash()) - if !self.current.ancestors.Has(string(uncle.ParentHash)) { + if !self.current.ancestors.Has(uncle.ParentHash) { return core.UncleError(fmt.Sprintf("Uncle's parent unknown (%x)", uncle.ParentHash[0:4])) } -- cgit v1.2.3 From 54dac59285ccc6a3af47201479ca556da2899e93 Mon Sep 17 00:00:00 2001 From: obscuren Date: Fri, 20 Mar 2015 17:42:09 +0100 Subject: wip --- miner/agent.go | 4 ++++ miner/worker.go | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'miner') diff --git a/miner/agent.go b/miner/agent.go index 6865d5a08..64491e04c 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -79,3 +79,7 @@ func (self *CpuMiner) mine(block *types.Block) { self.returnCh <- Work{block.Number().Uint64(), nonce, mixDigest, seedHash} } } + +func (self *CpuMiner) GetHashRate() int64 { + return self.pow.GetHashrate() +} diff --git a/miner/worker.go b/miner/worker.go index 63d1bfa0b..ae6782aca 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -57,7 +57,7 @@ type Agent interface { SetWorkCh(chan<- Work) Stop() Start() - Pow() pow.PoW + GetHashRate() int64 } type worker struct { @@ -272,7 +272,7 @@ func (self *worker) commitTransaction(tx *types.Transaction) error { func (self *worker) HashRate() int64 { var tot int64 for _, agent := range self.agents { - tot += agent.Pow().GetHashrate() + tot += agent.GetHashRate() } return tot -- cgit v1.2.3 From ce862ee7589a0780cebc8a7bb1cf6a75193d55a0 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 21 Mar 2015 14:51:45 +0100 Subject: Removed some comments --- miner/worker.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'miner') diff --git a/miner/worker.go b/miner/worker.go index ae6782aca..4a52a40fe 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -211,7 +211,8 @@ gasLimit: from, _ := tx.From() self.chain.TxState().RemoveNonce(from, tx.Nonce()) remove = append(remove, tx) - minerlogger.Infof("TX (%x) failed. Transaction will be removed\n", tx.Hash().Bytes()[:4]) + minerlogger.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err) + minerlogger.Infoln(tx) case state.IsGasLimitErr(err): minerlogger.Infof("Gas limit reached for block. %d TXs included in this block\n", i) // Break on gas limit -- cgit v1.2.3