core/tx_pool: fix data race

This commit is contained in:
Martin Holst Swende 2019-09-16 15:38:45 +02:00
parent 47fd824ebd
commit aab6a0b0ab
No known key found for this signature in database
GPG key ID: 683B438C05A5DDF0

View file

@ -805,16 +805,20 @@ func (pool *TxPool) addTxsLocked(txs []*types.Transaction, local bool) ([]error,
func (pool *TxPool) Status(hashes []common.Hash) []TxStatus { func (pool *TxPool) Status(hashes []common.Hash) []TxStatus {
status := make([]TxStatus, len(hashes)) status := make([]TxStatus, len(hashes))
for i, hash := range hashes { for i, hash := range hashes {
if tx := pool.Get(hash); tx != nil { tx := pool.Get(hash)
from, _ := types.Sender(pool.signer, tx) // already validated if tx == nil {
pool.mu.RLock() continue
if txList := pool.pending[from]; txList != nil && txList.txs.items[tx.Nonce()] != nil {
status[i] = TxStatusPending
} else {
status[i] = TxStatusQueued
}
pool.mu.RUnlock()
} }
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 return status
} }