Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
beeb opened this issue Apr 25, 2024 · 2 comments
Labels

Comments

@beeb
Copy link

beeb commented Apr 25, 2024

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.

@acheroncrypto
Copy link
Collaborator

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.

@beeb
Copy link
Author

beeb commented Apr 26, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants