diff options
author | Felix Lange <fjl@twurst.com> | 2016-06-03 02:33:45 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2016-06-06 21:22:00 +0800 |
commit | 44b912ec64b0d732a528e61ff6c899e3e51eddf7 (patch) | |
tree | 1614c978e94db159a3c48e3bbe85031d3e09d643 /core | |
parent | 3d69970c1555f8a730682039763d575c916fa5f6 (diff) | |
download | go-tangerine-44b912ec64b0d732a528e61ff6c899e3e51eddf7.tar go-tangerine-44b912ec64b0d732a528e61ff6c899e3e51eddf7.tar.gz go-tangerine-44b912ec64b0d732a528e61ff6c899e3e51eddf7.tar.bz2 go-tangerine-44b912ec64b0d732a528e61ff6c899e3e51eddf7.tar.lz go-tangerine-44b912ec64b0d732a528e61ff6c899e3e51eddf7.tar.xz go-tangerine-44b912ec64b0d732a528e61ff6c899e3e51eddf7.tar.zst go-tangerine-44b912ec64b0d732a528e61ff6c899e3e51eddf7.zip |
[release/1.4.6] core: add missing lock in TxPool.{GetTransaction,RemoveTx}
Fixes #2650
(cherry picked from commit fc85dd175ebeef4996e5d370a7a2f085c922196d)
Diffstat (limited to 'core')
-rw-r--r-- | core/tx_pool.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/tx_pool.go b/core/tx_pool.go index f2eb2bbdd..596356377 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -368,6 +368,9 @@ func (self *TxPool) AddTransactions(txs []*types.Transaction) { // GetTransaction returns a transaction if it is contained in the pool // and nil otherwise. func (tp *TxPool) GetTransaction(hash common.Hash) *types.Transaction { + tp.mu.RLock() + defer tp.mu.RUnlock() + // check the txs first if tx, ok := tp.pending[hash]; ok { return tx @@ -421,12 +424,18 @@ func (self *TxPool) RemoveTransactions(txs types.Transactions) { self.mu.Lock() defer self.mu.Unlock() for _, tx := range txs { - self.RemoveTx(tx.Hash()) + self.removeTx(tx.Hash()) } } // RemoveTx removes the transaction with the given hash from the pool. func (pool *TxPool) RemoveTx(hash common.Hash) { + pool.mu.Lock() + defer pool.mu.Unlock() + pool.removeTx(hash) +} + +func (pool *TxPool) removeTx(hash common.Hash) { // delete from pending pool delete(pool.pending, hash) // delete from queue |