diff options
author | Alexandre Van de Sande <alex.vandesande@ethdev.com> | 2015-03-04 21:04:07 +0800 |
---|---|---|
committer | Alexandre Van de Sande <alex.vandesande@ethdev.com> | 2015-03-04 21:04:07 +0800 |
commit | 5f25c117eb6a1145b18fc13ebc03e4dc570b908e (patch) | |
tree | f5296850d29c08179ac9f51c925463d880e2db08 /miner/worker.go | |
parent | cf880f78d5e85d563654ac8277c1d51bf8c382c2 (diff) | |
parent | a56243075a7527d65d14c4cf3480029feb0a1e3f (diff) | |
download | dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.gz dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.bz2 dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.lz dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.xz dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.tar.zst dexon-5f25c117eb6a1145b18fc13ebc03e4dc570b908e.zip |
Merge branch 'develop' into ui
Diffstat (limited to 'miner/worker.go')
-rw-r--r-- | miner/worker.go | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/miner/worker.go b/miner/worker.go index 1f3a52ab5..bc1c8e194 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -5,16 +5,20 @@ import ( "math/big" "sort" "sync" + "time" "github.com/ethereum/go-ethereum/core" "github.com/ethereum/go-ethereum/core/types" "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" "gopkg.in/fatih/set.v0" ) +var jsonlogger = logger.NewJsonLogger() + type environment struct { totalUsedGas *big.Int state *state.StateDB @@ -111,6 +115,8 @@ func (self *worker) register(agent Agent) { func (self *worker) update() { events := self.mux.Subscribe(core.ChainEvent{}, core.NewMinedBlockEvent{}) + timer := time.NewTicker(2 * time.Second) + out: for { select { @@ -129,6 +135,8 @@ out: agent.Stop() } break out + case <-timer.C: + minerlogger.Debugln("Hash rate:", self.HashRate(), "Khash") } } @@ -141,7 +149,12 @@ func (self *worker) wait() { block := self.current.block if block.Number().Uint64() == work.Number && block.Nonce() == nil { self.current.block.Header().Nonce = work.Nonce - + jsonlogger.LogJson(&logger.EthMinerNewBlock{ + BlockHash: ethutil.Bytes2Hex(block.Hash()), + BlockNumber: block.Number(), + ChainHeadHash: ethutil.Bytes2Hex(block.ParentHeaderHash), + BlockPrevHash: ethutil.Bytes2Hex(block.ParentHeaderHash), + }) if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil { self.mux.Post(core.NewMinedBlockEvent{self.current.block}) } else { @@ -197,7 +210,7 @@ gasLimit: } self.eth.TxPool().RemoveSet(remove) - self.current.coinbase.AddAmount(core.BlockReward) + self.current.coinbase.AddBalance(core.BlockReward) self.current.state.Update(ethutil.Big0) self.push() @@ -225,7 +238,7 @@ func (self *worker) commitUncle(uncle *types.Header) error { } uncleAccount := self.current.state.GetAccount(uncle.Coinbase) - uncleAccount.AddAmount(uncleReward) + uncleAccount.AddBalance(uncleReward) self.current.coinbase.AddBalance(uncleReward) @@ -244,3 +257,12 @@ func (self *worker) commitTransaction(tx *types.Transaction) error { return nil } + +func (self *worker) HashRate() int64 { + var tot int64 + for _, agent := range self.agents { + tot += agent.Pow().GetHashrate() + } + + return tot +} |