Skip to content

Commit 9cc0f60

Browse files
authored
Merge pull request #3429 from bas-vk/txpool-crash
core: init pending state in tx pool on creation
2 parents fdb8edf + 9f1520b commit 9cc0f60

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

core/tx_pool.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ func NewTxPool(config *params.ChainConfig, eventMux *event.TypeMux, currentState
124124
quit: make(chan struct{}),
125125
}
126126

127+
pool.resetState()
128+
127129
pool.wg.Add(2)
128130
go pool.eventLoop()
129131
go pool.expirationLoop()
@@ -196,12 +198,8 @@ func (pool *TxPool) Stop() {
196198
}
197199

198200
func (pool *TxPool) State() *state.ManagedState {
199-
pool.mu.Lock()
200-
defer pool.mu.Unlock()
201-
202-
if pool.pendingState == nil {
203-
pool.resetState()
204-
}
201+
pool.mu.RLock()
202+
defer pool.mu.RUnlock()
205203

206204
return pool.pendingState
207205
}
@@ -381,10 +379,6 @@ func (pool *TxPool) enqueueTx(hash common.Hash, tx *types.Transaction) {
381379
//
382380
// Note, this method assumes the pool lock is held!
383381
func (pool *TxPool) promoteTx(addr common.Address, hash common.Hash, tx *types.Transaction) {
384-
// Init delayed since tx pool could have been started before any state sync
385-
if pool.pendingState == nil {
386-
pool.resetState()
387-
}
388382
// Try to insert the transaction into the pending queue
389383
if pool.pending[addr] == nil {
390384
pool.pending[addr] = newTxList(true)

0 commit comments

Comments
 (0)