core: smaller txpool status locking (#20080)
* txpool: smaller lock portion * core/tx_pool: fix data race
This commit is contained in:
		
							parent
							
								
									8bd64f4a1c
								
							
						
					
					
						commit
						8d41e885e6
					
				| @ -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
 | // Status returns the status (unknown/pending/queued) of a batch of transactions
 | ||||||
| // identified by their hashes.
 | // identified by their hashes.
 | ||||||
| func (pool *TxPool) Status(hashes []common.Hash) []TxStatus { | func (pool *TxPool) Status(hashes []common.Hash) []TxStatus { | ||||||
| 	pool.mu.RLock() |  | ||||||
| 	defer pool.mu.RUnlock() |  | ||||||
| 
 |  | ||||||
| 	status := make([]TxStatus, len(hashes)) | 	status := make([]TxStatus, len(hashes)) | ||||||
| 	for i, hash := range hashes { | 	for i, hash := range hashes { | ||||||
| 		if tx := pool.all.Get(hash); tx != nil { | 		tx := pool.Get(hash) | ||||||
| 			from, _ := types.Sender(pool.signer, tx) // already validated
 | 		if tx == nil { | ||||||
| 			if pool.pending[from] != nil && pool.pending[from].txs.items[tx.Nonce()] != nil { | 			continue | ||||||
| 				status[i] = TxStatusPending |  | ||||||
| 			} else { |  | ||||||
| 				status[i] = TxStatusQueued |  | ||||||
| 			} |  | ||||||
| 		} | 		} | ||||||
|  | 		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 | ||||||
| } | } | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user