diff options
author | obscuren <geffobscura@gmail.com> | 2015-03-24 17:34:06 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2015-03-24 17:34:06 +0800 |
commit | a59ea7ce297d2bb26cee9ff295f622697645e49c (patch) | |
tree | 13c6feda5b05430911ebbc5492a485dfd59c54ae /miner/worker.go | |
parent | d8e21b39b30f3951c17a618baffcc3592afae0b1 (diff) | |
download | go-tangerine-a59ea7ce297d2bb26cee9ff295f622697645e49c.tar go-tangerine-a59ea7ce297d2bb26cee9ff295f622697645e49c.tar.gz go-tangerine-a59ea7ce297d2bb26cee9ff295f622697645e49c.tar.bz2 go-tangerine-a59ea7ce297d2bb26cee9ff295f622697645e49c.tar.lz go-tangerine-a59ea7ce297d2bb26cee9ff295f622697645e49c.tar.xz go-tangerine-a59ea7ce297d2bb26cee9ff295f622697645e49c.tar.zst go-tangerine-a59ea7ce297d2bb26cee9ff295f622697645e49c.zip |
Changed miner
* Instead of delivering `Work` to the `Worker`, push a complete Block to
the `Worker` so that each agent can work on their own block.
Diffstat (limited to 'miner/worker.go')
-rw-r--r-- | miner/worker.go | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/miner/worker.go b/miner/worker.go index d96da9829..3c3411fa9 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -51,7 +51,7 @@ type Work struct { type Agent interface { Work() chan<- *types.Block - SetWorkCh(chan<- Work) + SetReturnCh(chan<- *types.Block) Stop() Start() GetHashRate() int64 @@ -60,7 +60,7 @@ type Agent interface { type worker struct { mu sync.Mutex agents []Agent - recv chan Work + recv chan *types.Block mux *event.TypeMux quit chan struct{} pow pow.PoW @@ -82,7 +82,7 @@ func newWorker(coinbase common.Address, eth core.Backend) *worker { return &worker{ eth: eth, mux: eth.EventMux(), - recv: make(chan Work), + recv: make(chan *types.Block), chain: eth.ChainManager(), proc: eth.BlockProcessor(), possibleUncles: make(map[common.Hash]*types.Block), @@ -112,7 +112,7 @@ func (self *worker) stop() { func (self *worker) register(agent Agent) { self.agents = append(self.agents, agent) - agent.SetWorkCh(self.recv) + agent.SetReturnCh(self.recv) } func (self *worker) update() { @@ -155,30 +155,30 @@ func (self *worker) addUncle(uncle *types.Block) { func (self *worker) wait() { for { - for work := range self.recv { + for block := range self.recv { // Someone Successfully Mined! - block := self.current.block - if block.Number().Uint64() == work.Number && block.Nonce() == 0 { - self.current.block.SetNonce(work.Nonce) - self.current.block.Header().MixDigest = common.BytesToHash(work.MixDigest) - - jsonlogger.LogJson(&logger.EthMinerNewBlock{ - BlockHash: block.Hash().Hex(), - BlockNumber: block.Number(), - ChainHeadHash: block.ParentHeaderHash.Hex(), - BlockPrevHash: block.ParentHeaderHash.Hex(), - }) - - if err := self.chain.InsertChain(types.Blocks{self.current.block}); err == nil { - for _, uncle := range self.current.block.Uncles() { - delete(self.possibleUncles, uncle.Hash()) - } - - self.mux.Post(core.NewMinedBlockEvent{self.current.block}) - } else { - self.commitNewWork() + //block := self.current.block + //if block.Number().Uint64() == work.Number && block.Nonce() == 0 { + //self.current.block.SetNonce(work.Nonce) + //self.current.block.Header().MixDigest = common.BytesToHash(work.MixDigest) + + jsonlogger.LogJson(&logger.EthMinerNewBlock{ + BlockHash: block.Hash().Hex(), + BlockNumber: block.Number(), + ChainHeadHash: block.ParentHeaderHash.Hex(), + BlockPrevHash: block.ParentHeaderHash.Hex(), + }) + + if err := self.chain.InsertChain(types.Blocks{block}); err == nil { + for _, uncle := range block.Uncles() { + delete(self.possibleUncles, uncle.Hash()) } + + self.mux.Post(core.NewMinedBlockEvent{block}) + } else { + self.commitNewWork() } + //} break } } @@ -191,7 +191,7 @@ func (self *worker) push() { // push new work to agents for _, agent := range self.agents { - agent.Work() <- self.current.block + agent.Work() <- self.current.block.Copy() } } } |