Open beeb opened 2 months ago
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 errorWhat 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 toanchor keys sync
reports: "Found incorrect program id declaration in Anchor.toml for the programtest
"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.
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.
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 anchor0.30.0
.Steps to reproduce:
anchor init test
cd test
anchor build
-> "packagesolana-program v1.18.11
cannot be built"cargo update -p solana-program@1.18.11 --precise 1.18.5
(annoying, but ok, only needs to be done once...)anchor build
anchor keys sync
solana-test-validator
anchor test --skip-local-validator
-> Successfullib.rs
to add a parameter to theinitialize
function, and mirror the change in the test fileanchor test --skip-local-validator
-> Error belowSteps 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 errorsolana-test-validator
anchor test --skip-local-validator
-> Same errorWhat 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 toanchor keys sync
reports: "Found incorrect program id declaration in Anchor.toml for the programtest
"This would indicate a cache invalidation problem with
anchor keys sync
.