Skip to content

Commit

Permalink
Merge branch 'hotfix/0.9.21-1'
Browse files Browse the repository at this point in the history
  • Loading branch information
obscuren committed May 16, 2015
2 parents 1564f1a + ad7b0ef commit 69f8a1b
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/geth/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import _ "net/http/pprof"

const (
ClientIdentifier = "Geth"
Version = "0.9.21"
Version = "0.9.21.1"
)

var (
Expand Down
16 changes: 8 additions & 8 deletions core/block_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}

Expand Down
4 changes: 2 additions & 2 deletions eth/downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{})
Expand All @@ -166,6 +164,7 @@ func (d *Downloader) Synchronise(id string, hash common.Hash) error {
if p == nil {
return errUnknownPeer
}

return d.syncWithPeer(p, hash)
}

Expand All @@ -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 {
Expand Down
40 changes: 24 additions & 16 deletions miner/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -30,19 +31,27 @@ 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
// later on
self.quitCurrentOp = make(chan struct{})
self.workCh = make(chan *types.Block, 1)

go self.update()
}
Expand All @@ -51,25 +60,24 @@ 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:
break 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
}
Expand All @@ -80,9 +88,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)
Expand Down
1 change: 1 addition & 0 deletions miner/miner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)")
Expand Down

0 comments on commit 69f8a1b

Please sign in to comment.