tact-lang / tact

Tact compiler main repository
https://tact-lang.org
MIT License
303 stars 84 forks source link

Simple Contract Upgrades #27

Open ex3ndr opened 1 year ago

ex3ndr commented 1 year ago

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

howardpen9 commented 9 months ago

expanding, and raise this again!

wedvjin commented 2 months ago

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

bymoses commented 1 month ago

@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

alan890104 commented 1 month ago

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