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/agent.go | |
parent | d8e21b39b30f3951c17a618baffcc3592afae0b1 (diff) | |
download | dexon-a59ea7ce297d2bb26cee9ff295f622697645e49c.tar.gz dexon-a59ea7ce297d2bb26cee9ff295f622697645e49c.tar.zst dexon-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/agent.go')
-rw-r--r-- | miner/agent.go | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/miner/agent.go b/miner/agent.go index 64491e04c..d2e2e89bd 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -1,6 +1,7 @@ package miner import ( + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/pow" ) @@ -9,7 +10,7 @@ type CpuMiner struct { c chan *types.Block quit chan struct{} quitCurrentOp chan struct{} - returnCh chan<- Work + returnCh chan<- *types.Block index int pow pow.PoW @@ -24,9 +25,9 @@ func NewCpuMiner(index int, pow pow.PoW) *CpuMiner { return miner } -func (self *CpuMiner) Work() chan<- *types.Block { return self.c } -func (self *CpuMiner) Pow() pow.PoW { return self.pow } -func (self *CpuMiner) SetWorkCh(ch chan<- Work) { self.returnCh = ch } +func (self *CpuMiner) Work() chan<- *types.Block { return self.c } +func (self *CpuMiner) Pow() pow.PoW { return self.pow } +func (self *CpuMiner) SetReturnCh(ch chan<- *types.Block) { self.returnCh = ch } func (self *CpuMiner) Stop() { close(self.quit) @@ -74,9 +75,12 @@ done: func (self *CpuMiner) mine(block *types.Block) { minerlogger.Infof("(re)started agent[%d]. mining...\n", self.index) - nonce, mixDigest, seedHash := self.pow.Search(block, self.quitCurrentOp) + nonce, mixDigest, _ := self.pow.Search(block, self.quitCurrentOp) if nonce != 0 { - self.returnCh <- Work{block.Number().Uint64(), nonce, mixDigest, seedHash} + block.SetNonce(nonce) + block.Header().MixDigest = common.BytesToHash(mixDigest) + self.returnCh <- block + //self.returnCh <- Work{block.Number().Uint64(), nonce, mixDigest, seedHash} } } |