aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPéter Szilágyi <peterke@gmail.com>2016-06-03 19:08:22 +0800
committerPéter Szilágyi <peterke@gmail.com>2016-06-03 19:08:22 +0800
commit828e1e35fd03a701a1feace3abf3b80c222c6c70 (patch)
tree65fa1380301c4e890b0f5a001be045a7f09b7b5b
parent89ba380b3c89df259c1a26747fb5002519d2a6cb (diff)
parentfc85dd175ebeef4996e5d370a7a2f085c922196d (diff)
downloaddexon-828e1e35fd03a701a1feace3abf3b80c222c6c70.tar
dexon-828e1e35fd03a701a1feace3abf3b80c222c6c70.tar.gz
dexon-828e1e35fd03a701a1feace3abf3b80c222c6c70.tar.bz2
dexon-828e1e35fd03a701a1feace3abf3b80c222c6c70.tar.lz
dexon-828e1e35fd03a701a1feace3abf3b80c222c6c70.tar.xz
dexon-828e1e35fd03a701a1feace3abf3b80c222c6c70.tar.zst
dexon-828e1e35fd03a701a1feace3abf3b80c222c6c70.zip
Merge pull request #2655 from fjl/txpool-lock
core: add missing lock in TxPool.GetTransaction
-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