anchor icon indicating copy to clipboard operation
anchor copied to clipboard

RPC response error -32002: Transaction simulation failed: Error processing Instruction 0: account data too small for instruction

Open beeb opened this issue 10 months ago • 2 comments

I'm just starting out with Solana and Anchor development.

Currently following the tutorial at this address and I'm hitting a snag. I'm using the latest beta solana 1.18.5 and anchor 0.30.0.

Steps to reproduce:

  • anchor init test
  • cd test
  • anchor build -> "package solana-program v1.18.11 cannot be built"
  • cargo update -p [email protected] --precise 1.18.5 (annoying, but ok, only needs to be done once...)
  • anchor build
  • anchor keys sync
  • Start solana test validator in another shell solana-test-validator
  • anchor test --skip-local-validator -> Successful
  • Modify lib.rs to add a parameter to the initialize function, and mirror the change in the test file
  • anchor test --skip-local-validator -> Error below
Error: Deploying program failed: RPC response error -32002: Transaction simulation failed: Error processing Instruction 0: account data too small for instruction [3 log messages]
There was a problem deploying: Output { status: ExitStatus(unix_wait_status(256)), stdout: "", stderr: "" }.

Steps I tried to do to resolve (right after the last command)

  • anchor keys sync (NOTE: this does NOT change the program id in the code)
  • anchor test --skip-local-validator -> Same error
  • Stop and restart solana-test-validator
  • anchor test --skip-local-validator -> Same error

What gives? I'm super confused and it's a really frustrating experience.

I noticed that doing cargo clean then building again makes the error go away, but that's such bad DX I can't see myself doing that every time I make a change to my program! NOTE: after cargo clean, the next call to anchor keys sync reports: "Found incorrect program id declaration in Anchor.toml for the program test"

This would indicate a cache invalidation problem with anchor keys sync.

beeb avatar Apr 25 '24 06:04 beeb

package `solana-program v1.18.11` cannot be built

This error is related to your Solana version. With Anchor 0.30.0, it's recommended to use 1.18.8 as noted in release notes:

solana-install init 1.18.8

The first anchor keys sync step is redundant, as anchor init command already initializes programs with correct program ids. It should only output:

$ anchor keys sync
All program id declarations are synced.
Error: Deploying program failed: RPC response error -32002: Transaction simulation failed: Error processing Instruction 0: account data too small for instruction [3 log messages]
There was a problem deploying: Output { status: ExitStatus(unix_wait_status(256)), stdout: "", stderr: "" }.

This error happens because in Solana 1.18, Solana's deploy command doesn't allocate enough space for future program upgrades. When you added that extra parameter to the initialize function, program size increases, which makes deploying it to the same program account impossible without resizing. This should ideally be done automatically, but apperently the technology is not that advanced yet. For now, you can manually run solana program extend command.

Running anchor test (without --skip-local-validator flag) would not run into this problem, as each deployment is a new one. You can also run anchor test --detach if you'd like to keep the test-validator running after the tests.

Steps I tried to do to resolve (right after the last command)

  • anchor keys sync (NOTE: this does NOT change the program id in the code)
  • anchor test --skip-local-validator -> Same error
  • Stop and restart solana-test-validator
  • anchor test --skip-local-validator -> Same error

What gives? I'm super confused and it's a really frustrating experience.

I noticed that doing cargo clean then building again makes the error go away, but that's such bad DX I can't see myself doing that every time I make a change to my program! NOTE: after cargo clean, the next call to anchor keys sync reports: "Found incorrect program id declaration in Anchor.toml for the program test"

This would indicate a cache invalidation problem with anchor keys sync.

All this is irrelevant to the actual problem. You can run anchor clean instead of cargo clean if you'd like to keep the program keypair file, which would result in consistent program ids.

acheroncrypto avatar Apr 25 '24 17:04 acheroncrypto

Thanks for the detailed answer. I'm surprised that changing the size of the program by modifying the code does not trigger an update of the program ID via anchor keys sync, if the existing program account is not able to hold the program data. Is there a reason this could not be done?

Another option, like you mentioned, could be to automatically call solana program extend on behalf of the user. I believe this would massively improve the DX when using anchor.

Are there any downsides to removing --skip-local-validator when running tests? The tutorial I was following suggested it in their day1 course.

beeb avatar Apr 26 '24 06:04 beeb

Another option, like you mentioned, could be to automatically call solana program extend on behalf of the user. I believe this would massively improve the DX when using anchor.

This was added to Solana CLI in https://github.com/anza-xyz/agave/pull/791. It will also work for Anchor since we use Solana CLI internally to deploy.

Are there any downsides to removing --skip-local-validator when running tests? The tutorial I was following suggested it in their day1 course.

It depends on what you mean by downside. Including that option means you'll keep the existing state and only redeploy the program. This can be interpreted as both a downside and an upside. On the other hand, starting fresh each time is a more common pattern.

acheroncrypto avatar Jul 16 '24 16:07 acheroncrypto