core/txpool/legacypool: fix data race in Add

This commit is contained in:
Miro 2025-04-14 16:57:19 -04:00
parent 476f117211
commit 5d113eea32

View file

@ -943,8 +943,11 @@ func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error {
news = make([]*types.Transaction, 0, len(txs)) news = make([]*types.Transaction, 0, len(txs))
) )
for i, tx := range txs { for i, tx := range txs {
pool.mu.Lock()
hash := pool.all.Get(tx.Hash())
pool.mu.Unlock()
// If the transaction is known, pre-set the error slot // If the transaction is known, pre-set the error slot
if pool.all.Get(tx.Hash()) != nil { if hash != nil {
errs[i] = txpool.ErrAlreadyKnown errs[i] = txpool.ErrAlreadyKnown
knownTxMeter.Mark(1) knownTxMeter.Mark(1)
continue continue