4

Are there any rules / best practices when upgrading programs in Solana? Coming from the Ethereum development space, it's really important in the EVM to make sure existing storage isn't reallocated to new variables as a best practice (of course there are edge cases with bitpacking etc), but rather to continue to add new variables.

I am curious if there are similar restrictions / edge cases to watch out for when thinking about upgrading programs in Solana?

2 Answers 2

4

As long as a solana progamm is not frozen you can update it any time. If it becomes bigger after the upgrade you need to check if you payed enough rent for the new program size.

As of now all programs deployed will be deployed with double the size needed. This will change soon since it is now possible to extend the size of programs.

Extend program was activated on mainnet in epoch 532: https://github.com/solana-labs/solana/issues/26385

For accounts you can also allocate more data and then use the bytes after you extended the accounts. To increase an account size using anchor you can for example do it like this:

#[derive(Accounts)]
#[instruction(len: u16)]
pub struct IncreaseZeroCopy<'info> {
    #[account(mut, 
        realloc = len as usize, 
        realloc::zero = true, 
        realloc::payer=signer)]
    pub data_holder: AccountLoader<'info, DataHolder>,
    #[account(mut)]
    pub signer: Signer<'info>,
    #[account(address = system_program::ID)]
    pub system_program: Program<'info, System>,
}

In a progamm you can also use:

pda_account.realloc(new_size, false)?;

In this repo you can see some more info about how to create big accounts and realloc: https://github.com/solana-developers/anchor-zero-copy-example

The max size for accounts created via CPI (for example anchor init) is 10K max account size in general 10mb.

Complicated it becomes when you need to migrate data. Then you probably want to have a migration instruction in your program and V1 and V2 accounts or smth like that.

2

with my experience, i just update the program. You may have an error about insufficient space, in that case you have to redeploy the program (with a new program id) or extend the available space.

I'm not aware about any best practice around updating programs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.