-
Notifications
You must be signed in to change notification settings - Fork 103
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
Use try-catch for sending Functions requests #195
Conversation
const autoConsumerContractFactory = await ethers.getContractFactory("AutomatedFunctionsConsumer") | ||
const autoConsumerContract = await autoConsumerContractFactory.attach(taskArgs.contract) | ||
|
||
const checkUpkeep = await autoConsumerContract.checkUpkeep(performData) |
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.
Possibly a nit: Given that the goal is to make sure that we do not re run automation when the sub has no balance could we not just
- performUpkeep anyway and handle a reviert if checkUpkeep returns false (this logic is now in performupkeep)
- console log the error (with string or without) if the functions request fails
Do we need to call checkUpkeep separately here?
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.
I updated the console.log message slightly, although I do think how it is currently implemented is how I intended.
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.
sorry @KuphJr i commented over too many lines! I was wondering whether line 22 could just go straight to performUpkeep (and rely on its internal checkupkeep call).
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.
Minor question
const checkUpkeep = await autoConsumerContract.checkUpkeep(performData) | ||
if (!checkUpkeep.upkeepNeeded) { | ||
console.log("\ncheckUpkeep returned false. Upkeep was not performed.") | ||
return |
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.
This might be a little annoying if somebody wants to force a performUpkeep but now needs to wait for s_updateInterval to pass. How is this command expected to be used? Maybe put calling checkUpkeep under a flag?
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.
Noted. I can just remove this check and allow performUpkeep
to revert if checkUpkeep
returns false.
performUpkeep
to revert if the Functions subscription lacked funds. This meant the last upkeep time was never updated, so Automation kept retrying the upkeep and could spend all the funds in the Automation subscription.try-catch
prevents Automation from attempting repeated failed upkeeps since the last upkeep time is always updated even if the Functions request fails instead of the entire transaction reverting