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

fix(cli): add retry to getLogs when getting resource ID's #2709

Merged
merged 6 commits into from
Apr 23, 2024

Conversation

yonadaa
Copy link
Contributor

@yonadaa yonadaa commented Apr 23, 2024

Attempting to fetch invalid logs from an RPC can error with a 400 Bad Request and "block is out of range". In this case, Viem's getLogs does not retry the query.

However, when using a request router like proxyd, it is possible that some RPC's are slightly behind and do not have the newer logs. In this case we do actually want to retry the query until the RPC has caught up.

This PR adds a pretry to the getLogs call in the getResourceIds function which has consistently failed in deployment.

@yonadaa yonadaa requested review from alvrs and holic as code owners April 23, 2024 12:59
Copy link

changeset-bot bot commented Apr 23, 2024

🦋 Changeset detected

Latest commit: 9e5a05a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 24 packages
Name Type
@latticexyz/cli Patch
mock-game-contracts Patch
@latticexyz/abi-ts Patch
@latticexyz/block-logs-stream Patch
@latticexyz/common Patch
@latticexyz/config Patch
create-mud Patch
@latticexyz/dev-tools Patch
@latticexyz/faucet Patch
@latticexyz/gas-report Patch
@latticexyz/protocol-parser Patch
@latticexyz/query Patch
@latticexyz/react Patch
@latticexyz/recs Patch
@latticexyz/schema-type Patch
@latticexyz/services Patch
solhint-config-mud Patch
solhint-plugin-mud Patch
@latticexyz/store-indexer Patch
@latticexyz/store-sync Patch
@latticexyz/store Patch
@latticexyz/utils Patch
@latticexyz/world-modules Patch
@latticexyz/world Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

onFailedAttempt: async (error) => {
const delay = error.attemptNumber * 500;
debug(`failed to get logs, retrying in ${delay}ms...`);
await wait(delay);
Copy link
Member

Choose a reason for hiding this comment

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

no need for this here, I believe pRetry has its own back off internally
(I suspect this was copied from other spots where we also don't need to do this)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, yes just copied other examples :D

}),
{
retries: 3,
onFailedAttempt: async (error) => {
Copy link
Member

Choose a reason for hiding this comment

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

we could check the error to see if it contains "block is out of range" and only retry those? but I am happy just retrying all here since its a relatively safe operation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I also like that it makes the retry logic more self-explanatory

holic
holic previously approved these changes Apr 23, 2024
Co-authored-by: Kevin Ingersoll <[email protected]>
Co-authored-by: Kevin Ingersoll <[email protected]>
@yonadaa yonadaa merged commit dbc7e06 into main Apr 23, 2024
10 of 12 checks passed
@yonadaa yonadaa deleted the yonadaaa/get-logs-retry branch April 23, 2024 14:58
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