From 741fa8ca9cf5981805af16d5d9fc9adc31400320 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 16 May 2015 12:13:59 +0200 Subject: miner: mutex locks on cpu agent. Closes #1007 --- miner/agent.go | 39 +++++++++++++++++++++++---------------- 1 file changed, 23 insertions(+), 16 deletions(-) diff --git a/miner/agent.go b/miner/agent.go index 939f63fef..024e8aec0 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -11,8 +11,9 @@ import ( ) type CpuAgent struct { - chMu sync.Mutex - c chan *types.Block + mu sync.Mutex + + workCh chan *types.Block quit chan struct{} quitCurrentOp chan struct{} returnCh chan<- *types.Block @@ -30,19 +31,26 @@ func NewCpuAgent(index int, pow pow.PoW) *CpuAgent { return miner } -func (self *CpuAgent) Work() chan<- *types.Block { return self.c } +func (self *CpuAgent) Work() chan<- *types.Block { return self.workCh } func (self *CpuAgent) Pow() pow.PoW { return self.pow } func (self *CpuAgent) SetReturnCh(ch chan<- *types.Block) { self.returnCh = ch } func (self *CpuAgent) Stop() { + self.mu.Lock() + defer self.mu.Unlock() + close(self.quit) close(self.quitCurrentOp) } func (self *CpuAgent) Start() { + self.mu.Lock() + defer self.mu.Unlock() + self.quit = make(chan struct{}) - self.quitCurrentOp = make(chan struct{}, 1) - self.c = make(chan *types.Block, 1) + // creating current op ch makes sure we're not closing a nil ch + self.quitCurrentOp = make(chan struct{}) + self.workCh = make(chan *types.Block, 1) go self.update() } @@ -51,10 +59,10 @@ func (self *CpuAgent) update() { out: for { select { - case block := <-self.c: - self.chMu.Lock() - self.quitCurrentOp <- struct{}{} - self.chMu.Unlock() + case block := <-self.workCh: + self.mu.Lock() + close(self.quitCurrentOp) + self.mu.Unlock() go self.mine(block) case <-self.quit: @@ -62,14 +70,13 @@ out: } } - //close(self.quitCurrentOp) done: - // Empty channel + // Empty work channel for { select { - case <-self.c: + case <-self.workCh: default: - close(self.c) + close(self.workCh) break done } @@ -80,9 +87,9 @@ func (self *CpuAgent) mine(block *types.Block) { glog.V(logger.Debug).Infof("(re)started agent[%d]. mining...\n", self.index) // Reset the channel - self.chMu.Lock() - self.quitCurrentOp = make(chan struct{}, 1) - self.chMu.Unlock() + self.mu.Lock() + self.quitCurrentOp = make(chan struct{}) + self.mu.Unlock() // Mine nonce, mixDigest := self.pow.Search(block, self.quitCurrentOp) -- cgit v1.2.3 From fe64a13cea19556658971189024b5df98b45d4b7 Mon Sep 17 00:00:00 2001 From: Vitalik Buterin Date: Fri, 15 May 2015 21:23:09 -0400 Subject: Adjust miner coinbase and not just miner worker coinbase --- miner/miner.go | 1 + 1 file changed, 1 insertion(+) diff --git a/miner/miner.go b/miner/miner.go index 19d39a605..3f87e8151 100644 --- a/miner/miner.go +++ b/miner/miner.go @@ -75,6 +75,7 @@ func (self *Miner) Start(coinbase common.Address, threads int) { atomic.StoreInt32(&self.shouldStart, 1) self.threads = threads self.worker.coinbase = coinbase + self.coinbase = coinbase if atomic.LoadInt32(&self.canStart) == 0 { glog.V(logger.Info).Infoln("Can not start mining operation due to network sync (starts when finished)") -- cgit v1.2.3 From c2ef8682fe90c7e8c6e5d9d8ff30767f5a84e2f1 Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 16 May 2015 12:29:19 +0200 Subject: eth/downloader: moved start event Start event has moved because it could possibly could stall the miner --- eth/downloader/downloader.go | 4 ++-- miner/agent.go | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/eth/downloader/downloader.go b/eth/downloader/downloader.go index 1bc81406c..d817b223c 100644 --- a/eth/downloader/downloader.go +++ b/eth/downloader/downloader.go @@ -145,8 +145,6 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error { glog.V(logger.Info).Infoln("Block synchronisation started") } - d.mux.Post(StartEvent{}) - // Create cancel channel for aborting mid-flight d.cancelLock.Lock() d.cancelCh = make(chan struct{}) @@ -166,6 +164,7 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error { if p == nil { return errUnknownPeer } + return d.syncWithPeer(p, hash) } @@ -181,6 +180,7 @@ func (d *Downloader) Has(hash common.Hash) bool { // syncWithPeer starts a block synchronization based on the hash chain from the // specified peer and head hash. func (d *Downloader) syncWithPeer(p *peer, hash common.Hash) (err error) { + d.mux.Post(StartEvent{}) defer func() { // reset on error if err != nil { diff --git a/miner/agent.go b/miner/agent.go index 024e8aec0..da2a2008d 100644 --- a/miner/agent.go +++ b/miner/agent.go @@ -49,6 +49,7 @@ 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) -- cgit v1.2.3 From d98a6f85fc1787a166ab91720c738fed2098185f Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 16 May 2015 12:33:55 +0200 Subject: core: further improved uncle error messages --- core/block_processor.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/core/block_processor.go b/core/block_processor.go index 9a213686f..cae618b39 100644 --- a/core/block_processor.go +++ b/core/block_processor.go @@ -343,23 +343,23 @@ func (sm *BlockProcessor) VerifyUncles(statedb *state.StateDB, block, parent *ty uncles.Add(block.Hash()) for i, uncle := range block.Uncles() { - if uncles.Has(uncle.Hash()) { + hash := uncle.Hash() + if uncles.Has(hash) { // Error not unique - return UncleError("uncle[%d] not unique", i) + return UncleError("uncle[%d](%x) not unique", i, hash[:4]) } + uncles.Add(hash) - uncles.Add(uncle.Hash()) - - if ancestors.Has(uncle.Hash()) { - return UncleError("uncle[%d] is ancestor", i) + if ancestors.Has(hash) { + return UncleError("uncle[%d](%x) is ancestor", i, hash[:4]) } if !ancestors.Has(uncle.ParentHash) { - return UncleError("uncle[%d]'s parent unknown (%x)", i, uncle.ParentHash[0:4]) + return UncleError("uncle[%d](%x)'s parent unknown (%x)", i, hash[:4], uncle.ParentHash[0:4]) } if err := sm.ValidateHeader(uncle, ancestorHeaders[uncle.ParentHash]); err != nil { - return ValidationError(fmt.Sprintf("uncle[%d](%x) header invalid: %v", i, uncle.Hash().Bytes()[:4], err)) + return ValidationError(fmt.Sprintf("uncle[%d](%x) header invalid: %v", i, hash[:4], err)) } } -- cgit v1.2.3 From ad7b0efbd3fc00e089159768b7475e657adf84fe Mon Sep 17 00:00:00 2001 From: obscuren Date: Sat, 16 May 2015 12:38:23 +0200 Subject: cmd/geth: hotfix bump --- cmd/geth/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 158b08796..e9deec61f 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -50,7 +50,7 @@ import _ "net/http/pprof" const ( ClientIdentifier = "Geth" - Version = "0.9.21" + Version = "0.9.21.1" ) var ( -- cgit v1.2.3