From 113241efde1b998318a1d045eb7e930639c02c3a Mon Sep 17 00:00:00 2001 From: jonastheis <4181434+jonastheis@users.noreply.github.com> Date: Tue, 29 Oct 2024 07:36:57 +0800 Subject: [PATCH] Fix bug in queryInBatches --- rollup/l1/reader.go | 13 +++++++------ rollup/l1/tracker_test.go | 5 +++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/rollup/l1/reader.go b/rollup/l1/reader.go index 5250141ef39d..05ad280cf1b2 100644 --- a/rollup/l1/reader.go +++ b/rollup/l1/reader.go @@ -157,7 +157,7 @@ func (r *Reader) FetchRollupEventsInRange(from, to uint64) (RollupEvents, error) log.Trace("L1Client fetchRollupEventsInRange", "fromBlock", from, "toBlock", to) var logs []types.Log - err := r.queryInBatches(from, to, defaultRollupEventsFetchBlockRange, func(from, to uint64) (bool, error) { + err := queryInBatches(from, to, defaultRollupEventsFetchBlockRange, func(from, to uint64) (bool, error) { query := ethereum.FilterQuery{ FromBlock: big.NewInt(int64(from)), // inclusive ToBlock: big.NewInt(int64(to)), // inclusive @@ -188,7 +188,7 @@ func (r *Reader) FetchRollupEventsInRange(from, to uint64) (RollupEvents, error) func (r *Reader) FetchRollupEventsInRangeWithCallback(from, to uint64, callback func(event RollupEvent) bool) error { log.Trace("L1Client fetchRollupEventsInRange", "fromBlock", from, "toBlock", to) - err := r.queryInBatches(from, to, defaultRollupEventsFetchBlockRange, func(from, to uint64) (bool, error) { + err := queryInBatches(from, to, defaultRollupEventsFetchBlockRange, func(from, to uint64) (bool, error) { query := ethereum.FilterQuery{ FromBlock: big.NewInt(int64(from)), // inclusive ToBlock: big.NewInt(int64(to)), // inclusive @@ -287,15 +287,16 @@ func (r *Reader) processLogsToRollupEvents(logs []types.Log) (RollupEvents, erro return rollupEvents, nil } -func (r *Reader) queryInBatches(fromBlock, toBlock uint64, batchSize int, queryFunc func(from, to uint64) (bool, error)) error { - for from := fromBlock; from <= toBlock; from += uint64(batchSize) { - to := from + defaultL1MsgFetchBlockRange - 1 +// TODO: add context to allow for cancellation +func queryInBatches(fromBlock, toBlock uint64, batchSize uint64, queryFunc func(from, to uint64) (bool, error)) error { + for from := fromBlock; from <= toBlock; from += batchSize { + to := from + batchSize - 1 if to > toBlock { to = toBlock } cont, err := queryFunc(from, to) if err != nil { - return err + return fmt.Errorf("error querying blocks %d to %d: %w", from, to, err) } if !cont { break diff --git a/rollup/l1/tracker_test.go b/rollup/l1/tracker_test.go index 954a625f4c2b..518bff20db87 100644 --- a/rollup/l1/tracker_test.go +++ b/rollup/l1/tracker_test.go @@ -151,6 +151,11 @@ func (m *mockETHClient) BlockByHash(ctx context.Context, hash common.Hash) (*typ panic("implement me") } +func (m *mockETHClient) CallContract(ctx context.Context, msg ethereum.CallMsg, blockNumber *big.Int) ([]byte, error) { + //TODO implement me + panic("implement me") +} + type subscriptionCallTrace struct { old []*types.Header new []*types.Header