From e1be14f99c7ac89d3fa6900910df872762f1f8de Mon Sep 17 00:00:00 2001 From: maskpp Date: Sat, 22 Jun 2024 19:41:44 +0800 Subject: [PATCH] upgrade newPriceHeap --- core/txpool/blobpool/evictheap.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/core/txpool/blobpool/evictheap.go b/core/txpool/blobpool/evictheap.go index bc4543a352..84cc1dfbea 100644 --- a/core/txpool/blobpool/evictheap.go +++ b/core/txpool/blobpool/evictheap.go @@ -24,6 +24,7 @@ import ( "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 @@ -49,20 +50,17 @@ 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) - } + addrs := maps.Keys(*index) sort.Slice(addrs, func(i, j int) bool { return bytes.Compare(addrs[i][:], addrs[j][:]) < 0 }) + heap.addrs = addrs for _, addr := range addrs { heap.index[addr] = len(heap.addrs) - heap.addrs = append(heap.addrs, addr) } heap.reinit(basefee, blobfee, true) return heap