From 5d113eea3216e7c28d74faccb4f6caaafb075b46 Mon Sep 17 00:00:00 2001 From: Miro Date: Mon, 14 Apr 2025 16:57:19 -0400 Subject: [PATCH] core/txpool/legacypool: fix data race in Add --- core/txpool/legacypool/legacypool.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/core/txpool/legacypool/legacypool.go b/core/txpool/legacypool/legacypool.go index 04f1a2234c..08134fef62 100644 --- a/core/txpool/legacypool/legacypool.go +++ b/core/txpool/legacypool/legacypool.go @@ -943,8 +943,11 @@ func (pool *LegacyPool) Add(txs []*types.Transaction, sync bool) []error { news = make([]*types.Transaction, 0, len(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 pool.all.Get(tx.Hash()) != nil { + if hash != nil { errs[i] = txpool.ErrAlreadyKnown knownTxMeter.Mark(1) continue