tact
tact copied to clipboard
Simple Contract Upgrades
We need to make our contracts upgradable. Storage loading has to be flexible.
expanding, and raise this again!
the upgrade of the code works perfectly fine by calling stdlib function set_code from tact. it is possible to modify the existing methods, add new ones with new message types, as well as add new getters.
the issue arises when both code and data is being upgraded. by upgrading data i mean adding new state variables by calling set_data.
note: adding new state variables does not break contract or wrappers, only when the program tries to use them. also, after adding new state variables through the upgrade, it is impossible to upgrade-add new methods.
simple example, demonstrating the issue: https://github.com/wedvjin/ton-tact-contract-upgrade
i will take a closer look at generated func code
@wedvjin you could use early exit like nativeThrow(0)
right after set_data
, this will not corrupt storage, but overwrites it. Here's working example
But actually data transition is not that trivial. You should implement some migration logic in order to merge your previous data to the new layout. Otherwise your whole storage will be overwriten by set_data
@bymoses proposed the upgrade feature explanation here
I would suggest to adapt the off-chain one since the on-chain one requires halting the contract for upgrading, which introduce extra operational dependencies. Instead adding the Upgradable trait into tondynasty-contracts, i think implement upgradable trait in Tact compiler would be better. @anton-trunov I kindly inquire your opinion.