Skip to content

Commit 21b58df

Browse files
authored
test(evm): use typed sorting for trace totals (#3438)
Signed-off-by: alaningtrump <alaningtrump@outlook.com>
1 parent 22417ad commit 21b58df

2 files changed

Lines changed: 10 additions & 9 deletions

File tree

‎pkg/store/store_adapter.go‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -445,13 +445,13 @@ func (a *StoreAdapter[H]) Get(ctx context.Context, hash header.Hash) (H, error)
445445
// First try the store
446446
item, err := a.getter.GetByHash(ctx, hash)
447447
if err == nil {
448-
a.applyDAHint(item)
448+
a.applyDAHint(ctx, item)
449449
return item, nil
450450
}
451451

452452
// Check pending items using hash index for O(1) lookup
453453
if pendingItem, ok := a.pending.getByHash(hash); ok {
454-
a.applyDAHint(pendingItem)
454+
a.applyDAHint(ctx, pendingItem)
455455
return pendingItem, nil
456456
}
457457

@@ -485,21 +485,21 @@ func (a *StoreAdapter[H]) getByHeightNoWait(ctx context.Context, height uint64)
485485
// First try the store
486486
item, err := a.getter.GetByHeight(ctx, height)
487487
if err == nil {
488-
a.applyDAHint(item)
488+
a.applyDAHint(ctx, item)
489489
return item, nil
490490
}
491491

492492
// Check pending items
493493
if pendingItem, ok := a.pending.get(height); ok {
494-
a.applyDAHint(pendingItem)
494+
a.applyDAHint(ctx, pendingItem)
495495
return pendingItem, nil
496496
}
497497

498498
return zero, header.ErrNotFound
499499
}
500500

501501
// applyDAHint sets the DA hint on the item from cache or disk.
502-
func (a *StoreAdapter[H]) applyDAHint(item H) {
502+
func (a *StoreAdapter[H]) applyDAHint(ctx context.Context, item H) {
503503
if item.IsZero() {
504504
return
505505
}
@@ -513,7 +513,7 @@ func (a *StoreAdapter[H]) applyDAHint(item H) {
513513
}
514514

515515
// Try to load from disk
516-
if diskHint, err := a.getter.GetDAHint(context.Background(), height); err == nil && diskHint > 0 {
516+
if diskHint, err := a.getter.GetDAHint(ctx, height); err == nil && diskHint > 0 {
517517
a.pending.setDAHint(height, diskHint)
518518
item.SetDAHint(diskHint)
519519
}

‎test/e2e/evm_test_common.go‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
package e2e
1616

1717
import (
18+
"cmp"
1819
"context"
1920
"flag"
2021
"fmt"
@@ -23,7 +24,7 @@ import (
2324
"os"
2425
"path/filepath"
2526
"regexp"
26-
"sort"
27+
"slices"
2728
"strconv"
2829
"strings"
2930
"testing"
@@ -904,8 +905,8 @@ func PrintTraceReport(t testing.TB, label string, spans []TraceSpan) {
904905
for name := range m {
905906
names = append(names, name)
906907
}
907-
sort.Slice(names, func(i, j int) bool {
908-
return m[names[i]].Total > m[names[j]].Total
908+
slices.SortFunc(names, func(a, b string) int {
909+
return cmp.Compare(m[b].Total, m[a].Total)
909910
})
910911

911912
var overallTotal time.Duration

0 commit comments

Comments
 (0)