From a59ea7ce297d2bb26cee9ff295f622697645e49c Mon Sep 17 00:00:00 2001 From: obscuren Date: Tue, 24 Mar 2015 10:34:06 +0100 Subject: 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. --- miner/agent.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'miner/agent.go') 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} } } -- cgit v1.2.3