Gravitational plate of three masses and a slashed discABC0Static engraved plate. Three-dimensional view is unavailable or reduced motion is requested.

← back to fieldarticle

articleJul 31, 2022

Solana accounts model

How Solana accounts store state: data vs program accounts, PDA limits, ownership rules, rent, and the fields every account carries.

./sol.png
./sol.png

Account

Accounts are the basic building blocks for Solana programs. Each one has a unique address and holds state (data). Size is capped at 10 MB for ordinary accounts and 10 KB for PDA accounts. PDAs let a program sign on its own behalf. Size is fixed at creation but can change later with realloc. Storing data costs rent, and the default owner is the system program.

Account model

Three account kinds show up most often:

  • Data account — holds state
  • Program account — holds executable program bytes
  • Native program accounts — system, stake, and vote programs

Data account

  • System-owned account
  • PDA (program derived address) account

Account struct

Each account has an address (usually a public key) and an owner (a program account address). Fields in the account store:

FieldDescription
lamportsLamports owned by the account
ownerProgram that owns the account
executableWhether the account is executable
rent_epochNext rent epoch
dataRaw byte array stored in the account

Ownership rules

  • Only the owner of a data account can change its data or debit lamports.
  • Anyone can credit lamports to a data account.
  • When account data length becomes zero, the owner can assign a new owner.

Program accounts do not store app state

A counter program needs two accounts: one for the program code and one for the counter value. You still pay rent so the accounts are not garbage-collected.

./Solana-account-example.png
./Solana-account-example.png

Rent

Keeping data on-chain costs SOL as rent. An account is rent-exempt if its balance covers about two years of rent. Close the account and send lamports back to a wallet to recover most of that balance; a slice of collected rent is burned and the rest goes to vote accounts at epoch end. If an account cannot pay rent, it is deallocated and its data is removed.

Rent is charged in two situations:

  • when a transaction references the account
  • once per epoch

Other resources

Solana Cookbook: account model

Solana Wiki: account storage

related

  1. Jul 31, 2022/articleSolana Program Derived Addresses
  2. Jul 31, 2022/articleSolana transactions
  3. Mar 3, 2023/articleBlockchain infrastructure and consensus protocol security

graphfeed