Do we need to add and calculate the __gaps varibale

Have read the information about __gaps variable:

A few questions:
If a Test contract is inheriting ERC1155PresetMinterPauserUpgradeable and has also varibales that use contract storage, does the Test contract also need to implement
uint256[50] private __gap;

The Documentation states:

The size of the __gap array is calculated so that the amount of storage used by a contract always adds up to the same number (in this case 50 storage slots).

How is that calculated and if the Test contract has also the __gap variable, is updated with Test2 and new storage variables (example: 2 variables are added). Would be the new implementation of Test2 have: uint256[48] private __gap;

:computer: Environment
@openzeppelin/contracts-upgradeable”: “^4.1.0


:1234: Code to reproduce

contract Base {
  uint256 val1;

  uint256[50] private ______gap;

contract Child is Base {
uint256 cval1;

uint256[50] private ______gap;

Then at some point we decide to upgrade Child to ChildV2

 contract ChildV2 is Base {
  uint256 cval1;
  string cval2;
  uint256 cval3;

  uint256[48] private ______gap;

@Skyge @abcoathup @frangio any idea?

Sorry, I missed this.

It’s not necessary. It would be a good idea if Test were used as a parent contract, but otherwise I would say it’s best not to.

Yes this is the idea.

1 Like

Thanks for clarifying