diff options
author | Martin Holst Swende <martin@swende.se> | 2019-09-17 15:34:28 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-09-17 15:34:28 +0800 |
commit | 8d41e885e6c4bd8d6c1bd08d385165dd41f7edf1 (patch) | |
tree | 7cfdc41ae4954d508baf6862ff9a9c174d21d8c4 | |
parent | 8bd64f4a1c26a50e099cb47c91faaa3f9c8ca6ac (diff) | |
download | go-tangerine-8d41e885e6c4bd8d6c1bd08d385165dd41f7edf1.tar go-tangerine-8d41e885e6c4bd8d6c1bd08d385165dd41f7edf1.tar.gz go-tangerine-8d41e885e6c4bd8d6c1bd08d385165dd41f7edf1.tar.bz2 go-tangerine-8d41e885e6c4bd8d6c1bd08d385165dd41f7edf1.tar.lz go-tangerine-8d41e885e6c4bd8d6c1bd08d385165dd41f7edf1.tar.xz go-tangerine-8d41e885e6c4bd8d6c1bd08d385165dd41f7edf1.tar.zst go-tangerine-8d41e885e6c4bd8d6c1bd08d385165dd41f7edf1.zip |
core: smaller txpool status locking (#20080)
* txpool: smaller lock portion
* core/tx_pool: fix data race
-rw-r--r-- | core/tx_pool.go | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/core/tx_pool.go b/core/tx_pool.go index 161489cc5..e25877a1a 100644 --- a/core/tx_pool.go +++ b/core/tx_pool.go @@ -803,19 +803,22 @@ func (pool *TxPool) addTxsLocked(txs []*types.Transaction, local bool) ([]error, // Status returns the status (unknown/pending/queued) of a batch of transactions // identified by their hashes. func (pool *TxPool) Status(hashes []common.Hash) []TxStatus { - pool.mu.RLock() - defer pool.mu.RUnlock() - status := make([]TxStatus, len(hashes)) for i, hash := range hashes { - if tx := pool.all.Get(hash); tx != nil { - from, _ := types.Sender(pool.signer, tx) // already validated - if pool.pending[from] != nil && pool.pending[from].txs.items[tx.Nonce()] != nil { - status[i] = TxStatusPending - } else { - status[i] = TxStatusQueued - } + tx := pool.Get(hash) + if tx == nil { + continue + } + from, _ := types.Sender(pool.signer, tx) // already validated + pool.mu.RLock() + if txList := pool.pending[from]; txList != nil && txList.txs.items[tx.Nonce()] != nil { + status[i] = TxStatusPending + } else if txList := pool.queue[from]; txList != nil && txList.txs.items[tx.Nonce()] != nil { + status[i] = TxStatusQueued } + // implicit else: the tx may have been included into a block between + // checking pool.Get and obtaining the lock. In that case, TxStatusUnknown is correct + pool.mu.RUnlock() } return status } |