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

Use try-catch for sending Functions requests #195

Merged
merged 3 commits into from
Nov 24, 2023
Merged

Conversation

KuphJr
Copy link
Contributor

@KuphJr KuphJr commented Nov 21, 2023

  • This corrects a potential bug if a Functions subscription lacks the funds to send a request
  • Previously, it was possible for 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.
  • The 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

const autoConsumerContractFactory = await ethers.getContractFactory("AutomatedFunctionsConsumer")
const autoConsumerContract = await autoConsumerContractFactory.attach(taskArgs.contract)

const checkUpkeep = await autoConsumerContract.checkUpkeep(performData)
Copy link
Collaborator

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

  1. performUpkeep anyway and handle a reviert if checkUpkeep returns false (this logic is now in performupkeep)
  2. console log the error (with string or without) if the functions request fails

Do we need to call checkUpkeep separately here?

Copy link
Contributor Author

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.

Copy link
Collaborator

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).

Copy link
Collaborator

@zeuslawyer zeuslawyer left a comment

Choose a reason for hiding this comment

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

Minor question

contracts/AutomatedFunctionsConsumer.sol Show resolved Hide resolved
contracts/AutomatedFunctionsConsumer.sol Show resolved Hide resolved
const checkUpkeep = await autoConsumerContract.checkUpkeep(performData)
if (!checkUpkeep.upkeepNeeded) {
console.log("\ncheckUpkeep returned false. Upkeep was not performed.")
return
Copy link
Collaborator

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?

Copy link
Contributor Author

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.

@KuphJr KuphJr requested a review from bolekk November 23, 2023 23:30
@KuphJr KuphJr merged commit 62cc367 into main Nov 24, 2023
2 checks passed
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.

4 participants