aboutsummaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2016-06-03 02:33:45 +0800
committerFelix Lange <fjl@twurst.com>2016-06-03 18:43:33 +0800
commitfc85dd175ebeef4996e5d370a7a2f085c922196d (patch)
tree65fa1380301c4e890b0f5a001be045a7f09b7b5b /core
parent89ba380b3c89df259c1a26747fb5002519d2a6cb (diff)
downloadgo-tangerine-fc85dd175ebeef4996e5d370a7a2f085c922196d.tar
go-tangerine-fc85dd175ebeef4996e5d370a7a2f085c922196d.tar.gz
go-tangerine-fc85dd175ebeef4996e5d370a7a2f085c922196d.tar.bz2
go-tangerine-fc85dd175ebeef4996e5d370a7a2f085c922196d.tar.lz
go-tangerine-fc85dd175ebeef4996e5d370a7a2f085c922196d.tar.xz
go-tangerine-fc85dd175ebeef4996e5d370a7a2f085c922196d.tar.zst
go-tangerine-fc85dd175ebeef4996e5d370a7a2f085c922196d.zip
core: add missing lock in TxPool.{GetTransaction,RemoveTx}
Fixes #2650
Diffstat (limited to 'core')
-rw-r--r--core/tx_pool.go11
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