-
Notifications
You must be signed in to change notification settings - Fork 11.8k
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
Multiple inheritance with upgradeable contracts #4602
Comments
Unfortunately I don't have a good answer to give you. We are interested in having a check for this in our upgrades tooling (OpenZeppelin/openzeppelin-upgrades#160) but we haven't made progress on that front. I'm not sure I understood this part:
|
@frangio Please, check out the example. Basically, I am trying to say that if two child contracts on the same level in the inheritance hierarchy inherit from the same parent that must be initialized, don't initialize the parent in one of these children, but use the higher level child which is a parent of both child contracts (it can be the top most contract). It is easier to understand by the example. The good part is in case we have a standard for the naming of init functions and a standard for the place where a parent contract must be initialized, a check tool sounds like an easier mission. |
If I'm understanding correctly, the strategy would be initializing the contracts in the highest common parent, is that correct? It's a good heuristic and it'd solve the duplicate initialization. However, we also need to check there are no missing initializers and also they were executed in the correct order. Concretely, the initializers should follow the same C3 linearization order Solidity does. Using the highest common parent may result in a different execution orders of initializers |
🧐 Motivation
Hello OpenZeppelin team,
Navigating the world of multiple inheritance with upgradeable contracts can be a tad complex, especially for those who are newer to the ecosystem. I've noticed there isn't a clear guideline on this in the documentation, which led me to develop a potential approach. My intention is to foster a discussion here to refine it and maybe consider incorporating some variant of it into the OpenZeppelin documentation, if deemed useful.
📝 Details
Here is a question I found on StackOverflow:
Here is a link to the question.
And here is my recommended approach:
Consider it as bundling sections of contracts into modules. These modules are then grouped into larger modules, and this hierarchical grouping continues until you reach the most derived contract.
It sounds a bit complicated, but the following example makes it clear.
Here is a visual representation of the
Centaur
contract's architecture that can help you understand how the approach works.I'm keen to hear your thoughts on this and collaborate to refine the approach.
Thanks in advance!
The text was updated successfully, but these errors were encountered: