2

I am learning about Solana's account model. So far so good, these are the things I have found:

  • Solana account is represented by the AccountInfo struct and whose structure is basically this:
pub struct AccountInfo<'a> {
    pub key: &'a Pubkey,
    pub is_signer: bool,
    pub is_writable: bool,
    pub lamports: Rc<RefCell<&'a mut u64>>,
    pub data: Rc<RefCell<&'a mut [u8]>>,
    pub owner: &'a Pubkey,
    pub executable: bool,
    pub rent_epoch: Epoch,
}
  • I understand that the key property is known as the holder of the account. This is basically the public key that can run the account.

  • I understand that the owner property is known as the owner of the account. By default, it corresponds to the Solana’s System Program. This is the entity that has the ability to update both the lamports and data field.

Now my exploration has led me to the Solana program library, and in the definition of Account I see the following definition:

pub struct Account {
    /// The mint associated with this account
    pub mint: Pubkey,
    /// The owner of this account.
    pub owner: Pubkey,
    /// The amount of tokens this account holds.
    pub amount: u64,
    /// If `delegate` is `Some` then `delegated_amount` represents
    /// the amount authorized by the delegate
    pub delegate: COption<Pubkey>,
    /// The account's state
    pub state: AccountState,
    /// If is_some, this is a native token, and the value logs the rent-exempt reserve. An Account
    /// is required to be rent-exempt, so the value is used by the Processor to ensure that wrapped
    /// SOL accounts do not drop below this threshold.
    pub is_native: COption<u64>,
    /// The amount delegated
    pub delegated_amount: u64,
    /// Optional authority to close the account.
    pub close_authority: COption<Pubkey>,
}

The part that is not clear is what exactly is the owner field? and how is it different and interplay with the owner field on the AccountInfo struct?

2 Answers 2

3

On solana everything is an 'account'.

Your question: what's the 'owner' field for? From PencilFlip:

The address of the program that owns the account. Only the owning program is capable of modifying the account.

So you would set either your 'wallet-account' or the 'program-account' which should have control over that account to modify it.

1
  • This is a good answer but the last sentence is hard to understand. "you would set either your 'wallet-account' or the 'program-account'" - where would you set them? And set them to what? Can you please edit the answer to make this clearer?
    – mikemaccana
    Apr 2 at 20:46
0

On Solana, there is no definite answer to what an account owner should be.

Basically, when an account is created, its default owner is the System program, the one with a lot of 1s in its address. One such example is your "wallet" account.

In other cases, you can assign your wallet account as an "owner" to other accounts, so that you can modify it later. For example, a program account, which hosts an on-chain program; Or a token account, which holds tokens in your wallet; In this case, the owner of the token account is your wallet.

You can learn more about different types of accounts [here][1].

1
  • I think what you are describing is not what is going own. In the question I asked, the owner is not being changed. What I think is going on is this: By default an account has an holder (who can sign transaction to modify the account) and an owner, the program that actually has the power to process the instructions in the signed transactions. The owner has the ability to update the data field and the lamport field. In the case of the token program, the owner, instead of using the holder, it uses transactions that emanates from another owner it sets in a user level field defined in data.
    – dade
    Sep 5, 2022 at 10:36

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.