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

Refactor handler errors to try on next block watch tower pattern #87

Merged
merged 14 commits into from
Aug 5, 2024

Conversation

yvesfracari
Copy link
Contributor

@yvesfracari yvesfracari commented May 7, 2024

Description

Refactor Stop Loss, Trade Above Threshold, and Good After Time errors to watch tower try again pattern.

Changes

  • Add revertPollAtNextBlockmethod on ConditionalOrdersUtilsLib
  • Stop Loss Refactoring
  • Trade Above Threshold Refactoring
  • Good After Time Refactoring

How to test

  1. Run modified test files
  2. Stop Loss Deployment on sepolia: 0x410c267baf50b36475B30051Da2aE734f6726F01

Related Issues

Copy link

github-actions bot commented May 7, 2024

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@yvesfracari
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@yvesfracari yvesfracari marked this pull request as ready for review May 8, 2024 13:13
@mfw78
Copy link
Contributor

mfw78 commented May 10, 2024

In general, I'd suggest to include all the watch-tower errors that are possible. I'd already done some work in develop on this. Refer:

// --- errors specific for polling
// Signal to a watch tower that polling should be attempted again.
error PollTryNextBlock(string reason);
// Signal to a watch tower that polling should be attempted again at a specific block number.
error PollTryAtBlock(uint256 blockNumber, string reason);
// Signal to a watch tower that polling should be attempted again at a specific epoch (unix timestamp).
error PollTryAtEpoch(uint256 timestamp, string reason);
// Signal to a watch tower that the conditional order should not be polled again (delete).
error PollNever(string reason);

Instead of introducing this within IConditionalOrder as I did, having a separate interface, as you have done, for the watch-tower custom errors is fine.

Copy link
Contributor

@mfw78 mfw78 left a comment

Choose a reason for hiding this comment

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

In general looks OK. I've left some comments about IwatchtowerCustomErrors in the main PR comments. FYI, there is a error PollTryNextBlock(string reason) that is supported by the watch-tower. This allows for simpler code as it was identified that trying at the very next block is a common pattern and alleviates a lot of block.number + 1.

Comment on lines 35 to 45

/**
* @dev Reverts call execution with a custom error that indicates to the
* watchtower to poll for new order when the next block is mined.
*/
function revertPollAtNextBlock(string memory message) internal view {
revert IWatchtowerCustomErrors.PollTryAtBlock(
block.number + 1,
message
);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd generally discourage the use of revert utilities, such as this, to reduce the layers of indirection required when reviewing the logic within the smart contract to know where I can expect a revert (sure, it's in the name, but it's another function that I then need to drill into to triple check that it indeed does revert). Depending on the optimiser as well and how this gets compiled, this may also result in additional gas consumption.

@yvesfracari
Copy link
Contributor Author

Thanks for review @mfw78 . I refactor the contracts to address them. Let me know if we need more on the dev side. Also, once you think it's ready for deployment, let me know what should be the process (if we should do it or not).

mfw78
mfw78 previously approved these changes May 21, 2024
Copy link
Contributor

@mfw78 mfw78 left a comment

Choose a reason for hiding this comment

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

LGTM

@mfw78 mfw78 requested a review from fleupold May 21, 2024 19:23
@ribeirojose
Copy link
Contributor

rebased onto #88 @mfw78

@yvesfracari
Copy link
Contributor Author

@mfw78 since we're planning to launch the stop-loss app soon, I think that we should have this PR merged. Let me know if you need more things on our side. All the changed handlers contracts will need to be redeployed, I was assuming that you guys will do it since you have a wallet to do this process, right?

mfw78
mfw78 previously approved these changes Jul 23, 2024
@mfw78 mfw78 requested a review from fedgiac July 23, 2024 06:23
Copy link
Contributor

@fedgiac fedgiac left a comment

Choose a reason for hiding this comment

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

The changes look good to me with the exception of the comment below. Once clarified it's good for merging.

src/types/GoodAfterTime.sol Outdated Show resolved Hide resolved
@mfw78 mfw78 requested a review from fedgiac July 24, 2024 13:02
Copy link
Contributor

@fedgiac fedgiac left a comment

Choose a reason for hiding this comment

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

Nice!

@mfw78 mfw78 merged commit 7c815d4 into cowprotocol:main Aug 5, 2024
2 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

chore: Interface with errors supported by the watchtower
4 participants