Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core/txpool/blobpool: improve newPriceHeap function #30050

Merged
merged 6 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions core/txpool/blobpool/evictheap.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
package blobpool

import (
"bytes"
"container/heap"
"math"
"sort"
"slices"

"github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256"
"golang.org/x/exp/maps"
)

// evictHeap is a helper data structure to keep track of the cheapest bottleneck
Expand All @@ -49,20 +49,15 @@ type evictHeap struct {
func newPriceHeap(basefee *uint256.Int, blobfee *uint256.Int, index map[common.Address][]*blobTxMeta) *evictHeap {
heap := &evictHeap{
metas: index,
index: make(map[common.Address]int),
index: make(map[common.Address]int, len(index)),
}
// Populate the heap in account sort order. Not really needed in practice,
// but it makes the heap initialization deterministic and less annoying to
// test in unit tests.
addrs := make([]common.Address, 0, len(index))
for addr := range index {
addrs = append(addrs, addr)
}
sort.Slice(addrs, func(i, j int) bool { return bytes.Compare(addrs[i][:], addrs[j][:]) < 0 })

for _, addr := range addrs {
heap.index[addr] = len(heap.addrs)
heap.addrs = append(heap.addrs, addr)
heap.addrs = maps.Keys(index)
slices.SortFunc(heap.addrs, common.Address.Cmp)
for i, addr := range heap.addrs {
heap.index[addr] = i
}
heap.reinit(basefee, blobfee, true)
return heap
Expand Down