I'm using the Anchor framework with Solana.
I have this account policy (not sure what to call it), for creating a PDA.
#[derive(Accounts)]
#[instruction(bump: u8)]
pub struct CreateGameState<'info> {
#[account(init, payer=user,
space=GameState::space(),
seeds=[],
bump=bump)]
pub game_account: Account<'info, GameState>,
#[account(mut)]
pub user: Signer<'info>,
pub system_program: Program<'info, System>,
}
impl GameState {
fn space() -> usize {
10240
}
}
I notice that if I increase the number above 10240, I get the error: "'SystemProgram::CreateAccount data size limited to 10240 in inner instructions',"
but, I know that the maximum account size in Solana is 10MB, which is well above 10240 bytes.
Why can I not have more space in the account?
When creating accounts as an inner instruction through CPI, there is indeed a "realloc" limit, mentioned briefly at https://docs.solana.com/developing/on-chain-programs/overview#input-parameter-serialization. This is because the runtime needs to pre-allocate new space just in case an account is created, and allocating too much would take up a lot of RAM from the validators.
If you want to create an account with the full 10MB, you need to do it as a standalone instruction, and not as an inner instruction using invoke_signed
or invoke
from within your program.
In your situation, that means you won't be able to use a PDA for your GameState
if you need it to be bigger than 10240 bytes.