coral-xyz / anchor

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

the `init_if_needed` flag in the accounts macro validates space constraints even if the account is already initialized. #2995

Open dhruvja opened 1 month ago

dhruvja commented 1 month ago

When i use init_if_needed flag to initialize my account if not initialized, i have to pass the space flag indicating the amount of space i need to allocate. But if the account is already initialized and has data length more or less than the space specified which can be due to reallocation, the constraint fails and panics. Ideally we want the space constraint only when the account is not initialized. We wouldnt want to check if the data length matches the space specified since thats only for uninitialized accounts.

acheroncrypto commented 1 month ago

I agree that space shouldn't be checked if the account exists, but it's also a bit ambigious to specify the space constraint, and not check it. I think it's fine though, just noting a slight concern.

dhruvja commented 1 month ago

well i think u could make it something like init::space = <space> like how we have for realloc but i guess that can be a breaking change.