-
Notifications
You must be signed in to change notification settings - Fork 201
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
Stack Size increased with 1.18.x (platform-tools) #1186
Comments
I believe the problem is fixed is platform tools version v1.41. You can check the version of your tools using running Either way, can you provide an example code that triggers the problem? |
@LucasSte we have an existing program that got into this problem when moving from 1.17 to 1.18.15, even though platform tools is 1.41, there's still significantly more stack usage compared to 1.17. In our case anchor's init constraints were the culprit, so we fixed it by moving some ATA account inits to separate IX, but I believe 1.18 is still vastly overusing stack. |
Did you run into the stack access violation error as well? If so, would mind providing an example of the offending code? |
We're seeing this all over the Metaplex Program Library as users and ourselves migrate to 1.18 |
Here is a simple reproduction of the stack frame problem, or at least of one possible occasion. When running the tests in this repository against a local validator that has feature: EenyoWx9UMXYKpR8mW5Jmfmy2fRjzUtM7NduYMY8bx33 diesabled the stack frame error appears, when running them locally with the feature enabled the error does not appear. You can find the code here: https://github.com/Woody4618/stackframe_repro/blob/main/README.md |
The feature disables stack frame gaps, amongst other changes, to enhance the network performance. The gaps serve to detect invalid memory accesses by programs. If you enable the feature, the protection goes away, but it does not mean your contract is behaving correctly. The Rust compiler does not guarantee a stable ABI, so default sizes may change between releases. Tempering with the compiler to change allocation would overshadow a language feature: Rust allows you to choose where to allocate items (e.g. by using Box). The main issue I've found was the |
@LucasSte I agree that |
Will the feature be enabled on mainet soon? Otherwise it would help maybe disable it on localhost and devnet, so people dont get surprised when deploying to mainnet? Then they can fix the problems, by splitting instructions and boxing accounts savely. |
I've found out that the compiler has been missing stack errors. This is why you may not see a compiler error, but your contract may error out during execution. The next release will solve this. If you see the error there, your contract will hit the same error on main net. |
I discussed this issue with @acheroncrypto it looks like PR coral-xyz/anchor#2939 fixes the stack problems with |
Hey @LucasSte there is another ecosystem team that has stack frame issues when upgrading from 1.17 to 1.18. They created a great reproduction: It has warnings like these: Error: Function ZN105$LT$vprog..InitializeStrategy$u20$as$u20$anchor_lang..Accounts$LT$vprog..InitializeStrategyBumps$GT$$GT$12try_accounts17hb64a220c71e28f36E Stack offset of 5168 exceeded max offset of 4096 by 1072 bytes, please minimize large stack variables Are these warnings now always turn into runtime errors with version 1.18? Whats the best way to fix these? Is the only option to decrease size of the accounts? |
These warnings are an indication that your program will misbehave during execution. You do not always see the runtime error in a program with such warning, because the offending case depends on which code path you execute. In general, all stack warnings emitted will lead to a runtime error.
I identified that the compiler was missing stack warning for many cases. This rendered any fix attempt by Anchor or other developers difficult. In Agave v2.0, we shipped platform-tools v1.42, with fixes to warn about all possible scenarios the contract may cause a runtime error. This allowed the Anchor team to merge coral-xyz/anchor#2939, which decreases the stack usage of function I am not aware of Anchor's release schedule, but I can say that upgrading to platform tools v1.42 and using an Anchor version with such a fix will solve most problems. |
As @LucasSte mentioned, this problem is mostly fixed from Anchor's side, but the next version is currently blocked by |
Yup, we're on it. As long as there isn't a blocker updating our client crate and leaving the program on 1.x then it should be done soon. |
Problem
Programs built with solana 1.18.x experience new stack size related issues.
Details
We started having issues after migrating from solana
1.16.16
and anchor0.28.0
to solana1.18.11
and anchor0.29.0
.Started getting messages when building informing us of our ix using too much stack, i.e:
Then at runtime:
Hotfixed the issue by splitting IXs and migrating accounts to use
zero_copy
.We have noticed that the
init
of accounts takes a lot of stack, 800 bytes+. Can't have more than 3 accounts toinit
within the same instruction atm.Note: Even when testnet tests works, it may still fail on devnet.
Setup:
Using https://github.com/anza-xyz/platform-tools/releases v1.41 to compile.
Related
Found an issue here talking about platform tools growing stack usage.
Related to #1158
Proposed Solution
The text was updated successfully, but these errors were encountered: