Fixed a few issues in the miner and updated hash rate title

* Sometimes old nonces were set by "old" agents
* Added the hash rate to the miner
This commit is contained in:
obscuren
2015-02-13 17:23:09 +01:00
parent 8305d409d2
commit 8a0f23915e
5 changed files with 66 additions and 29 deletions

View File

@ -9,7 +9,7 @@ type CpuMiner struct {
c chan *types.Block
quit chan struct{}
quitCurrentOp chan struct{}
returnCh chan<- []byte
returnCh chan<- Work
index int
pow pow.PoW
@ -28,9 +28,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) SetNonceCh(ch chan<- []byte) { 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) SetNonceCh(ch chan<- Work) { self.returnCh = ch }
func (self *CpuMiner) Stop() {
close(self.quit)
@ -42,7 +42,6 @@ out:
for {
select {
case block := <-self.c:
minerlogger.Infof("miner[%d] got block\n", self.index)
// make sure it's open
self.quitCurrentOp <- struct{}{}
@ -66,9 +65,9 @@ done:
}
func (self *CpuMiner) mine(block *types.Block) {
minerlogger.Infof("started agent[%d]. mining...\n", self.index)
minerlogger.Infof("(re)started agent[%d]. mining...\n", self.index)
nonce := self.pow.Search(block, self.quitCurrentOp)
if nonce != nil {
self.returnCh <- nonce
self.returnCh <- Work{block.Number().Uint64(), nonce}
}
}