upgrade newPriceHeap

This commit is contained in:
maskpp 2024-06-22 19:41:44 +08:00
parent 00675c5876
commit e1be14f99c

View file

@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/holiman/uint256" "github.com/holiman/uint256"
"golang.org/x/exp/maps"
) )
// evictHeap is a helper data structure to keep track of the cheapest bottleneck // evictHeap is a helper data structure to keep track of the cheapest bottleneck
@ -49,20 +50,17 @@ type evictHeap struct {
func newPriceHeap(basefee *uint256.Int, blobfee *uint256.Int, index *map[common.Address][]*blobTxMeta) *evictHeap { func newPriceHeap(basefee *uint256.Int, blobfee *uint256.Int, index *map[common.Address][]*blobTxMeta) *evictHeap {
heap := &evictHeap{ heap := &evictHeap{
metas: index, 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, // Populate the heap in account sort order. Not really needed in practice,
// but it makes the heap initialization deterministic and less annoying to // but it makes the heap initialization deterministic and less annoying to
// test in unit tests. // test in unit tests.
addrs := make([]common.Address, 0, len(*index)) addrs := maps.Keys(*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 }) sort.Slice(addrs, func(i, j int) bool { return bytes.Compare(addrs[i][:], addrs[j][:]) < 0 })
heap.addrs = addrs
for _, addr := range addrs { for _, addr := range addrs {
heap.index[addr] = len(heap.addrs) heap.index[addr] = len(heap.addrs)
heap.addrs = append(heap.addrs, addr)
} }
heap.reinit(basefee, blobfee, true) heap.reinit(basefee, blobfee, true)
return heap return heap