mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
cmd/workload: fix everything up. rework the code so that the test generators build.
This commit is contained in:
parent
72a6e23dfa
commit
2bb9862661
5 changed files with 58 additions and 32 deletions
|
|
@ -108,7 +108,7 @@ func (s *filterTestSuite) filterFullRange(t *utesting.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *filterTestSuite) queryAndCheck(t *utesting.T, query *filterQuery) {
|
func (s *filterTestSuite) queryAndCheck(t *utesting.T, query *filterQuery) {
|
||||||
query.run(s.cfg)
|
query.run(s.cfg.client, s.cfg.historyPruneBlock)
|
||||||
if query.Err != nil {
|
if query.Err != nil {
|
||||||
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)
|
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)
|
||||||
return
|
return
|
||||||
|
|
@ -125,7 +125,7 @@ func (s *filterTestSuite) fullRangeQueryAndCheck(t *utesting.T, query *filterQue
|
||||||
Address: query.Address,
|
Address: query.Address,
|
||||||
Topics: query.Topics,
|
Topics: query.Topics,
|
||||||
}
|
}
|
||||||
frQuery.run(s.cfg)
|
frQuery.run(s.cfg.client, s.cfg.historyPruneBlock)
|
||||||
if frQuery.Err != nil {
|
if frQuery.Err != nil {
|
||||||
t.Errorf("Full range filter query failed (addresses: %v topics: %v error: %v)", frQuery.Address, frQuery.Topics, frQuery.Err)
|
t.Errorf("Full range filter query failed (addresses: %v topics: %v error: %v)", frQuery.Address, frQuery.Topics, frQuery.Err)
|
||||||
return
|
return
|
||||||
|
|
@ -197,23 +197,22 @@ func (fq *filterQuery) calculateHash() common.Hash {
|
||||||
return crypto.Keccak256Hash(enc)
|
return crypto.Keccak256Hash(enc)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fq *filterQuery) run(cfg testConfig) {
|
func (fq *filterQuery) run(client *client, historyPruneBlock *uint64) {
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
logs, err := cfg.client.Eth.FilterLogs(ctx, ethereum.FilterQuery{
|
logs, err := client.Eth.FilterLogs(ctx, ethereum.FilterQuery{
|
||||||
FromBlock: big.NewInt(fq.FromBlock),
|
FromBlock: big.NewInt(fq.FromBlock),
|
||||||
ToBlock: big.NewInt(fq.ToBlock),
|
ToBlock: big.NewInt(fq.ToBlock),
|
||||||
Addresses: fq.Address,
|
Addresses: fq.Address,
|
||||||
Topics: fq.Topics,
|
Topics: fq.Topics,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fq.Err = err
|
if err = validateHistoryPruneErr(fq.Err, uint64(fq.FromBlock), historyPruneBlock); err != nil {
|
||||||
err := validateHistoryPruneErr(fq.Err, uint64(fq.FromBlock), cfg)
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("Filter query failed: fromBlock: %d toBlock: %d addresses: %v topics: %v error: %v\n",
|
fmt.Printf("Filter query failed: fromBlock: %d toBlock: %d addresses: %v topics: %v error: %v\n",
|
||||||
fq.FromBlock, fq.ToBlock, fq.Address, fq.Topics, err)
|
fq.FromBlock, fq.ToBlock, fq.Address, fq.Topics, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
fq.Err = err
|
||||||
}
|
}
|
||||||
fq.results = logs
|
fq.results = logs
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func filterGenCmd(ctx *cli.Context) error {
|
||||||
|
|
||||||
f.updateFinalizedBlock()
|
f.updateFinalizedBlock()
|
||||||
query := f.newQuery()
|
query := f.newQuery()
|
||||||
query.run(f.client)
|
query.run(f.client, nil)
|
||||||
if query.Err != nil {
|
if query.Err != nil {
|
||||||
f.errors = append(f.errors, query)
|
f.errors = append(f.errors, query)
|
||||||
continue
|
continue
|
||||||
|
|
@ -81,7 +81,7 @@ func filterGenCmd(ctx *cli.Context) error {
|
||||||
if extQuery == nil {
|
if extQuery == nil {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
extQuery.run(f.client)
|
extQuery.run(f.client, nil)
|
||||||
if extQuery.Err == nil && len(extQuery.results) < len(query.results) {
|
if extQuery.Err == nil && len(extQuery.results) < len(query.results) {
|
||||||
extQuery.Err = fmt.Errorf("invalid result length; old range %d %d; old length %d; new range %d %d; new length %d; address %v; Topics %v",
|
extQuery.Err = fmt.Errorf("invalid result length; old range %d %d; old length %d; new range %d %d; new length %d; address %v; Topics %v",
|
||||||
query.FromBlock, query.ToBlock, len(query.results),
|
query.FromBlock, query.ToBlock, len(query.results),
|
||||||
|
|
|
||||||
|
|
@ -70,7 +70,7 @@ func filterPerfCmd(ctx *cli.Context) error {
|
||||||
queries[pick] = queries[len(queries)-1]
|
queries[pick] = queries[len(queries)-1]
|
||||||
queries = queries[:len(queries)-1]
|
queries = queries[:len(queries)-1]
|
||||||
start := time.Now()
|
start := time.Now()
|
||||||
qt.query.run(cfg.client)
|
qt.query.run(cfg.client, cfg.historyPruneBlock)
|
||||||
qt.runtime = append(qt.runtime, time.Since(start))
|
qt.runtime = append(qt.runtime, time.Since(start))
|
||||||
slices.Sort(qt.runtime)
|
slices.Sort(qt.runtime)
|
||||||
qt.medianTime = qt.runtime[len(qt.runtime)/2]
|
qt.medianTime = qt.runtime[len(qt.runtime)/2]
|
||||||
|
|
|
||||||
|
|
@ -108,8 +108,11 @@ func (s *historyTestSuite) testGetBlockByHash(t *utesting.T) {
|
||||||
for i, num := range s.tests.BlockNumbers {
|
for i, num := range s.tests.BlockNumbers {
|
||||||
bhash := s.tests.BlockHashes[i]
|
bhash := s.tests.BlockHashes[i]
|
||||||
b, err := s.cfg.client.getBlockByHash(ctx, bhash, false)
|
b, err := s.cfg.client.getBlockByHash(ctx, bhash, false)
|
||||||
if err = validateHistoryPruneErr(err, num, s.cfg); err != nil {
|
if err = validateHistoryPruneErr(err, num, s.cfg.historyPruneBlock); err == errPrunedHistory {
|
||||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("block %d (hash %v): error %v", num, bhash, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if b == nil {
|
if b == nil {
|
||||||
t.Errorf("block %d (hash %v): not found", num, bhash)
|
t.Errorf("block %d (hash %v): not found", num, bhash)
|
||||||
|
|
@ -127,8 +130,11 @@ func (s *historyTestSuite) testGetBlockByNumber(t *utesting.T) {
|
||||||
for i, num := range s.tests.BlockNumbers {
|
for i, num := range s.tests.BlockNumbers {
|
||||||
bhash := s.tests.BlockHashes[i]
|
bhash := s.tests.BlockHashes[i]
|
||||||
b, err := s.cfg.client.getBlockByNumber(ctx, num, false)
|
b, err := s.cfg.client.getBlockByNumber(ctx, num, false)
|
||||||
if err = validateHistoryPruneErr(err, num, s.cfg); err != nil {
|
if err = validateHistoryPruneErr(err, num, s.cfg.historyPruneBlock); err == errPrunedHistory {
|
||||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("block %d (hash %v): error %v", num, bhash, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if b == nil {
|
if b == nil {
|
||||||
t.Errorf("block %d (hash %v): not found", num, bhash)
|
t.Errorf("block %d (hash %v): not found", num, bhash)
|
||||||
|
|
@ -146,8 +152,11 @@ func (s *historyTestSuite) testGetBlockTransactionCountByHash(t *utesting.T) {
|
||||||
for i, num := range s.tests.BlockNumbers {
|
for i, num := range s.tests.BlockNumbers {
|
||||||
bhash := s.tests.BlockHashes[i]
|
bhash := s.tests.BlockHashes[i]
|
||||||
count, err := s.cfg.client.getBlockTransactionCountByHash(ctx, bhash)
|
count, err := s.cfg.client.getBlockTransactionCountByHash(ctx, bhash)
|
||||||
if err = validateHistoryPruneErr(err, num, s.cfg); err != nil {
|
if err = validateHistoryPruneErr(err, num, s.cfg.historyPruneBlock); err == errPrunedHistory {
|
||||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("block %d (hash %v): error %v", num, bhash, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
expectedCount := uint64(s.tests.TxCounts[i])
|
expectedCount := uint64(s.tests.TxCounts[i])
|
||||||
if count != expectedCount {
|
if count != expectedCount {
|
||||||
|
|
@ -162,8 +171,11 @@ func (s *historyTestSuite) testGetBlockTransactionCountByNumber(t *utesting.T) {
|
||||||
for i, num := range s.tests.BlockNumbers {
|
for i, num := range s.tests.BlockNumbers {
|
||||||
bhash := s.tests.BlockHashes[i]
|
bhash := s.tests.BlockHashes[i]
|
||||||
count, err := s.cfg.client.getBlockTransactionCountByNumber(ctx, num)
|
count, err := s.cfg.client.getBlockTransactionCountByNumber(ctx, num)
|
||||||
if err = validateHistoryPruneErr(err, num, s.cfg); err != nil {
|
if err = validateHistoryPruneErr(err, num, s.cfg.historyPruneBlock); err == errPrunedHistory {
|
||||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("block %d (hash %v): error %v", num, bhash, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
expectedCount := uint64(s.tests.TxCounts[i])
|
expectedCount := uint64(s.tests.TxCounts[i])
|
||||||
if count != expectedCount {
|
if count != expectedCount {
|
||||||
|
|
@ -178,8 +190,11 @@ func (s *historyTestSuite) testGetBlockReceiptsByHash(t *utesting.T) {
|
||||||
for i, num := range s.tests.BlockNumbers {
|
for i, num := range s.tests.BlockNumbers {
|
||||||
bhash := s.tests.BlockHashes[i]
|
bhash := s.tests.BlockHashes[i]
|
||||||
receipts, err := s.cfg.client.getBlockReceipts(ctx, bhash)
|
receipts, err := s.cfg.client.getBlockReceipts(ctx, bhash)
|
||||||
if err = validateHistoryPruneErr(err, num, s.cfg); err != nil {
|
if err = validateHistoryPruneErr(err, num, s.cfg.historyPruneBlock); err == errPrunedHistory {
|
||||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("block %d (hash %v): error %v", num, bhash, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
hash := calcReceiptsHash(receipts)
|
hash := calcReceiptsHash(receipts)
|
||||||
expectedHash := s.tests.ReceiptsHashes[i]
|
expectedHash := s.tests.ReceiptsHashes[i]
|
||||||
|
|
@ -195,8 +210,11 @@ func (s *historyTestSuite) testGetBlockReceiptsByNumber(t *utesting.T) {
|
||||||
for i, num := range s.tests.BlockNumbers {
|
for i, num := range s.tests.BlockNumbers {
|
||||||
bhash := s.tests.BlockHashes[i]
|
bhash := s.tests.BlockHashes[i]
|
||||||
receipts, err := s.cfg.client.getBlockReceipts(ctx, hexutil.Uint64(num))
|
receipts, err := s.cfg.client.getBlockReceipts(ctx, hexutil.Uint64(num))
|
||||||
if err = validateHistoryPruneErr(err, num, s.cfg); err != nil {
|
if err = validateHistoryPruneErr(err, num, s.cfg.historyPruneBlock); err == errPrunedHistory {
|
||||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("block %d (hash %v): error %v", num, bhash, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
hash := calcReceiptsHash(receipts)
|
hash := calcReceiptsHash(receipts)
|
||||||
expectedHash := s.tests.ReceiptsHashes[i]
|
expectedHash := s.tests.ReceiptsHashes[i]
|
||||||
|
|
@ -218,8 +236,11 @@ func (s *historyTestSuite) testGetTransactionByBlockHashAndIndex(t *utesting.T)
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := s.cfg.client.getTransactionByBlockHashAndIndex(ctx, bhash, uint64(txIndex))
|
tx, err := s.cfg.client.getTransactionByBlockHashAndIndex(ctx, bhash, uint64(txIndex))
|
||||||
if err = validateHistoryPruneErr(err, num, s.cfg); err != nil {
|
if err = validateHistoryPruneErr(err, num, s.cfg.historyPruneBlock); err == errPrunedHistory {
|
||||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("block %d (hash %v): error %v", num, bhash, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
t.Errorf("block %d (hash %v): txIndex %d not found", num, bhash, txIndex)
|
t.Errorf("block %d (hash %v): txIndex %d not found", num, bhash, txIndex)
|
||||||
|
|
@ -243,8 +264,11 @@ func (s *historyTestSuite) testGetTransactionByBlockNumberAndIndex(t *utesting.T
|
||||||
}
|
}
|
||||||
|
|
||||||
tx, err := s.cfg.client.getTransactionByBlockNumberAndIndex(ctx, num, uint64(txIndex))
|
tx, err := s.cfg.client.getTransactionByBlockNumberAndIndex(ctx, num, uint64(txIndex))
|
||||||
if err = validateHistoryPruneErr(err, num, s.cfg); err != nil {
|
if err = validateHistoryPruneErr(err, num, s.cfg.historyPruneBlock); err == errPrunedHistory {
|
||||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
continue
|
||||||
|
} else if err != nil {
|
||||||
|
t.Errorf("block %d (hash %v): error %v", num, bhash, err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
if tx == nil {
|
if tx == nil {
|
||||||
t.Errorf("block %d (hash %v): txIndex %d not found", num, bhash, txIndex)
|
t.Errorf("block %d (hash %v): txIndex %d not found", num, bhash, txIndex)
|
||||||
|
|
|
||||||
|
|
@ -88,18 +88,21 @@ type testConfig struct {
|
||||||
historyPruneBlock *uint64
|
historyPruneBlock *uint64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var errPrunedHistory = fmt.Errorf("attempt to access pruned history")
|
||||||
|
|
||||||
// validateHistoryPruneErr checks whether the given error is caused by access
|
// validateHistoryPruneErr checks whether the given error is caused by access
|
||||||
// to history before the pruning threshold block (it is an rpc.Error with code 4444).
|
// to history before the pruning threshold block (it is an rpc.Error with code 4444).
|
||||||
// If the error is of a different type, it is returned. If the error is a pruned
|
// In this case, errPrunedHistory is returned.
|
||||||
// history error occurring past the pruning threshold, an error is returned.
|
// If the error is a pruned history error that occurs when accessing a block past the
|
||||||
// Otherwise, nil is returned.
|
// historyPrune block, an error is returned.
|
||||||
func validateHistoryPruneErr(err error, blockNum uint64, cfg testConfig) error {
|
// Otherwise, the original value of err is returned.
|
||||||
|
func validateHistoryPruneErr(err error, blockNum uint64, historyPruneBlock *uint64) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == 4444 {
|
if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == 4444 {
|
||||||
if cfg.historyPruneBlock != nil && blockNum > *cfg.historyPruneBlock {
|
if historyPruneBlock != nil && blockNum > *historyPruneBlock {
|
||||||
return fmt.Errorf("pruned history error returned after pruning threshold")
|
return fmt.Errorf("pruned history error returned after pruning threshold")
|
||||||
}
|
}
|
||||||
return nil
|
return errPrunedHistory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue