I was wondering if there was some resource available to better understand how to implement the __gap variable you are using in all your upgradeable abstract contracts (i.e. on v4.3.2OwnableUpgradeable.sol where line 77 is uint256[49] private __gap;.
Does that mean that we're reserving 49 uint256 storage slots?
Will we then be able to declare new single variables pulling from that storage space? Something like
That's great to know!
I'm assuming if a reserved storage slot will then be used by a struct type, we will have to consider its internal storage when declaring the new gap size?
Something like:
// V1
uint256[49] private __gap;
// V2
struct MyData {
// will this struct also take up storage space? it shouldn't, being defined outside the contract, correct?
uint256[] numbers;
address[] addresses;
uint256 number;
}
abstract contract MyContract {
uint256 private myNewDataStruct;
// [assuming the struct wont take up storage]
// define the remaining gap as 49 minus the 3 slots used by struct, is this correct?
uint256[46] private __gap;
}
The diamond storage pattern is indeed interesting and a good (better?) alternative to gaps.
The struct that you showed does not affect storage layout, not because it was defined outside the contract but because the contract doesn't have a state variable of that type.