Optimize locking in LegacyPool.Content method

Changed locking mechanism in Content method to use RLock for read operations.
This commit is contained in:
Kyrin 2025-10-16 23:37:13 +08:00 committed by GitHub
parent 7c107c2691
commit f90ed5c81f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -456,7 +456,7 @@ func (pool *LegacyPool) stats() (int, int) {
// Content retrieves the data content of the transaction pool, returning all the
// pending as well as queued transactions, grouped by account and sorted by nonce.
func (pool *LegacyPool) Content() (map[common.Address][]*types.Transaction, map[common.Address][]*types.Transaction) {
pool.mu.Lock()
pool.mu.RLock()
defer pool.mu.Unlock()
pending := make(map[common.Address][]*types.Transaction, len(pool.pending))
@ -492,7 +492,7 @@ func (pool *LegacyPool) Pending(filter txpool.PendingFilter) map[common.Address]
if filter.BlobTxs {
return nil
}
pool.mu.Lock()
pool.mu.RLock()
defer pool.mu.Unlock()
pending := make(map[common.Address][]*txpool.LazyTransaction, len(pool.pending))