coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.61k stars 1.32k forks source link

Upgradeable accounts #233

Open armaniferrante opened 3 years ago

armaniferrante commented 3 years ago

Accounts can have a version field (which is part of the seed when creating associated accounts). Then, we can change the data of an account with a method that will migrate data from the old to the new account, destroying the old one.

Suggested by @NorbertBodziony

armaniferrante commented 3 years ago

We could potentially put the version number in the account header, next to the discriminant. So the layout is 8-byte-discriminant || version || borsh(account)

NorbertBodziony commented 3 years ago

We will also need to force that no one will be able to create an old version of the account. Maybe allow for only one use of init/associated ?

armaniferrante commented 3 years ago

@NorbertBodziony I believe no one will be able to create an old version of the account by virtue of the program's code being updated, since only the program can modify account data.