Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle RPC range errors in getLogs #606

Merged
merged 9 commits into from
Dec 22, 2023
Merged

Handle RPC range errors in getLogs #606

merged 9 commits into from
Dec 22, 2023

Conversation

gmbronco
Copy link
Contributor

Extracted getLogs into separate function where we can handle RPC errors related to maximum block range thrown differently by different providers. Added an option to decode event data when ABI is passed.

).map((gauge) => gauge.gaugeAddress);
)
.map((gauge) => gauge.gaugeAddress)
.filter((address, i, arr) => arr.indexOf(address) === i); // Make unique
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

they should already be unique?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, good catch, removing.

Comment on lines 66 to 81
.catch((e: any) => {
// Ankr RPC returns error if block range is too wide
if (e.includes('block range is too wide')) {
return getEvents(from, to, addresses, topics, rpcUrl, rpcMaxBlockRange / 2);
}

// Infura returns 'more than 10000 results' error if block range is too wide
if (e.includes('query returned more than 10000 results')) {
const range = e
.match(/\[([0-9a-fA-F, x]+)\]/)
.pop()
.split(', ')
.map((hex: string) => parseInt(hex, 16));

return getEvents(from, to, addresses, topics, rpcUrl, range[1] - range[0]);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These retries will mess with the "latestSyncBlock" logic. If it retries, it will still persist the toBlock as the latest think block and not the one it actually synced to. You either need to make sure all blocks up until toBlock are queried or get rid of the retries and set reasonable block limits.

I guess we anyway need to make sure that it fails if one of the promises fails, or not do promise.all but do they sequentially and return the block number until which we synced

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, I double checked and unless I'm missing something obvious, catch is refetching only the chunk that failed, not the whole range, so it's just filling the gaps. there is promise.all instead of allSettled to make sure it gets rejected as a whole, not just a part of it.

calling getEvents should return the whole range or nothing.

Comment on lines 41 to 48
if (e.includes('query returned more than 10000 results')) {
const range = e
.match(/\[([0-9a-fA-F, x]+)\]/)
.pop()
.split(', ')
.map((hex: string) => parseInt(hex, 16));

return getEvents(from, to, addressChunk, topics, rpcUrl, range[1] - range[0]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you describe the actual string you are parsing here in the comments? Hard to say whether the string manipulation is correct

@franzns franzns self-requested a review December 22, 2023 07:55
@gmbronco gmbronco merged commit db31f65 into v3-canary Dec 22, 2023
1 check passed
@gmbronco gmbronco deleted the fix-logs branch December 22, 2023 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants