aboutsummaryrefslogtreecommitdiffstats
path: root/miner/agent.go
diff options
context:
space:
mode:
authorTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 05:42:46 +0800
committerTaylor Gerring <taylor.gerring@gmail.com>2015-03-27 05:42:46 +0800
commit6bd1f6cc49acd459e61559e5af515da2db2481e5 (patch)
tree3e4f7a51ca8e3cb03d24fbe1898578d88fd7456c /miner/agent.go
parentbb12dbe233db2e064715b329b7ba987c76ba3bfa (diff)
parentb0b0939879b9fb8453ec1c8fa2ceb522e56df3bc (diff)
downloadgo-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar
go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.gz
go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.bz2
go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.lz
go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.xz
go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.tar.zst
go-tangerine-6bd1f6cc49acd459e61559e5af515da2db2481e5.zip
Merge remote-tracking branch 'origin' into rpcargs
Conflicts: rpc/args.go
Diffstat (limited to 'miner/agent.go')
-rw-r--r--miner/agent.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/miner/agent.go b/miner/agent.go
index 5661d2982..c650fa2f3 100644
--- a/miner/agent.go
+++ b/miner/agent.go
@@ -1,12 +1,15 @@
package miner
import (
+ "sync"
+
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/pow"
)
type CpuMiner struct {
+ chMu sync.Mutex
c chan *types.Block
quit chan struct{}
quitCurrentOp chan struct{}
@@ -43,16 +46,13 @@ func (self *CpuMiner) Start() {
}
func (self *CpuMiner) update() {
- justStarted := true
out:
for {
select {
case block := <-self.c:
- if justStarted {
- justStarted = true
- } else {
- self.quitCurrentOp <- struct{}{}
- }
+ self.chMu.Lock()
+ self.quitCurrentOp <- struct{}{}
+ self.chMu.Unlock()
go self.mine(block)
case <-self.quit:
@@ -60,6 +60,7 @@ out:
}
}
+ close(self.quitCurrentOp)
done:
// Empty channel
for {
@@ -75,12 +76,20 @@ done:
func (self *CpuMiner) mine(block *types.Block) {
minerlogger.Debugf("(re)started agent[%d]. mining...\n", self.index)
+
+ // Reset the channel
+ self.chMu.Lock()
+ self.quitCurrentOp = make(chan struct{}, 1)
+ self.chMu.Unlock()
+
+ // Mine
nonce, mixDigest, _ := self.pow.Search(block, self.quitCurrentOp)
if nonce != 0 {
block.SetNonce(nonce)
block.Header().MixDigest = common.BytesToHash(mixDigest)
self.returnCh <- block
- //self.returnCh <- Work{block.Number().Uint64(), nonce, mixDigest, seedHash}
+ } else {
+ self.returnCh <- nil
}
}