fixed stop of miner

pull/658/head
obscuren 10 years ago
parent 7f32a08b60
commit d09d2b96fc
  1. 26
      miner/worker.go

@ -98,12 +98,11 @@ func newWorker(coinbase common.Address, eth core.Backend) *worker {
possibleUncles: make(map[common.Hash]*types.Block), possibleUncles: make(map[common.Hash]*types.Block),
coinbase: coinbase, coinbase: coinbase,
txQueue: make(map[common.Hash]*types.Transaction), txQueue: make(map[common.Hash]*types.Transaction),
quit: make(chan struct{}),
} }
go worker.update() go worker.update()
go worker.wait() go worker.wait()
worker.quit = make(chan struct{})
worker.commitNewWork() worker.commitNewWork()
return worker return worker
@ -133,8 +132,14 @@ func (self *worker) start() {
} }
func (self *worker) stop() { func (self *worker) stop() {
atomic.StoreInt64(&self.mining, 0) if atomic.LoadInt64(&self.mining) == 1 {
// stop all agents
for _, agent := range self.agents {
agent.Stop()
}
}
atomic.StoreInt64(&self.mining, 0)
atomic.StoreInt64(&self.atWork, 0) atomic.StoreInt64(&self.atWork, 0)
} }
@ -164,12 +169,7 @@ out:
self.commitNewWork() self.commitNewWork()
} }
} }
case <-self.quit: case <-self.quit:
// stop all agents
for _, agent := range self.agents {
agent.Stop()
}
break out break out
case <-timer.C: case <-timer.C:
if glog.V(logger.Debug) { if glog.V(logger.Debug) {
@ -261,20 +261,18 @@ func (self *worker) commitNewWork() {
// Keep track of transactions which return errors so they can be removed // Keep track of transactions which return errors so they can be removed
var ( var (
remove types.Transactions remove = set.New()
tcount = 0 tcount = 0
) )
gasLimit: gasLimit:
for i, tx := range transactions { for i, tx := range transactions {
err := self.commitTransaction(tx) err := self.commitTransaction(tx)
switch { switch {
case core.IsNonceErr(err): case core.IsNonceErr(err) || core.IsInvalidTxErr(err):
fallthrough
case core.IsInvalidTxErr(err):
// Remove invalid transactions // Remove invalid transactions
from, _ := tx.From() from, _ := tx.From()
self.chain.TxState().RemoveNonce(from, tx.Nonce()) self.chain.TxState().RemoveNonce(from, tx.Nonce())
remove = append(remove, tx) remove.Add(tx.Hash())
if glog.V(logger.Debug) { if glog.V(logger.Debug) {
glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err) glog.Infof("TX (%x) failed, will be removed: %v\n", tx.Hash().Bytes()[:4], err)
@ -288,7 +286,7 @@ gasLimit:
tcount++ tcount++
} }
} }
self.eth.TxPool().RemoveSet(remove) self.eth.TxPool().InvalidateSet(remove)
var ( var (
uncles []*types.Header uncles []*types.Header

Loading…
Cancel
Save