From 8b1c1ddfa0d4c57f31d46c0970ba4a63f247e164 Mon Sep 17 00:00:00 2001 From: maskpp Date: Mon, 28 Jul 2025 21:47:42 +0800 Subject: [PATCH] fix bug and comments --- core/txpool/legacypool/list.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/core/txpool/legacypool/list.go b/core/txpool/legacypool/list.go index da17e96394..c003272f6a 100644 --- a/core/txpool/legacypool/list.go +++ b/core/txpool/legacypool/list.go @@ -88,7 +88,12 @@ func (m *SortedMap) Put(tx *types.Transaction) { index := slices.IndexFunc(m.cache, func(tx *types.Transaction) bool { return tx.Nonce() == nonce }) - m.cache[index] = tx + if index == -1 { + m.cache = append(m.cache, tx) + sort.Sort(types.TxByNonce(m.cache)) + } else { + m.cache[index] = tx + } } m.cacheMu.Unlock() } @@ -200,11 +205,7 @@ func (m *SortedMap) Remove(nonce uint64) bool { delete(m.items, nonce) m.cacheMu.Lock() - if m.cache != nil { - slices.DeleteFunc(m.cache, func(tx *types.Transaction) bool { - return tx.Nonce() == nonce - }) - } + m.cache = nil m.cacheMu.Unlock() return true