From the anchor lang 25.0 docs, they have implemented the realloc
constraint to give you access to the new functionality of resizing accounts. This functionality is particularly relevant for PDAs which can only be inited with 10kb of space and is limited to a 10kb increase in size each block (or maybe it's per transaction?).
realloc =
sets the new space in bytes
realloc::payer =
points to an account with Sol to pay for the extra space
realloc::zero =
indicates whether you want the data in the account to be zeroed out (basically refresh and delete the entire account). In most cases you may not want this.
Anchor encourages using their constraints over the built in AccountInfo
method because it's possible you might over allocate space and mess with other accounts, check the docs for more deets.
#[derive(Accounts)]
pub struct Example {
#[account(mut)]
pub payer: Signer<'info>,
#[account(
mut,
seeds = [b"example"],
bump,
realloc = 8 + std::mem::size_of::() + 100,
realloc::payer = payer,
realloc::zero = false,
)]
pub acc: Account<'info, MyType>,
pub system_program: Program<'info, System>,
}
realloc
, so I DDGdsolana realloc
and it was like the 5th link