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

Improve Initializable docstrings #3704

Merged
merged 5 commits into from Sep 16, 2022

Conversation

tinchoabbate
Copy link
Contributor

@tinchoabbate tinchoabbate commented Sep 15, 2022

Updating the docstrings of the Initializable contract so they better reflect the actual behavior of the code.

Changes include:

  1. Warning that reinitializer(1) is not equivalent to initializer. Because one allows nesting while the other doesn't. I noticed this was even mentioned in Simplify Initializable #3450, so I guess you're already aware of the difference, and the docs were just outdated.
  2. Warning that reinitializer(255) will prevent further reinitializations.
  3. Mentioning that these functions emit events.

There's one additional thing I wanted to raise, that I noticed while writing (2) but I did not mention in the docs. At first sight, it may seem that a function that executes reinitializer(255) would behave the same as calling _disableInitializers, in terms of disabling further reinitialization. However, _disableInitializers explicitly requires that the contract is not initializing. While reinitializer(255) first checks the same, then it would continue execution into initializing mode. So it feels like a subtle inconsistency, but I'm not sure to what extent it could actually be problematic, or even worth highlighting in the docs.

@frangio
Copy link
Contributor

frangio commented Sep 15, 2022

Thanks! These are great additions.

I'm not sure I agree with the removal of the "equivalent to..." notes. While you're right that they are not exactly equivalent, and we should definitely document the differences, I think the comparisons are valuable to give an intuition about what the modifiers do and how they relate. Perhaps we should simply replace "equivalent" with "similar", and explain how the differ (as you've done). Do you agree, and can you make this change?

Regarding the last point about the difference between _disableInitializers() and reinitializer(255), if I understand correctly what you're saying is that the modifier will disable and then execute the body of the reinitializer. But as far as I can tell that's the only place where they differ? I see them being consistent in the sense that the disable function could be equivalently written as function _disableInitializers() reinitializer(255) {}.

@tinchoabbate
Copy link
Contributor Author

tinchoabbate commented Sep 16, 2022

I'm not sure I agree with the removal of the "equivalent to..." notes. While you're right that they are not exactly equivalent, and we should definitely document the differences, I think the comparisons are valuable to give an intuition about what the modifiers do and how they relate. Perhaps we should simply replace "equivalent" with "similar", and explain how the differ (as you've done). Do you agree, and can you make this change?

I see your point. Agreed! I changed it so that it better states that the modifiers are indeed similar, except for the mentioned behavior. I also removed the WARNING label for these, because I think they were too strong.

Regarding the last point about the difference between _disableInitializers() and reinitializer(255), if I understand correctly what you're saying is that the modifier will disable and then execute the body of the reinitializer. But as far as I can tell that's the only place where they differ?

Yes, that's my point. Though I might be overthinking it, and probably the discussion is out of scope of the PR. If I can come up with an example scenario to be clearer, I'll open an issue.

Copy link
Contributor

@frangio frangio left a comment

Choose a reason for hiding this comment

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

Approved with minor changes. Thanks!

@frangio frangio changed the title Improvements in Initializable docstrings Improve Initializable docstrings Sep 16, 2022
@frangio frangio enabled auto-merge (squash) September 16, 2022 18:07
@frangio frangio merged commit a549ec6 into OpenZeppelin:master Sep 16, 2022
@gitpoap-bot
Copy link

gitpoap-bot bot commented Sep 16, 2022

Woohoo, your important contribution to this open-source project has earned you a GitPOAP!

GitPOAP: 2022 OpenZeppelin Contracts Contributor:
GitPOAP: 2022 OpenZeppelin Contracts Contributor GitPOAP Badge

Head on over to GitPOAP.io and connect your GitHub account to mint!

@tinchoabbate tinchoabbate deleted the patch-docs-initializable branch September 18, 2022 17:24
frangio pushed a commit that referenced this pull request Sep 23, 2022
Co-authored-by: tincho <tinchoabbate@noreply.users.github.com>
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
(cherry picked from commit a549ec6)
JulissaDantes pushed a commit to JulissaDantes/openzeppelin-contracts that referenced this pull request Nov 3, 2022
Co-authored-by: tincho <tinchoabbate@noreply.users.github.com>
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants