Skip to content

Commit 343cb26

Browse files
mirokuratczyk0g-wh
authored andcommitted
core/txpool/legacypool: fix data race of txlookup access (ethereum#31641)
1 parent eb97340 commit 343cb26

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

core/txpool/legacypool/legacypool.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1827,6 +1827,16 @@ func (t *lookup) Remove(hash common.Hash) {
18271827
delete(t.txs, hash)
18281828
}
18291829

1830+
// Clear resets the lookup structure, removing all stored entries.
1831+
func (t *lookup) Clear() {
1832+
t.lock.Lock()
1833+
defer t.lock.Unlock()
1834+
1835+
t.slots = 0
1836+
t.txs = make(map[common.Hash]*types.Transaction)
1837+
t.auths = make(map[common.Address][]common.Hash)
1838+
}
1839+
18301840
// TxsBelowTip finds all remote transactions below the given tip threshold.
18311841
func (t *lookup) TxsBelowTip(threshold *big.Int) types.Transactions {
18321842
found := make(types.Transactions, 0, 128)
@@ -1923,7 +1933,7 @@ func (pool *LegacyPool) Clear() {
19231933
for addr := range pool.queue {
19241934
pool.reserver.Release(addr)
19251935
}
1926-
pool.all = newLookup()
1936+
pool.all.Clear()
19271937
pool.priced = newPricedList(pool.all)
19281938
pool.pending = make(map[common.Address]*list)
19291939
pool.queue = make(map[common.Address]*list)

0 commit comments

Comments
 (0)