-
Notifications
You must be signed in to change notification settings - Fork 353
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
dev: two step ownable #809
Conversation
Seeking initial feedback on the proposed approach. The whole test suite is missing, I'll add it once we flesh out the rest. On more point I'd like to discuss - I always felt like there should be a way for the pending owner to renounce their nomination. This isn't present in the Solidity version (not sure if it was considered). I don't have a use case for it, just that it "feels fair" for the pending owner 😄 WDYT? |
Thanks for pushing this. Overall direction looks really good to me! I appreciate the effort to streamline migration for existing Ownable users.
I don't think it's just code reuse, I still believe it makes sense since this is to me just an alternative implementation of the same Ownable component. One drawback though is that this forces an extra storage element for vanilla Ownable users. It'd be useful to understand what's the cost difference (if any).
Agree on containing any ugliness within the component, away from the user interface. I presume using
I honestly don't see the benefit, my bias is always towards minimizing complexity. |
My understanding is that there would only be a minimal increased cost when declaring a class, because of the increased bytecode size. I haven't verified it though. Otherwise, during runtime, there should be no difference whatsoever since the
Yes, something like
That's a good point as the alternative would require another public function 👍 Will continue with adding tests and cleaning the PR up then. |
Code-wise the PR is ready for review (so I'm marking it as such). However I haven't yet touched the docs section. How do you want to handle it? Should the two step process be a subsection under "Ownership and Ownable" or should it be its own section? Should I test the component on testnet as well? |
Oh, forgot to mention - in the test file ( |
I'd add a new section, while documenting the component in the API section.
If you can do that, it'd be great. But to be fair we haven't been doing so since we're usually running behind the latest Cairo language which is not always deployed. Thanks for the work put into this, and please bear with us while we make some space to properly review it. |
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.
Looking very good @milancermak. Thanks for taking the time! I left some comments mostly related to consistency and comments, but I think is pretty much done.
Dealt with all the points from the review. Thanks for the keen eye @ericnordelo. Also did try the functionality on testnet. It works as designed. Even upgrading from one-step to two-step ownable (and back) is without any surprises. Will proceed with writing the docs then. |
I forgot to do |
gm guys Just pushed the docs - added both a section to the general overview and also updated the API docs. Three things to point out:
Thanks for any feedback 🚀 |
44236d2
to
a90a0a9
Compare
we already have |
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.
Hey @milancermak , sorry for the delay. Thanks again for taking the time. I left some suggestions about doc organization.
A valid point that two-step ownable is not a separate component. I've updated the docs based on the comments above, hopefully satisfactory. If not, feel free to unresolve the conversation or post new comments. However I now feel that the docs don't show well enough how to use the two step functionality of the component. An easy copy-paste-able snippet like this would help IMO: #[abi(embed_v0)]
impl OwnableTwoStepImpl = OwnableComponent::OwnableTwoStepImpl<ContractState>; WDYT? Also the mention about upgrading is now gone. Not sure how important that is. |
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.
Very nice work! I left some comments.
I'd like to see how the snippet looks in the docs, and I think we can forego the upgrading guide.
Co-authored-by: Eric Nordelo <eric.nordelo39@gmail.com>
thanks for the heads up! |
@milancermak is this ready for final review? |
Yes |
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.
Looking good! Left some comments.
GM sirs and happy new year. Just bumping this, I've addressed the latest comments. Let me know if there's anything else missing. |
Resurfacing this PR 😇 |
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.
Great progress, we're nearly there! I think we're ready to test this onchain, can you do it?
That and resolving the pending discussions should be enough.
I already did the onchain testing some time ago - can't find the TXs anymore. But basically I did a super simple contract that was Ownable and Upgradable, did the upgrade back and forth, verified that the owner stayed the same during upgrades and that the new owner was transferred successfully after it was accepted and that a protected function could only be access by the owner. It worked smoothly. |
Should be ready for final review and merge @martriay @ericnordelo |
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.
Looks good to me! Let's address the merge conflicts.
Done. Thanks @martriay |
Thank you, for the contribution and the patience. Just requested @ericnordelo's approval (because he requested changes) to unblock the merge. |
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.
LGTM! Thanks @milancermak for the time and patience. We need to refactor tests a bit for consistency with our last updates, but we don't need to stale the PR because of that IMO. That can be fixed later.
Fixes #304
Adds support for two step ownership transfer, i.e. a new owner is first proposed by the current owner by calling
transfer_ownership
, then the proposed owner has to callaccept_ownership
to become newowner
. Modeled after the Solidity version as linked in the original issue.I kept the code in the
ownable.cairo
component because of code reuse. While I'm not a DRY fanatic, in this case I think it works pretty well. From a user's perspective, if they have a contract with (one step) Ownable and decide to upgrade to two step Ownable, they only have to switch fromto
so it's a one line diff. Everything else (
component!
declaration and whatnot) stays the same and the contract upgrade is safe (current owner is not lost) as the underlying storage is the same.The one slight drawback is that in the component impl, since both interfaces have functions of the same signature, I had to use the impl name to fully qualify which one should be run. In practice, it means going from
self.transfer_ownership(newOwner)
toOwnable::transfer_ownership(ref self, newOwner);
in two or three places. It's a bit ugly IMO since it's inconsistent with the surrounding code, but because it's hidden inside the code of the component, I think it's a good trade-off. Curious to hear your thoughts.PR Checklist