Skip to content

Commit 44b912e

Browse files
fjlkaralabe
authored andcommitted
[release/1.4.6] core: add missing lock in TxPool.{GetTransaction,RemoveTx}
Fixes #2650 (cherry picked from commit fc85dd1)
1 parent 3d69970 commit 44b912e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

core/tx_pool.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,9 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) {
368368
// GetTransaction returns a transaction if it is contained in the pool
369369
// and nil otherwise.
370370
func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction {
371+
tp.mu.RLock()
372+
defer tp.mu.RUnlock()
373+
371374
// check the txs first
372375
if tx, ok := tp.pending[hash]; ok {
373376
return tx
@@ -421,12 +424,18 @@ func (self *TxPool) RemoveTransactions(txs types.Transactions) {
421424
self.mu.Lock()
422425
defer self.mu.Unlock()
423426
for _, tx := range txs {
424-
self.RemoveTx(tx.Hash())
427+
self.removeTx(tx.Hash())
425428
}
426429
}
427430

428431
// RemoveTx removes the transaction with the given hash from the pool.
429432
func (pool *TxPool) RemoveTx(hash common.Hash) {
433+
pool.mu.Lock()
434+
defer pool.mu.Unlock()
435+
pool.removeTx(hash)
436+
}
437+
438+
func (pool *TxPool) removeTx(hash common.Hash) {
430439
// delete from pending pool
431440
delete(pool.pending, hash)
432441
// delete from queue

0 commit comments

Comments
 (0)