-
Notifications
You must be signed in to change notification settings - Fork 202
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
Changes from 1 commit
fb97fc9
a6ce365
ade6164
6da9640
a26f286
9e5a05a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ import { getLogs } from "viem/actions"; | |
import { storeSpliceStaticDataEvent } from "@latticexyz/store"; | ||
import { WorldDeploy, storeTables } from "./common"; | ||
import { debug } from "./debug"; | ||
import pRetry from "p-retry"; | ||
import { wait } from "@latticexyz/common/utils"; | ||
|
||
export async function getResourceIds({ | ||
client, | ||
|
@@ -15,15 +17,25 @@ export async function getResourceIds({ | |
// TODO: PR to viem's getLogs to accept topics array so we can filter on all store events and quickly recreate this table's current state | ||
|
||
debug("looking up resource IDs for", worldDeploy.address); | ||
const logs = await getLogs(client, { | ||
strict: true, | ||
address: worldDeploy.address, | ||
fromBlock: worldDeploy.deployBlock, | ||
toBlock: worldDeploy.stateBlock, | ||
event: parseAbiItem(storeSpliceStaticDataEvent), | ||
args: { tableId: storeTables.store_ResourceIds.tableId }, | ||
}); | ||
|
||
const logs = await pRetry( | ||
() => | ||
getLogs(client, { | ||
strict: true, | ||
address: worldDeploy.address, | ||
fromBlock: worldDeploy.deployBlock, | ||
toBlock: worldDeploy.stateBlock, | ||
event: parseAbiItem(storeSpliceStaticDataEvent), | ||
args: { tableId: storeTables.store_ResourceIds.tableId }, | ||
}), | ||
{ | ||
retries: 3, | ||
onFailedAttempt: async (error) => { | ||
const delay = error.attemptNumber * 500; | ||
debug(`failed to get logs, retrying in ${delay}ms...`); | ||
await wait(delay); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for this here, I believe There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, yes just copied other examples :D |
||
}, | ||
}, | ||
); | ||
const resourceIds = logs.map((log) => log.args.keyTuple[0]); | ||
debug("found", resourceIds.length, "resource IDs for", worldDeploy.address); | ||
|
||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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