I have read it in forum that upgrading structs can cause a problem when they are contract variables, but if they are stored in mapping then problem won’t be caused. Well I have a struct which is stored in mapping as array of structs. And when I added a property to the end of struct. Previous data of struct is ruined.
Any way to recover this? Or to revert this implementation?
Hi @shakeib98,
I assume that you are referring to this advice on structs and upgradeable contracts:
If I understand correctly, you have a mapping to an array of structs, and not a mapping to a struct. I assume that adding fields to a struct used in an array will likely cause issues.
I recommend thorough testing of upgrades before making them in production.
See the following article for testing real world contract upgrades:
I am not sure if there is a way to recover, it may depend what changes have been made to the state since upgrading.
Hi @shakeib98, please let us know if this happened in production, as it will change the nature of the recommendations.
The latest release of the Upgrades Plugins for Hardhat and Truffle supports structs.