This commit is contained in:
maskpp 2025-07-27 14:35:37 +08:00
parent 50958bac5c
commit b07605627f

View file

@ -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
}
m.items[nonce] = tx
if m.items[nonce] == nil {
heap.Push(m.index, nonce)
}
m.items[nonce] = tx
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()
}