Repurposing state variable on upgrade

I happen to be removing a uint and adding a uint in the same upgrade. Is there any reason for me not to simply change the name of the uint and start using it for something else? Aka. recycling the uint.

:computer: Environment


Keep in mind that the old value would still exist in that storage slot until you overwrite it with the new context.

This would be easily done in the initialiser, right?

For repurposing a uint for another uint, this can be done with a reinitializer during upgrade.

But other variables such as mappings should not be repurposed. It's not possible to reinitialize those since their values are stored at different slots which depend on the keys that were used.

Note that repurposing a variable also prevents downgrading directly back to the old implementation, since the variable would no longer make sense in the old context.

1 Like