mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 15:16:43 +00:00
cmd/workload: check if history prune error is returned beyond the pruning threshold. if so, it is an error
This commit is contained in:
parent
04ca215ddd
commit
a73100200a
3 changed files with 59 additions and 38 deletions
|
|
@ -108,11 +108,9 @@ func (s *filterTestSuite) filterFullRange(t *utesting.T) {
|
|||
}
|
||||
|
||||
func (s *filterTestSuite) queryAndCheck(t *utesting.T, query *filterQuery) {
|
||||
query.run(s.cfg.client)
|
||||
query.run(s.cfg)
|
||||
if query.Err != nil {
|
||||
if !errIsPrunedHistory(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)
|
||||
}
|
||||
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
|
||||
}
|
||||
if *query.ResultHash != query.calculateHash() {
|
||||
|
|
@ -127,11 +125,9 @@ func (s *filterTestSuite) fullRangeQueryAndCheck(t *utesting.T, query *filterQue
|
|||
Address: query.Address,
|
||||
Topics: query.Topics,
|
||||
}
|
||||
frQuery.run(s.cfg.client)
|
||||
frQuery.run(s.cfg)
|
||||
if frQuery.Err != nil {
|
||||
if !errIsPrunedHistory(frQuery.Err) {
|
||||
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
|
||||
}
|
||||
// filter out results outside the original query range
|
||||
|
|
@ -201,10 +197,10 @@ func (fq *filterQuery) calculateHash() common.Hash {
|
|||
return crypto.Keccak256Hash(enc)
|
||||
}
|
||||
|
||||
func (fq *filterQuery) run(client *client) {
|
||||
func (fq *filterQuery) run(cfg testConfig) {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
|
||||
defer cancel()
|
||||
logs, err := client.Eth.FilterLogs(ctx, ethereum.FilterQuery{
|
||||
logs, err := cfg.client.Eth.FilterLogs(ctx, ethereum.FilterQuery{
|
||||
FromBlock: big.NewInt(fq.FromBlock),
|
||||
ToBlock: big.NewInt(fq.ToBlock),
|
||||
Addresses: fq.Address,
|
||||
|
|
@ -212,12 +208,12 @@ func (fq *filterQuery) run(client *client) {
|
|||
})
|
||||
if err != nil {
|
||||
fq.Err = err
|
||||
if errIsPrunedHistory(err) {
|
||||
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",
|
||||
fq.FromBlock, fq.ToBlock, fq.Address, fq.Topics, err)
|
||||
return
|
||||
}
|
||||
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)
|
||||
return
|
||||
}
|
||||
fq.results = logs
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/internal/utesting"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
// historyTest is the content of a history test.
|
||||
|
|
@ -43,17 +42,6 @@ type historyTestSuite struct {
|
|||
tests historyTest
|
||||
}
|
||||
|
||||
// errIsPrunedHistory returns true if an error is an rpc.Error with an error
|
||||
// code of 4444.
|
||||
func errIsPrunedHistory(err error) bool {
|
||||
if err != nil {
|
||||
if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == 4444 {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func newHistoryTestSuite(cfg testConfig) *historyTestSuite {
|
||||
s := &historyTestSuite{cfg: cfg}
|
||||
if err := s.loadTests(); err != nil {
|
||||
|
|
@ -121,7 +109,8 @@ func (s *historyTestSuite) testGetBlockByHash(t *utesting.T) {
|
|||
bhash := s.tests.BlockHashes[i]
|
||||
b, err := s.cfg.client.getBlockByHash(ctx, bhash, false)
|
||||
if err != nil {
|
||||
if errIsPrunedHistory(err) {
|
||||
err = validateHistoryPruneErr(err, num, s.cfg)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
||||
|
|
@ -143,7 +132,8 @@ func (s *historyTestSuite) testGetBlockByNumber(t *utesting.T) {
|
|||
bhash := s.tests.BlockHashes[i]
|
||||
b, err := s.cfg.client.getBlockByNumber(ctx, num, false)
|
||||
if err != nil {
|
||||
if errIsPrunedHistory(err) {
|
||||
err = validateHistoryPruneErr(err, num, s.cfg)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
||||
|
|
@ -165,7 +155,8 @@ func (s *historyTestSuite) testGetBlockTransactionCountByHash(t *utesting.T) {
|
|||
bhash := s.tests.BlockHashes[i]
|
||||
count, err := s.cfg.client.getBlockTransactionCountByHash(ctx, bhash)
|
||||
if err != nil {
|
||||
if errIsPrunedHistory(err) {
|
||||
err = validateHistoryPruneErr(err, num, s.cfg)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
||||
|
|
@ -184,7 +175,8 @@ func (s *historyTestSuite) testGetBlockTransactionCountByNumber(t *utesting.T) {
|
|||
bhash := s.tests.BlockHashes[i]
|
||||
count, err := s.cfg.client.getBlockTransactionCountByNumber(ctx, num)
|
||||
if err != nil {
|
||||
if errIsPrunedHistory(err) {
|
||||
err = validateHistoryPruneErr(err, num, s.cfg)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
||||
|
|
@ -203,7 +195,8 @@ func (s *historyTestSuite) testGetBlockReceiptsByHash(t *utesting.T) {
|
|||
bhash := s.tests.BlockHashes[i]
|
||||
receipts, err := s.cfg.client.getBlockReceipts(ctx, bhash)
|
||||
if err != nil {
|
||||
if errIsPrunedHistory(err) {
|
||||
err = validateHistoryPruneErr(err, num, s.cfg)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
||||
|
|
@ -223,7 +216,8 @@ func (s *historyTestSuite) testGetBlockReceiptsByNumber(t *utesting.T) {
|
|||
bhash := s.tests.BlockHashes[i]
|
||||
receipts, err := s.cfg.client.getBlockReceipts(ctx, hexutil.Uint64(num))
|
||||
if err != nil {
|
||||
if errIsPrunedHistory(err) {
|
||||
err = validateHistoryPruneErr(err, num, s.cfg)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
||||
|
|
@ -249,7 +243,8 @@ func (s *historyTestSuite) testGetTransactionByBlockHashAndIndex(t *utesting.T)
|
|||
|
||||
tx, err := s.cfg.client.getTransactionByBlockHashAndIndex(ctx, bhash, uint64(txIndex))
|
||||
if err != nil {
|
||||
if errIsPrunedHistory(err) {
|
||||
err = validateHistoryPruneErr(err, num, s.cfg)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
||||
|
|
@ -277,7 +272,8 @@ func (s *historyTestSuite) testGetTransactionByBlockNumberAndIndex(t *utesting.T
|
|||
|
||||
tx, err := s.cfg.client.getTransactionByBlockNumberAndIndex(ctx, num, uint64(txIndex))
|
||||
if err != nil {
|
||||
if errIsPrunedHistory(err) {
|
||||
err = validateHistoryPruneErr(err, num, s.cfg)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
t.Fatalf("block %d (hash %v): error %v", num, bhash, err)
|
||||
|
|
|
|||
|
|
@ -18,6 +18,8 @@ package main
|
|||
|
||||
import (
|
||||
"embed"
|
||||
"fmt"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
"io/fs"
|
||||
"os"
|
||||
"slices"
|
||||
|
|
@ -75,12 +77,35 @@ var (
|
|||
}
|
||||
)
|
||||
|
||||
const (
|
||||
sepoliaMergeBlock uint64 = 1450409
|
||||
mainnetMergeBlock uint64 = 15537393
|
||||
)
|
||||
|
||||
// testConfig holds the parameters for testing.
|
||||
type testConfig struct {
|
||||
client *client
|
||||
fsys fs.FS
|
||||
filterQueryFile string
|
||||
historyTestFile string
|
||||
client *client
|
||||
fsys fs.FS
|
||||
filterQueryFile string
|
||||
historyTestFile string
|
||||
historyPruneBlock *uint64
|
||||
}
|
||||
|
||||
// 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).
|
||||
// If the error is of a different type, it is returned. If the error is a pruned
|
||||
// history error occurring past the pruning threshold, an error is returned.
|
||||
// Otherwise, nil is returned.
|
||||
func validateHistoryPruneErr(err error, blockNum uint64, cfg testConfig) error {
|
||||
if err != nil {
|
||||
if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == 4444 {
|
||||
if cfg.historyPruneBlock != nil && blockNum > *cfg.historyPruneBlock {
|
||||
return fmt.Errorf("pruned history error returned after pruning threshold")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func testConfigFromCLI(ctx *cli.Context) (cfg testConfig) {
|
||||
|
|
@ -98,10 +123,14 @@ func testConfigFromCLI(ctx *cli.Context) (cfg testConfig) {
|
|||
cfg.fsys = builtinTestFiles
|
||||
cfg.filterQueryFile = "queries/filter_queries_mainnet.json"
|
||||
cfg.historyTestFile = "queries/history_mainnet.json"
|
||||
cfg.historyPruneBlock = new(uint64)
|
||||
*cfg.historyPruneBlock = mainnetMergeBlock
|
||||
case ctx.Bool(testSepoliaFlag.Name):
|
||||
cfg.fsys = builtinTestFiles
|
||||
cfg.filterQueryFile = "queries/filter_queries_sepolia.json"
|
||||
cfg.historyTestFile = "queries/history_sepolia.json"
|
||||
cfg.historyPruneBlock = new(uint64)
|
||||
*cfg.historyPruneBlock = sepoliaMergeBlock
|
||||
default:
|
||||
cfg.fsys = os.DirFS(".")
|
||||
cfg.filterQueryFile = ctx.String(filterQueryFileFlag.Name)
|
||||
|
|
|
|||
Loading…
Reference in a new issue