4

Specifically:

  1. what happens if I re-alloc an account but i forget to transfer enough lamports to make the account rent-exempt?
  2. is it possible to make an account smaller?
  3. The following note in the realloc documentation was confusing:
    /// This method makes assumptions about the layout and location of memory
    /// referenced by `AccountInfo` fields. It should only be called for
    /// instances of `AccountInfo` that were created by the runtime and received
    /// in the `process_instruction` entrypoint of a program.

I'm confused how it's even possible to call re-alloc without always satisfying these constraints.

1 Answer 1

2
  1. The transaction will fail if there's not enough lamports for the account to be rent-exempt.
  2. Yes, you can make an account smaller.
  3. This means that you should only use realloc in an on-chain program. If you use it off-chain, it will cause a segfault because of the unsafe code that it performs. Feel free to read the source code! https://github.com/solana-labs/solana/blob/1fbd818647e7e87b9c706ddb26a28572d19a44c8/sdk/program/src/account_info.rs#L147

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.