@@ -98,12 +98,11 @@ func newWorker(coinbase common.Address, eth core.Backend) *worker {
9898 possibleUncles : make (map [common.Hash ]* types.Block ),
9999 coinbase : coinbase ,
100100 txQueue : make (map [common.Hash ]* types.Transaction ),
101+ quit : make (chan struct {}),
101102 }
102103 go worker .update ()
103104 go worker .wait ()
104105
105- worker .quit = make (chan struct {})
106-
107106 worker .commitNewWork ()
108107
109108 return worker
@@ -133,8 +132,14 @@ func (self *worker) start() {
133132}
134133
135134func (self * worker ) stop () {
136- atomic .StoreInt64 (& self .mining , 0 )
135+ if atomic .LoadInt64 (& self .mining ) == 1 {
136+ // stop all agents
137+ for _ , agent := range self .agents {
138+ agent .Stop ()
139+ }
140+ }
137141
142+ atomic .StoreInt64 (& self .mining , 0 )
138143 atomic .StoreInt64 (& self .atWork , 0 )
139144}
140145
@@ -164,12 +169,7 @@ out:
164169 self .commitNewWork ()
165170 }
166171 }
167-
168172 case <- self .quit :
169- // stop all agents
170- for _ , agent := range self .agents {
171- agent .Stop ()
172- }
173173 break out
174174 case <- timer .C :
175175 if glog .V (logger .Debug ) {
@@ -261,20 +261,18 @@ func (self *worker) commitNewWork() {
261261
262262 // Keep track of transactions which return errors so they can be removed
263263 var (
264- remove types. Transactions
264+ remove = set . New ()
265265 tcount = 0
266266 )
267267gasLimit:
268268 for i , tx := range transactions {
269269 err := self .commitTransaction (tx )
270270 switch {
271- case core .IsNonceErr (err ):
272- fallthrough
273- case core .IsInvalidTxErr (err ):
271+ case core .IsNonceErr (err ) || core .IsInvalidTxErr (err ):
274272 // Remove invalid transactions
275273 from , _ := tx .From ()
276274 self .chain .TxState ().RemoveNonce (from , tx .Nonce ())
277- remove = append ( remove , tx )
275+ remove . Add ( tx . Hash () )
278276
279277 if glog .V (logger .Debug ) {
280278 glog .Infof ("TX (%x) failed, will be removed: %v\n " , tx .Hash ().Bytes ()[:4 ], err )
@@ -288,7 +286,7 @@ gasLimit:
288286 tcount ++
289287 }
290288 }
291- self .eth .TxPool ().RemoveSet (remove )
289+ self .eth .TxPool ().InvalidateSet (remove )
292290
293291 var (
294292 uncles []* types.Header
0 commit comments