Skip to content

Commit

Permalink
handling too many requests error and storing logs received to retry i…
Browse files Browse the repository at this point in the history
…n the next iteration (#159)
  • Loading branch information
lucasmenendez authored Feb 20, 2024
1 parent 38f6cd1 commit 5f7b64a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion scanner/providers/farcaster/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ func (p *FarcasterProvider) ScanLogsIDRegistry(ctx context.Context, fromBlock, t
web3.LOG_TOPIC_FARCASTER_REGISTER,
)
if err != nil {
return nil, 0, false, err
if !errors.Is(err, web3.ErrTooManyRequests) {
return nil, 0, false, err
}
log.Debug("too many requests error, handling scanned logs")
}
// encode the number of new registers
newFIDs := make(map[uint64]common.Address, 0)
Expand Down
1 change: 1 addition & 0 deletions scanner/providers/web3/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ var (
ErrConnectingToWeb3Client = fmt.Errorf("client not set")
ErrInitializingContract = fmt.Errorf("error initializing token contract")
ErrScanningTokenLogs = fmt.Errorf("error scanning token logs")
ErrTooManyRequests = fmt.Errorf("web3 endpoint returns too many requests")
ErrParsingTokenLogs = fmt.Errorf("error parsing token logs")
ErrGettingTotalSupply = fmt.Errorf("error getting total supply")
)
5 changes: 5 additions & 0 deletions scanner/providers/web3/web3_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,11 @@ func RangeOfLogs(ctx context.Context, client *ethclient.Client, addr common.Addr
log.Warnf("too much results on query, decreasing blocks to %d", blocksRange)
continue
}
// if error is about too many requests, return the logs scanned
// until now and the last block scanned with an specific error
if strings.Contains(strings.ToLower(err.Error()), "too many requests") {
return finalLogs, fromBlock, false, errors.Join(ErrTooManyRequests, fmt.Errorf("%s: %w", addr.Hex(), err))
}
return finalLogs, fromBlock, false, errors.Join(ErrScanningTokenLogs, fmt.Errorf("%s: %w", addr.Hex(), err))
}
// if there are logs, add them to the final list and update the
Expand Down

0 comments on commit 5f7b64a

Please sign in to comment.