aboutsummaryrefslogtreecommitdiffstats
path: root/miner
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2015-05-22 00:58:57 +0800
committerobscuren <geffobscura@gmail.com>2015-05-22 00:58:57 +0800
commit2c1c78a6d9e59de1d4cdeb32737d281814d690f7 (patch)
tree05471c7e1862733478b08e18bd7ed9419f7f7297 /miner
parent915fc0e581c042a8d4896880d45e680003809254 (diff)
parent3ea9868b656077c38af5ea8590761c3218ce558e (diff)
downloadgo-tangerine-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar
go-tangerine-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.gz
go-tangerine-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.bz2
go-tangerine-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.lz
go-tangerine-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.xz
go-tangerine-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.tar.zst
go-tangerine-2c1c78a6d9e59de1d4cdeb32737d281814d690f7.zip
Merge branch 'release/0.9.23'v0.9.23
Diffstat (limited to 'miner')
-rw-r--r--miner/agent.go25
-rw-r--r--miner/miner.go8
-rw-r--r--miner/worker.go9
3 files changed, 29 insertions, 13 deletions
diff --git a/miner/agent.go b/miner/agent.go
index da2a2008d..3ed3ba839 100644
--- a/miner/agent.go
+++ b/miner/agent.go
@@ -40,7 +40,6 @@ func (self *CpuAgent) Stop() {
defer self.mu.Unlock()
close(self.quit)
- close(self.quitCurrentOp)
}
func (self *CpuAgent) Start() {
@@ -50,7 +49,6 @@ func (self *CpuAgent) Start() {
self.quit = make(chan struct{})
// creating current op ch makes sure we're not closing a nil ch
// later on
- self.quitCurrentOp = make(chan struct{})
self.workCh = make(chan *types.Block, 1)
go self.update()
@@ -62,11 +60,19 @@ out:
select {
case block := <-self.workCh:
self.mu.Lock()
- close(self.quitCurrentOp)
+ if self.quitCurrentOp != nil {
+ close(self.quitCurrentOp)
+ }
+ self.quitCurrentOp = make(chan struct{})
+ go self.mine(block, self.quitCurrentOp)
self.mu.Unlock()
-
- go self.mine(block)
case <-self.quit:
+ self.mu.Lock()
+ if self.quitCurrentOp != nil {
+ close(self.quitCurrentOp)
+ self.quitCurrentOp = nil
+ }
+ self.mu.Unlock()
break out
}
}
@@ -84,16 +90,11 @@ done:
}
}
-func (self *CpuAgent) mine(block *types.Block) {
+func (self *CpuAgent) mine(block *types.Block, stop <- chan struct{}) {
glog.V(logger.Debug).Infof("(re)started agent[%d]. mining...\n", self.index)
- // Reset the channel
- self.mu.Lock()
- self.quitCurrentOp = make(chan struct{})
- self.mu.Unlock()
-
// Mine
- nonce, mixDigest := self.pow.Search(block, self.quitCurrentOp)
+ nonce, mixDigest := self.pow.Search(block, stop)
if nonce != 0 {
block.SetNonce(nonce)
block.Header().MixDigest = common.BytesToHash(mixDigest)
diff --git a/miner/miner.go b/miner/miner.go
index 3f87e8151..4e99245f8 100644
--- a/miner/miner.go
+++ b/miner/miner.go
@@ -39,6 +39,10 @@ func New(eth core.Backend, mux *event.TypeMux, pow pow.PoW) *Miner {
return miner
}
+// update keeps track of the downloader events. Please be aware that this is a one shot type of update loop.
+// It's entered once and as soon as `Done` or `Failed` has been broadcasted the events are unregistered and
+// the loop is exited. This to prevent a major security vuln where external parties can DOS you with blocks
+// and halt your mining operation for as long as the DOS continues.
func (self *Miner) update() {
events := self.mux.Subscribe(downloader.StartEvent{}, downloader.DoneEvent{}, downloader.FailedEvent{})
for ev := range events.Chan() {
@@ -59,6 +63,10 @@ func (self *Miner) update() {
self.Start(self.coinbase, self.threads)
}
}
+ // unsubscribe. we're only interested in this event once
+ events.Unsubscribe()
+ // stop immediately and ignore all further pending events
+ break
}
}
diff --git a/miner/worker.go b/miner/worker.go
index d5f9dd8c5..5e4ff7510 100644
--- a/miner/worker.go
+++ b/miner/worker.go
@@ -224,7 +224,13 @@ func (self *worker) wait() {
}
self.mux.Post(core.NewMinedBlockEvent{block})
- glog.V(logger.Info).Infof("🔨 Mined block #%v", block.Number())
+ var stale string
+ canonBlock := self.chain.GetBlockByNumber(block.NumberU64())
+ if canonBlock != nil && canonBlock.Hash() != block.Hash() {
+ stale = "stale-"
+ }
+
+ glog.V(logger.Info).Infof("🔨 Mined %sblock #%v (%x)", stale, block.Number(), block.Hash().Bytes()[:4])
jsonlogger.LogJson(&logger.EthMinerNewBlock{
BlockHash: block.Hash().Hex(),
@@ -264,6 +270,7 @@ func (self *worker) makeCurrent() {
}
block.Header().Extra = self.extra
+ // when 08 is processed ancestors contain 07 (quick block)
current := env(block, self.eth)
for _, ancestor := range self.chain.GetAncestors(block, 7) {
for _, uncle := range ancestor.Uncles() {