Overview
Theaccount_resize syscall changes the data storage size of an account. This can be used to expand or shrink the accountโs data capacity.
Syscall Code
Code:0x07 (TN_SYSCALL_CODE_ACCOUNT_RESIZE)
C SDK Function
Arguments
Index of the account to resize. Must be writable by the current program.
New data size for the account in bytes. Must not exceed maximum account data size.
Return Value
Returns a syscall result code:TN_VM_SYSCALL_SUCCESS(0) - Account resized successfully
TN_VM_ERR_SYSCALL_INVALID_ACCOUNT_INDEX(-7) - Account index out of boundsTN_VM_ERR_SYSCALL_ACCOUNT_DOES_NOT_EXIST(-8) - Account does not existTN_VM_ERR_SYSCALL_ACCOUNT_NOT_WRITABLE(-26) - Account not writable by current programTN_VM_ERR_SYSCALL_ACCOUNT_TOO_BIG(-11) - New size exceeds maximum allowedTN_VM_ERR_SYSCALL_INSUFFICIENT_PAGES(-25) - Not enough pages available for expansion
Resource Consumption
Compute Units
- Base cost:
TN_VM_SYSCALL_BASE_COST(512 units) - Additional cost: None (size changes donโt directly affect compute cost)
- Total cost: Fixed at 512 units regardless of new size
Memory Pages
- Page allocation: New pages allocated from transaction pool when expanding
- Page deallocation: Excess pages returned to transaction pool when shrinking
- Page granularity: Account data is managed in page-sized chunks
- Minimum allocation: Account metadata always requires at least one page
Side Effects
- Data size: Changes the accountโs data size to the specified value
- Memory allocation: Allocates or frees pages as needed
- Metadata: Makes account metadata and data writable if not already
- Data preservation: Existing data is preserved when expanding
Usage Notes
- The new size must not exceed
TN_ACCOUNT_DATA_SZ_MAX - When expanding: additional space is allocated and initialized
- When shrinking: excess data is truncated and pages may be freed
- If new size equals current size, the syscall succeeds immediately
- Account must be writable by the current program
- Sufficient pages must be available in the transactionโs page pool
Memory Management
- Expansion: Allocates additional pages from the transaction page pool
- Shrinking: May free pages back to the pool (implementation dependent)
- Page alignment: Account data is managed in page-sized chunks
- Data preservation: Existing data within the new size is preserved