tact icon indicating copy to clipboard operation
tact copied to clipboard

Simple Contract Upgrades

Open ex3ndr opened this issue 1 year ago • 1 comments

We need to make our contracts upgradable. Storage loading has to be flexible.

ex3ndr avatar Mar 08 '23 20:03 ex3ndr

expanding, and raise this again!

howardpen9 avatar Oct 16 '23 17:10 howardpen9

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 avatar May 22 '24 12:05 wedvjin

@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 avatar Jun 06 '24 16:06 bymoses

@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.

alan890104 avatar Jun 13 '24 16:06 alan890104