Skip to content

Commit

Permalink
Fix bug in queryInBatches
Browse files Browse the repository at this point in the history
  • Loading branch information
jonastheis committed Oct 28, 2024
1 parent c96a3da commit 113241e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 7 additions & 6 deletions rollup/l1/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions rollup/l1/tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 113241e

Please sign in to comment.