From b07605627f963a36355931f3a33156c0c354fcb0 Mon Sep 17 00:00:00 2001 From: maskpp Date: Sun, 27 Jul 2025 14:35:37 +0800 Subject: [PATCH] fix bug --- core/txpool/legacypool/list.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/core/txpool/legacypool/list.go b/core/txpool/legacypool/list.go index c72323cc62..da17e96394 100644 --- a/core/txpool/legacypool/list.go +++ b/core/txpool/legacypool/list.go @@ -78,18 +78,17 @@ func (m *SortedMap) Get(nonce uint64) *types.Transaction { // index. If a transaction already exists with the same nonce, it's overwritten. func (m *SortedMap) Put(tx *types.Transaction) { nonce := tx.Nonce() - // If the tx already exit, return immediately. - if m.items[nonce] != nil { - return + if m.items[nonce] == nil { + heap.Push(m.index, nonce) } - m.items[nonce] = tx - heap.Push(m.index, nonce) m.cacheMu.Lock() if m.cache != nil { - m.cache = append(m.cache, tx) - sort.Sort(types.TxByNonce(m.cache)) + index := slices.IndexFunc(m.cache, func(tx *types.Transaction) bool { + return tx.Nonce() == nonce + }) + m.cache[index] = tx } m.cacheMu.Unlock() }