Skip to content

Commit 14e79cc

Browse files
zsfelfoldihowjmay
authored andcommitted
cmd/workload: fixed filter test request error handling (ethereum#31424)
This PR fixes the broken request error handling of the workload filter tests. Until now `validateHistoryPruneErr` was invoked with `fq.Err` as an input which was always nil and a timeout or http error was reported as a result content mismatch. Also, in case of `errPrunedHistory` it is wrong to return here without setting an error because then it will look like a valid empty result and the check will later fail. So instead `errPrunedHistory` is always returned now (without printing an error message) and the callers of `run` should handle this special case (typically ignore silently).
1 parent 93ccb43 commit 14e79cc

File tree

3 files changed

+49
-35
lines changed

3 files changed

+49
-35
lines changed

cmd/workload/filtertest.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ func (s *filterTestSuite) filterFullRange(t *utesting.T) {
109109

110110
func (s *filterTestSuite) queryAndCheck(t *utesting.T, query *filterQuery) {
111111
query.run(s.cfg.client, s.cfg.historyPruneBlock)
112+
if query.Err == errPrunedHistory {
113+
return
114+
}
112115
if query.Err != nil {
113116
t.Errorf("Filter query failed (fromBlock: %d toBlock: %d addresses: %v topics: %v error: %v)", query.FromBlock, query.ToBlock, query.Address, query.Topics, query.Err)
114117
return
@@ -126,6 +129,9 @@ func (s *filterTestSuite) fullRangeQueryAndCheck(t *utesting.T, query *filterQue
126129
Topics: query.Topics,
127130
}
128131
frQuery.run(s.cfg.client, s.cfg.historyPruneBlock)
132+
if frQuery.Err == errPrunedHistory {
133+
return
134+
}
129135
if frQuery.Err != nil {
130136
t.Errorf("Full range filter query failed (addresses: %v topics: %v error: %v)", frQuery.Address, frQuery.Topics, frQuery.Err)
131137
return
@@ -206,14 +212,11 @@ func (fq *filterQuery) run(client *client, historyPruneBlock *uint64) {
206212
Addresses: fq.Address,
207213
Topics: fq.Topics,
208214
})
209-
if err != nil {
210-
if err = validateHistoryPruneErr(fq.Err, uint64(fq.FromBlock), historyPruneBlock); err == errPrunedHistory {
211-
return
212-
} else if err != nil {
213-
fmt.Printf("Filter query failed: fromBlock: %d toBlock: %d addresses: %v topics: %v error: %v\n",
214-
fq.FromBlock, fq.ToBlock, fq.Address, fq.Topics, err)
215-
}
216-
fq.Err = err
217-
}
218215
fq.results = logs
216+
fq.Err = validateHistoryPruneErr(err, uint64(fq.FromBlock), historyPruneBlock)
217+
}
218+
219+
func (fq *filterQuery) printError() {
220+
fmt.Printf("Filter query failed: fromBlock: %d toBlock: %d addresses: %v topics: %v error: %v\n",
221+
fq.FromBlock, fq.ToBlock, fq.Address, fq.Topics, fq.Err)
219222
}

cmd/workload/filtertestgen.go

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ var (
4040
Action: filterGenCmd,
4141
Flags: []cli.Flag{
4242
filterQueryFileFlag,
43-
filterErrorFileFlag,
4443
},
4544
}
4645
filterQueryFileFlag = &cli.StringFlag{
@@ -72,8 +71,8 @@ func filterGenCmd(ctx *cli.Context) error {
7271
query := f.newQuery()
7372
query.run(f.client, nil)
7473
if query.Err != nil {
75-
f.errors = append(f.errors, query)
76-
continue
74+
query.printError()
75+
exit("filter query failed")
7776
}
7877
if len(query.results) > 0 && len(query.results) <= maxFilterResultSize {
7978
for {
@@ -90,8 +89,8 @@ func filterGenCmd(ctx *cli.Context) error {
9089
)
9190
}
9291
if extQuery.Err != nil {
93-
f.errors = append(f.errors, extQuery)
94-
break
92+
extQuery.printError()
93+
exit("filter query failed")
9594
}
9695
if len(extQuery.results) > maxFilterResultSize {
9796
break
@@ -101,7 +100,6 @@ func filterGenCmd(ctx *cli.Context) error {
101100
f.storeQuery(query)
102101
if time.Since(lastWrite) > time.Second*10 {
103102
f.writeQueries()
104-
f.writeErrors()
105103
lastWrite = time.Now()
106104
}
107105
}
@@ -112,18 +110,15 @@ func filterGenCmd(ctx *cli.Context) error {
112110
type filterTestGen struct {
113111
client *client
114112
queryFile string
115-
errorFile string
116113

117114
finalizedBlock int64
118115
queries [filterBuckets][]*filterQuery
119-
errors []*filterQuery
120116
}
121117

122118
func newFilterTestGen(ctx *cli.Context) *filterTestGen {
123119
return &filterTestGen{
124120
client: makeClient(ctx),
125121
queryFile: ctx.String(filterQueryFileFlag.Name),
126-
errorFile: ctx.String(filterErrorFileFlag.Name),
127122
}
128123
}
129124

@@ -360,17 +355,6 @@ func (s *filterTestGen) writeQueries() {
360355
file.Close()
361356
}
362357

363-
// writeQueries serializes the generated errors to the error file.
364-
func (s *filterTestGen) writeErrors() {
365-
file, err := os.Create(s.errorFile)
366-
if err != nil {
367-
exit(fmt.Errorf("Error creating filter error file %s: %v", s.errorFile, err))
368-
return
369-
}
370-
defer file.Close()
371-
json.NewEncoder(file).Encode(s.errors)
372-
}
373-
374358
func mustGetFinalizedBlock(client *client) int64 {
375359
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
376360
defer cancel()

cmd/workload/filtertestperf.go

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
package main
1818

1919
import (
20+
"encoding/json"
2021
"fmt"
2122
"math/rand"
23+
"os"
2224
"slices"
2325
"sort"
2426
"time"
@@ -41,7 +43,7 @@ var (
4143
}
4244
)
4345

44-
const passCount = 1
46+
const passCount = 3
4547

4648
func filterPerfCmd(ctx *cli.Context) error {
4749
cfg := testConfigFromCLI(ctx)
@@ -61,7 +63,10 @@ func filterPerfCmd(ctx *cli.Context) error {
6163
}
6264

6365
// Run test queries.
64-
var failed, mismatch int
66+
var (
67+
failed, pruned, mismatch int
68+
errors []*filterQuery
69+
)
6570
for i := 1; i <= passCount; i++ {
6671
fmt.Println("Performance test pass", i, "/", passCount)
6772
for len(queries) > 0 {
@@ -71,27 +76,35 @@ func filterPerfCmd(ctx *cli.Context) error {
7176
queries = queries[:len(queries)-1]
7277
start := time.Now()
7378
qt.query.run(cfg.client, cfg.historyPruneBlock)
79+
if qt.query.Err == errPrunedHistory {
80+
pruned++
81+
continue
82+
}
7483
qt.runtime = append(qt.runtime, time.Since(start))
7584
slices.Sort(qt.runtime)
7685
qt.medianTime = qt.runtime[len(qt.runtime)/2]
7786
if qt.query.Err != nil {
87+
qt.query.printError()
88+
errors = append(errors, qt.query)
7889
failed++
7990
continue
8091
}
8192
if rhash := qt.query.calculateHash(); *qt.query.ResultHash != rhash {
8293
fmt.Printf("Filter query result mismatch: fromBlock: %d toBlock: %d addresses: %v topics: %v expected hash: %064x calculated hash: %064x\n", qt.query.FromBlock, qt.query.ToBlock, qt.query.Address, qt.query.Topics, *qt.query.ResultHash, rhash)
94+
errors = append(errors, qt.query)
95+
mismatch++
8396
continue
8497
}
8598
processed = append(processed, qt)
8699
if len(processed)%50 == 0 {
87-
fmt.Println(" processed:", len(processed), "remaining", len(queries), "failed:", failed, "result mismatch:", mismatch)
100+
fmt.Println(" processed:", len(processed), "remaining", len(queries), "failed:", failed, "pruned:", pruned, "result mismatch:", mismatch)
88101
}
89102
}
90103
queries, processed = processed, nil
91104
}
92105

93106
// Show results and stats.
94-
fmt.Println("Performance test finished; processed:", len(queries), "failed:", failed, "result mismatch:", mismatch)
107+
fmt.Println("Performance test finished; processed:", len(queries), "failed:", failed, "pruned:", pruned, "result mismatch:", mismatch)
95108
stats := make([]bucketStats, len(f.queries))
96109
var wildcardStats bucketStats
97110
for _, qt := range queries {
@@ -114,11 +127,14 @@ func filterPerfCmd(ctx *cli.Context) error {
114127
sort.Slice(queries, func(i, j int) bool {
115128
return queries[i].medianTime > queries[j].medianTime
116129
})
117-
for i := 0; i < 10; i++ {
118-
q := queries[i]
130+
for i, q := range queries {
131+
if i >= 10 {
132+
break
133+
}
119134
fmt.Printf("Most expensive query #%-2d median runtime: %13v max runtime: %13v result count: %4d fromBlock: %9d toBlock: %9d addresses: %v topics: %v\n",
120135
i+1, q.medianTime, q.runtime[len(q.runtime)-1], len(q.query.results), q.query.FromBlock, q.query.ToBlock, q.query.Address, q.query.Topics)
121136
}
137+
writeErrors(ctx.String(filterErrorFileFlag.Name), errors)
122138
return nil
123139
}
124140

@@ -135,3 +151,14 @@ func (st *bucketStats) print(name string) {
135151
fmt.Printf("%-20s queries: %4d average block length: %12.2f average log count: %7.2f average runtime: %13v\n",
136152
name, st.count, float64(st.blocks)/float64(st.count), float64(st.logs)/float64(st.count), st.runtime/time.Duration(st.count))
137153
}
154+
155+
// writeQueries serializes the generated errors to the error file.
156+
func writeErrors(errorFile string, errors []*filterQuery) {
157+
file, err := os.Create(errorFile)
158+
if err != nil {
159+
exit(fmt.Errorf("Error creating filter error file %s: %v", errorFile, err))
160+
return
161+
}
162+
defer file.Close()
163+
json.NewEncoder(file).Encode(errors)
164+
}

0 commit comments

Comments
 (0)