mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-24 13:46:43 +00:00
fix bug
This commit is contained in:
parent
50958bac5c
commit
b07605627f
1 changed files with 6 additions and 7 deletions
|
|
@ -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.
|
// index. If a transaction already exists with the same nonce, it's overwritten.
|
||||||
func (m *SortedMap) Put(tx *types.Transaction) {
|
func (m *SortedMap) Put(tx *types.Transaction) {
|
||||||
nonce := tx.Nonce()
|
nonce := tx.Nonce()
|
||||||
// If the tx already exit, return immediately.
|
if m.items[nonce] == nil {
|
||||||
if m.items[nonce] != nil {
|
heap.Push(m.index, nonce)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m.items[nonce] = tx
|
m.items[nonce] = tx
|
||||||
heap.Push(m.index, nonce)
|
|
||||||
|
|
||||||
m.cacheMu.Lock()
|
m.cacheMu.Lock()
|
||||||
if m.cache != nil {
|
if m.cache != nil {
|
||||||
m.cache = append(m.cache, tx)
|
index := slices.IndexFunc(m.cache, func(tx *types.Transaction) bool {
|
||||||
sort.Sort(types.TxByNonce(m.cache))
|
return tx.Nonce() == nonce
|
||||||
|
})
|
||||||
|
m.cache[index] = tx
|
||||||
}
|
}
|
||||||
m.cacheMu.Unlock()
|
m.cacheMu.Unlock()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue