English
 找回密码
 立即注册

Getting Started with Solana (3)

Anatoly 2025-11-24 08:57 21434人围观 SOL

The humble room was empty, but the bed was full of wats; Withered grass and withered poplars, it was once a singing and dancing venue. Spider silk is covered with carved beams, and green gauze is now stuck on the canopy windows. It is said that the fat is
The humble room was empty, but the bed was full of wats. ; Withered grass and withered poplars, it was once a singing and dancing venue. Spider silk is covered with carved beams, and green gauze is now stuck on the canopy windows. It is said that the fat is thick and the powder is fragrant, how can the temples become frost again? Yesterday there were bones in the loess; tonight there are mandarin ducks under the red light tent. The box is full of gold, the box is full of silver, and in a blink of an eye, beggars are slandered by everyone. I was sighing that others would not live long, but I didn't know that I would be mourned when I returned! If you train well, you can't guarantee that you will be a strong leader in the future. Who chooses to live in Fireworks Alley? Because I thought the gauze hat was too small, I had to carry the shackles. Yesterday I felt sorry for the coldness of my broken coat, but now I think the purple python is too long. Luan Hengheng, you just finished singing and I came on stage, but I thought that the foreign country was my hometown. It’s so ridiculous. In the end, it’s all about making wedding clothes for others.

2. Solana account structure

  • Similar to "everything is a file" in Unix-like systems, almost "everything is an account" in Solana”



The wallet account is on the left, and its owner is System Program (From: https://www.quicknode.com/guides/solana)



Use SolanaScan to query wallet accounts

  • Wallet account, also known as System-owned Account, ordinary account, key pair account, etc.
    • Account rent is redeemable (Reclaimable)
    • Transfers that attempt to reduce Lamport below Rent will fail.
    • A transaction that directly reduces Lamport to 0 will succeed, which means the account will be destroyed, and Rent will be redeemed at this time.
    • Lamports: Token balance owned by the account; This balance is less than the actual balance held by the account because a portion of the rental fee (Rent) is deducted
    • Owner: Specify the Ownership of the account; The owners of all wallet accounts are System Program
    • Executable (Boolean): Identifies whether the account is executable; Wallet account is No, Program account is Yes
    • Data: Data maintained by the account; In wallet accounts, Data is generally customized by the account creator. ; In the Program account, Data is the index of sBPF bytecode
    • System Program belongs to Native System Account
    • Its address/ID is fixed to an all-one string of length 32
    • Uniquely controlled by the public key and private key pair defined on the elliptic curve Ed25519; Similar to Ethereum and Bitcoin, the public key is the unique index/ID/address of the account
    • The corresponding account information is abstracted into the AccountInfo structure, including the following keywords
    • The reason for the rental fee is that the corresponding status of any account will be maintained in its local memory (Memory) by the Validator, resulting in a fee



Program Account and its PDA

  • Program account, the “smart contract” in Solana”
    • This data account is a PDA, and its owner is the Program from which the account is derived.
    • Similar to program accounts, data accounts do not have private keys.
    • There is a special field Update Authority in the data account, which indicates which account has the authority to upgrade the Program, which is usually the wallet account address where the Program is deployed.
    • BPF Loader v1: only supports static, non-updatable Program and has been deprecated
    • BPF Loader v2: a simplified version of v1
    • BPF Loader Upgradeable: The currently used BPF Loader version supports updatable programs.
    • BPF Loader v4: Simplify the current version of the dual-account model into a single-account model
    • Similar to wallet accounts, program accounts are uniquely indexed by Program ID; Unlike wallet accounts, program accounts do not have private keys
    • Similar to wallet accounts, program account information also has Lamport, Data, Owner, and Executable fields.; Among them, Owner is BPF Loader Upgradeable and Executable is Yes. ; In Solana, BPF Loader includes four versions, namely:
    • The program account is stateless, that is, it only processes the data contained in the instruction and does not maintain/track changes in the related account status.
    • The Data data field should store the corresponding sBPF bytecode; In fact, Solana adopts a proxy mode, which maintains sBPF bytecode through a dedicated data account and only stores the corresponding address in the Data domain.



Use Solanascan to view Program Account and its PDA



Accounts involved in Solana token issuance and their relationships

  • Solana uses Token Program, Mint Account and Token Account to implement token functions
    • Token Program implements core functions necessary for ERC-20 tokens such as mint, burn, and transfer. Its owner is BPF Loader.



Mint Account



Solana token issuance involves subordination and reference relationships between accounts

  • Mint Account is used to maintain metadata for specific tokens
    • Supply: Total amount of issued tokens
    • Mint Authority: Which addresses are authorized to issue new tokens
    • Freeze Authority: Which addresses are authorized to freeze tokens
    • Decimals: The decimal precision of the smallest divisible unit of the token (if Decimals=4, then storing 10000 means one token)
    • A Mint Account corresponds to a type of token. The so-called issuing tokens in Solana is to create the corresponding Mint Account through the Token Program.
    • Mint Account is a type of PDA whose Owner is Token Program and Executable is No.
    • In addition to Owner, Lamport, and Executable, its maintenance metadata includes
    • It should be noted that unlike the ERC-20 token contract on Ethereum, the Mint Account in Solana does not have a Maximum Supply field.; In Solana, the maximum supply of tokens is limited by removing authorization ; Specifically, when the token issuance reaches the expected amount, the token issuer will empty Mint Authority, that is, no one will be allowed to issue tokens anymore, thereby setting the current total token issuance as the supply limit. ; During this process, the token issuer will be maintained in the Update Authority field by Mint Account.

  • Token Account is used to track which accounts hold how many tokens of a specific type.
    • Mint: points to the Mint Account account, indicating the token type
    • Owner: Specify the owner of the token; It should be noted that the Owner here is not the Owner in the programming sense (that is, the relationship between Wallet Account and System Program), but refers to the Authority, or the Owner in the real sense.
    • Amount: number of tokens
    • Token Account is also a type of PDA. Its Owner is Token Program and Executable is No.
    • Token Account contains the following keywords
    • In Solana, a user can own multiple different tokens at the same time, that is, one wallet account can be associated with multiple different Mint Token Accounts.
    • In Solana, for a specific token, the token balance controlled by the user can be stored in multiple different Token Accounts of the same Mint. As a result, when other users initiate transfers, it is not clear which Token Account of the user should be selected as the receiving address.



ATA

  • Associated Token Account (ATA) is used to solve the above problems



    ATA Program
    • Mint: Specify the token type
    • Owner: Indicates the actual owner of the token (actually Authority)
    • Amount: Token balance
    • State: Token status, which is an enumeration (Enum) type, including Uninitialized, Initialized, and Frozen
    • Delegated: Which accounts are authorized to perform transfer operations on behalf of the Owner; It should be noted that in Ethereum, delegated addresses are a list, which means that the owner can approve multiple delegated accounts ; However, in Solana, only one delegated account is allowed to exist
    • Delegated Amount: The upper limit of the token balance at the delegator’s disposal
    • Close_Authority: Which accounts are authorized to close ATA and redeem Rent; It can be either the Owner or another address.

    • For a specific user, ATA will centralize the balance of tokens of the same type owned by the user into a unique Token Account (i.e. ATA)

    • ATA is also a special kind of PDA; For the target token recipient, any transfer initiator can calculate its corresponding ATA address deterministically in advance, that is, ,in is the target wallet account address, Mint Account address indicating the token type

    • ATA contains the following keywords



Generate the process corresponding to ATA based on ATA Program

  • Before the token sender (Bob) transfers money to the target recipient (Alice), he cannot confirm whether the corresponding ATA exists.; If it does not exist, the transfer fails. ; Therefore, Bob needs to confirm whether Alice's ATA exists before transferring money. ; If it does not exist, Bob creates the corresponding ATA.
    • In Ethereum, how many tokens Alice and Bob know are maintained in the token contract in the form of mapping. If Alice does not exist in the mapping, just add the corresponding Key-Value Pair.; Different from Ethereum, in Solana, the balances of Alice and Bob are explicitly recorded in their respective ATA, so the existence of the ATA must be ensured.
    • The ATA Program is responsible for confirming (Find) or creating (Create) the corresponding ATA based on the entered wallet account and Mint Account.
    • Similar to Token Program, the owner of ATA Program is also BPF Loader
    • The ATA Program itself cannot create an account. It can only generate the corresponding ATA address based on the wallet account and Mint Account, and then through cross program invocation (CPI), entrust the System Program to create an empty account containing the corresponding ATA data, and set its owner to Token Program; Finally, the account is initialized to ATA through Token Program
    • It should be noted that since Alice's ATA was created by Bob, Bob may set the keywords in the ATA, such as Delegated and Close_Authority, to himself.; To avoid the above problems, Solana has added additional security guarantees, that is, the ATA Program forces Delegated and Close_Authority to be set to Alice’s wallet address.

3. Solana transaction data structure




Solana transaction basic data structure
  • Solana transactions include Signature and Message



Solana Message data structure
  • A message includes
    • Header: Used to describe the role of the accounts involved in the transaction, including which accounts to read data from, which accounts to write data to, which accounts the transaction is signed by, etc.
    • Compact Array of Account Addresses: All accounts involved in the transaction; Cooperating with Header to implement Upfront Account Declarations is the key technology for Solana to achieve high parallelism and Local Market Fee.
    • Recent Blockhash: equivalent to the timestamp of the transaction, used to identify the freshness of the transaction; Premature transactions will be judged as expired and abandoned by the Solana node. ; Currently, the expiration time of a transaction is generally 150 Slots
    • Compact Array of Instructions: list of instructions, used to call Program



Solana InstructionData Structure
  • An instruction includes
    • Program ID: Specify the Program to be called
    • Compact Array of Account Address Indexes: Specify the list of accounts involved in the execution of this command; It should be noted that this is not the original account address, but all the addresses of the accounts involved in the instruction in the Message account list.
    • Compact Array of Opaque Data: parameters required to call this command

Reference

  • https://blocksec.com/blog/solana-simplified-master-solana-core-concepts-in-one-read
  • https://blocksec.com/blog/solana-simplified-02-writing-your-first-solana-smart-contract-from-scratch
  • https://blocksec.com/blog/solana-simplifed-03-understand-solana-transactions-in-5-minutes
  • https://explorer.solana.com/address/9wQQZPeLjnPQhMURKdEX3xFgiVqPPt9oBRD35BWDvHa3?cluster=devnet
  • https://faucet.solana.com/
  • https://app.blocksec.com/explorer/tx/solana/byRn8qtNAYSdvgaGCK4kmZV1m89b7uuFuy1cn96W6femp7WgwymLqJ2MP9hPbegqN9EPe7NvghWpqDFqoCDjKph
  • https://beta.solpg.io/
  • https://rareskills.io/post/spl-token
  • https://rareskills.io/post/solana-instruction-introspection
  • https://rareskills.io/post/solana-sysvar
  • https://www.helius.dev/blog/proof-of-history-proof-of-stake-proof-of-work-explained
  • https://www.helius.dev/blog/solana-executive-overview#consensus
  • https://www.helius.dev/blog/how-to-land-transactions-on-solana#how-are-transactions-processed
  • https://www.helius.dev/blog/solana-nodes-a-primer-on-solana-rpcs-validators-and-rpc-providers#solana-node-requirements
  • https://www.quicknode.com/guides/solana
  • https://www.helius.dev/blog/the-solana-programming-model-an-introduction-to-developing-on-solana
  • https://www.helius.dev/blog/solana-gulf-stream
  • https://4pillars.io/en/articles/make-svm-great-again
  • https://www.helius.dev/blog/turbine-block-propagation-on-solana



精彩评论0
我有话说......
TA还没有介绍自己。