core: fixed race condition for subscriptions

pull/1223/head
obscuren 10 years ago
parent 29f7902fee
commit 4407524d13
  1. 3
      core/transaction_pool.go

@ -58,6 +58,7 @@ func NewTxPool(eventMux *event.TypeMux, currentStateFn stateFn, gasLimitFn func(
currentState: currentStateFn, currentState: currentStateFn,
gasLimit: gasLimitFn, gasLimit: gasLimitFn,
pendingState: state.ManageState(currentStateFn()), pendingState: state.ManageState(currentStateFn()),
events: eventMux.Subscribe(ChainEvent{}),
} }
go pool.eventLoop() go pool.eventLoop()
@ -68,7 +69,6 @@ func (pool *TxPool) eventLoop() {
// Track chain events. When a chain events occurs (new chain canon block) // Track chain events. When a chain events occurs (new chain canon block)
// we need to know the new state. The new state will help us determine // we need to know the new state. The new state will help us determine
// the nonces in the managed state // the nonces in the managed state
pool.events = pool.eventMux.Subscribe(ChainEvent{})
for _ = range pool.events.Chan() { for _ = range pool.events.Chan() {
pool.mu.Lock() pool.mu.Lock()
@ -103,7 +103,6 @@ func (pool *TxPool) resetState() {
} }
func (pool *TxPool) Stop() { func (pool *TxPool) Stop() {
pool.pending = make(map[common.Hash]*types.Transaction)
close(pool.quit) close(pool.quit)
pool.events.Unsubscribe() pool.events.Unsubscribe()
glog.V(logger.Info).Infoln("TX Pool stopped") glog.V(logger.Info).Infoln("TX Pool stopped")

Loading…
Cancel
Save