coral-xyz / anchor

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

Account data too small for instruction error when deploying program with anchor deploy #2870

Closed ASoldo closed 6 months ago

ASoldo commented 6 months ago

Hi, I'm new to Anchor and by following some working tutorials from beta.solpg.io I made local project and got it working and building fine. But when this code is present while deploying i get error saying that Deploying program failed: RPC response error -32002: Transaction simulation failed: Error processing Instruction 0: account data too small for instruction.

Im on latest builds for avm and anchor-cli.

Can someone point out the issue with this code?

#[derive(Accounts)]
#[instruction()]
pub struct CreatePost<'info> {
    #[account(
        init,
        seeds = [POST_SEED, authority.key().as_ref(), &[user_account.last_post_id as u8].as_ref()],
        bump,
        payer = authority,
        space = 2377 + 8
    )]
    pub post_account: Account<'info, PostAccount>,

    #[account(mut,seeds = [USER_SEED, authority.key().as_ref()], bump, has_one = authority)]
    pub user_account: Account<'info, UserAccount>,

    #[account(mut)]
    pub authority: Signer<'info>,

    pub system_program: Program<'info, System>,
}
#[account]
#[derive(Default, InitSpace)]
pub struct PostAccount {
    pub id: u8, // 1
    #[max_len(256)]
    pub title: String, // 4 + 256
    #[max_len(2048)]
    pub content: String, // 4 + 2048
    pub user: Pubkey, // 32
    pub authority: Pubkey, // 32
}

This program can be built locally but not deployed but on beta.solpg.io it builds, tests are passing and it deploys. I even connected from frontend to that program and interact with it. image

Why is it not deploying from cli I have no idea and I really need some help if anyone know the answer from their experiences that would be great.

thank you!

ASoldo commented 6 months ago

Skill issue.

When we deploy our program once and we want to redeploy it because we did more stuff to it it will throw this error. Solution for me was to just generate new keys for program id and new name. Now it builds, deploys as before.

I think that is self explanatory now when I know that information. Correct me if I'm wrong.