1

I was working on some code today, and I noticed that I couldn't reallocate an account by a difference of morethan 10KB. I reckon that I could do multiple reallocs to achieve any desired size, but given that per realloc, there is already a set limit, I am wondering whether it is a safe habit to do multiple reallocs, and why there is even the 10KB limit to start with.

thanks

         /// Maximum number of bytes a program may add to an account during a 
        single realloc
        pub const MAX_PERMITTED_DATA_INCREASE: usize = 1_024 * 10;

        // Return early if the length increase from the original serialized data
        // length is too large and would result in an out of bounds allocation.
        let original_data_len = unsafe { self.original_data_len() };
        if new_len.saturating_sub(original_data_len) > MAX_PERMITTED_DATA_INCREASE {
            return Err(ProgramError::InvalidRealloc);
        }

the code excerpt is a mixture of slivers of the Solana program.

1 Answer 1

1

Yes, it's safe to perform multiple reallocs. The per-tranasction limit is to rate-limit cluster-wide storage growth do a reasonable rate

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.