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

Cancelling an already cancelled order shouldn't consume all gas #143

Closed
jorisbontje opened this issue Aug 22, 2016 · 7 comments
Closed

Cancelling an already cancelled order shouldn't consume all gas #143

jorisbontje opened this issue Aug 22, 2016 · 7 comments

Comments

@jorisbontje
Copy link
Contributor

Currently we throw if you try to cancel an order that is already cancelled. This will cause all the 1M gas to be consumed. Instead we should just return instead of throw and make this a NOOP / save lots of gas / trees.

@nmushegian
Copy link
Contributor

I disagree. The habit of using returns when the thing which your function is named didn't happen is too dangerous to be worth it IMO. That's on the EVM designers for not including a free exception op.

p.s. Did you know throw is implemented as an "invalid jump" (which like all exceptions is handled gracefully at the EVM level and then repackaged into confusing semantics at the solidity level)

@nmushegian
Copy link
Contributor

pps see ethereum/EIPs#140

@jorisbontje
Copy link
Contributor Author

While I appreciate your principled position, the EVM designers aren't paying the gas cost for this. It is our users that will have to pay instead. In this specific case it is not about return -ing when no cancel -lation happened, but when it already happened; we can specifically make sure that the specified order_id is/was a valid one to not confuse this with trying to cancel an order that did never exist.

@rainbreak
Copy link
Contributor

We already use the boolean return for buy, so this would be consistent. We already have the boolean return for cancel, it just isn't exercised (just true or throw).

In general and certainly for bigger contracts I'd agree that throw is the better pattern, as it reverts all state changes.

@jorisbontje: would you also want to return false in the case of offer.owner != msg.sender? Similarly on buy, if the offer is inactive?

@jorisbontje
Copy link
Contributor Author

@rainbeam yes, preferably; especially during mass order cancellation (when the market is closed) it is likely that cancel will be triggered concurrently.

@nmushegian
Copy link
Contributor

These arguments make sense to me. I have been using tryAction naming scheme where a safe-reverting non-throwing version is useful, what do you think?

@rainbreak
Copy link
Contributor

Yeah, for a bigger codebase. There's only 3 public functions here though so not sure it's worth it. But then maybe it could be seen in the context of the larger ecosystem. Whichever way it's addressed we're still just working around limitations of the current language. We need better tooling for localised state rollback. Nice EIP btw.

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

No branches or pull requests

4 participants