fix comments

This commit is contained in:
maskpp 2025-07-30 11:26:59 +08:00
parent 640d0079d5
commit 90f83f4b37

View file

@ -114,7 +114,12 @@ func (m *SortedMap) Forward(threshold uint64) types.Transactions {
// If you want to do several consecutive filterings, it's therefore better to first // If you want to do several consecutive filterings, it's therefore better to first
// do a .filter(func1) followed by .Filter(func2) or reheap() // do a .filter(func1) followed by .Filter(func2) or reheap()
func (m *SortedMap) Filter(filter func(*types.Transaction) bool) types.Transactions { func (m *SortedMap) Filter(filter func(*types.Transaction) bool) types.Transactions {
return m.filter(filter) removed := m.filter(filter)
// If transactions were removed, the heap and cache are ruined
if len(removed) > 0 {
m.reheap()
}
return removed
} }
func (m *SortedMap) reheap() { func (m *SortedMap) reheap() {
@ -138,8 +143,6 @@ func (m *SortedMap) filter(filter func(*types.Transaction) bool) types.Transacti
m.cacheMu.Lock() m.cacheMu.Lock()
m.cache = nil m.cache = nil
m.cacheMu.Unlock() m.cacheMu.Unlock()
// If transactions were removed, the heap and cache are ruined
m.reheap()
} }
return removed return removed
} }
@ -353,7 +356,7 @@ func (l *list) Filter(costLimit *uint256.Int, gasLimit uint64) (types.Transactio
if l.costcap.Cmp(costLimit) <= 0 && l.gascap <= gasLimit { if l.costcap.Cmp(costLimit) <= 0 && l.gascap <= gasLimit {
return nil, nil return nil, nil
} }
l.costcap.Set(costLimit) // Lower the caps to the thresholds l.costcap = new(uint256.Int).Set(costLimit) // Lower the caps to the thresholds
l.gascap = gasLimit l.gascap = gasLimit
// Filter out all the transactions above the account's funds // Filter out all the transactions above the account's funds
@ -378,6 +381,7 @@ func (l *list) Filter(costLimit *uint256.Int, gasLimit uint64) (types.Transactio
// Reset total cost // Reset total cost
l.subTotalCost(removed) l.subTotalCost(removed)
l.subTotalCost(invalids) l.subTotalCost(invalids)
l.txs.reheap()
return removed, invalids return removed, invalids
} }