-
Notifications
You must be signed in to change notification settings - Fork 426
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
Add docstring for the gap variable #47
Comments
What is this variable used for? |
@nevverlander Since OpenZeppelin contracts are used by inheritance, user-defined variables will be placed by the compiler after OpenZeppelin's ones. If, in a newer version, new variables are added by the library, the storage layouts would be incompatible, and an upgrade would not be possible. The gap is a workaround to that issue: by leaving a 50-slot gap, we're able to increase the contract's storage by that amount (provided we also remove the same slots from the gap) with no clashing issues. |
May I ask what would happen is some of the base contracts modify the layout e.g. adding a new field. Should we still keep the gap of 50 slot or should it be 50 - For example, imagine the following hierarchy]
Then at some point we decide to update the Base1 by adding a new fields
Should we still keep |
Hi @ppoliani, If you add a new state variable to Please see the documentation for how storage gaps are used in OpenZeppelin Contracts: https://docs.openzeppelin.com/contracts/3.x/upgradeable#storage_gaps If you have further questions, you can ask in the community forum: https://forum.openzeppelin.com/ |
Hi, I am also wondering why it has to be an array of 50? Why not 40 or 30? Thanks |
@alexon1234 I'm not sure either maybe @abcoathup can correct me, but since the number of slots does not cause any overhead then something safe as 50 might not be a bad figure to use |
The number 50 seemed enough. There is a very small overhead in code size because slot numbers will be slightly larger. |
Hi @abcoathup |
Fixed in OpenZeppelin/openzeppelin-transpiler#73. @GhasemiReza21 Reducing gaps is not yet supported in the Upgrades Plugins but we're adding this in the next few weeks. For now you need to resolve this issue manually, if you need help please post in the OpenZeppelin Forum. |
Contracts have an undocumented
uint256[50] private ______gap;
This variable should be documented with a very clear explanation, because it's weird.
The text was updated successfully, but these errors were encountered: