From e1be14f99c7ac89d3fa6900910df872762f1f8de Mon Sep 17 00:00:00 2001 From: maskpp Date: Sat, 22 Jun 2024 19:41:44 +0800 Subject: [PATCH 1/5] 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 bc4543a352e2..84cc1dfbea47 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 From a4b7a65ac938dce0e42ca62ce929abcfa917481d Mon Sep 17 00:00:00 2001 From: maskpp Date: Sat, 22 Jun 2024 19:45:57 +0800 Subject: [PATCH 2/5] upgrade newPriceHeap --- core/txpool/blobpool/evictheap.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/txpool/blobpool/evictheap.go b/core/txpool/blobpool/evictheap.go index 84cc1dfbea47..74d3d9d3dc84 100644 --- a/core/txpool/blobpool/evictheap.go +++ b/core/txpool/blobpool/evictheap.go @@ -59,8 +59,8 @@ func newPriceHeap(basefee *uint256.Int, blobfee *uint256.Int, index *map[common. 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) + for i, addr := range addrs { + heap.index[addr] = i } heap.reinit(basefee, blobfee, true) return heap From 1b2082942a7a71ebbf43505b423b0acacff08aea Mon Sep 17 00:00:00 2001 From: maskpp Date: Tue, 25 Jun 2024 20:45:41 +0800 Subject: [PATCH 3/5] change to use slices.SortFunc --- core/txpool/blobpool/evictheap.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/core/txpool/blobpool/evictheap.go b/core/txpool/blobpool/evictheap.go index 74d3d9d3dc84..6ac3261c631c 100644 --- a/core/txpool/blobpool/evictheap.go +++ b/core/txpool/blobpool/evictheap.go @@ -17,10 +17,9 @@ package blobpool import ( - "bytes" "container/heap" "math" - "sort" + "slices" "github.com/ethereum/go-ethereum/common" "github.com/holiman/uint256" @@ -56,7 +55,7 @@ func newPriceHeap(basefee *uint256.Int, blobfee *uint256.Int, index *map[common. // but it makes the heap initialization deterministic and less annoying to // test in unit tests. addrs := maps.Keys(*index) - sort.Slice(addrs, func(i, j int) bool { return bytes.Compare(addrs[i][:], addrs[j][:]) < 0 }) + slices.SortFunc(addrs, common.Address.Cmp) heap.addrs = addrs for i, addr := range addrs { From b5e6a5847fd31eecca15ce320acd6de5ccfde40b Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 28 Jun 2024 13:18:28 +0200 Subject: [PATCH 4/5] Update evictheap.go --- 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 ed023dcae3f4..582bfc9c1af7 100644 --- a/core/txpool/blobpool/evictheap.go +++ b/core/txpool/blobpool/evictheap.go @@ -49,16 +49,14 @@ 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, len(*index)), + 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 := maps.Keys(*index) - slices.SortFunc(addrs, common.Address.Cmp) - - heap.addrs = addrs - for i, addr := range addrs { + heap.addrs = maps.Keys(index) + slices.SortFunc(heap.addrs, common.Address.Cmp) + for i, addr := range heap.index { heap.index[addr] = i } heap.reinit(basefee, blobfee, true) From 7b32d5364c496969ba6b5eda14ddad2c77e76055 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Fri, 28 Jun 2024 13:36:20 +0200 Subject: [PATCH 5/5] Update evictheap.go --- core/txpool/blobpool/evictheap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/txpool/blobpool/evictheap.go b/core/txpool/blobpool/evictheap.go index 582bfc9c1af7..5e285e6c534e 100644 --- a/core/txpool/blobpool/evictheap.go +++ b/core/txpool/blobpool/evictheap.go @@ -56,7 +56,7 @@ func newPriceHeap(basefee *uint256.Int, blobfee *uint256.Int, index map[common.A // test in unit tests. heap.addrs = maps.Keys(index) slices.SortFunc(heap.addrs, common.Address.Cmp) - for i, addr := range heap.index { + for i, addr := range heap.addrs { heap.index[addr] = i } heap.reinit(basefee, blobfee, true)