Dev/Blockchain

[Solana 이해하기] Account

TaeGit 2022. 10. 1. 18:55

Account

Solana에서 Account는 상태를 저장하기 위해 사용되며, block을 만드는 필수적인 요소입니다.

  • Account는 데이터를 저장하기 위해 사용됩니다.
  •  Account는 유일한 address를 갖고 있습니다.
  • Account는 10MB의 최대 크기를 가집니다.
  • PDA Account는 10KB의 최대 크기를 가집니다.
  • PDA Account는 program을 대표하여 서명하기 위해 사용될 수 있습니다.
  • Account 크기는 생성 시점에 고정된다. 하지만 realloc을 사용해서 조정될 수 있습니다.
  • Account 데이터 저장은 rent라는 비용이 발생합니다.
  • 기본적으로 Account 의 소유자(Owner)는 시스템 프로그램입니다.

 

Account Model

3가지 종류의 Account

  • Data Account는 데이터를 저장합니다.
  • Program Account는 실행 가능한 프로그램들을 저장합니다.
  • Native Account는 솔라나에 있는 System, Stake, Vote 같은 Native 프로그램입니다.

 

Data Account의 2가지 타입

  • System이 소유한 Account
  • PDA (Program Derived Address) Account

 

Account는 Address(보통 public key)와 Owner(프로그램 Account의 주소)를 갖고 있습니다.
Account가 저장하는 전체 필드 리스트는 아래와 같습니다.

Field Description
lamports Account가 소유하고 있는 lamport의 개수
owner Account를 소유하고 있는 Program
executable Account가 명령들(instructions)을 처리할 수 있는지 여부
data Account가 저장한 byte array 원본 데이터
rent_epoch Account가 rent를 할 다음 epoch

 

소유권에 대한 중요한 몇 가지 규칙

  • 오직 소유자만 Data Account의 데이터를 수정할 수 있고, lamports를 인출할 수 있습니다.
  • 누구나 Data Account에 lamports들을 입금할 수 있습니다.
  • Account의 소유자는 이 Account의 데이터가 비어있다면 새로운 소유자에게 이 Account를 할당할 수 있습니다.

 

Program Account는 상태를 저장하지 않습니다.

예를 들어, 만약 counter를 증가시킬 수 있는 counter program을 가지고 있다면, 두 개의 Account를 생성해야합니다.
하나는 Program의 Code를 저장하는 Account, 다른 하나는 counter 데이터를 저장하는 Account입니다.

Account가 삭제되는 것을 막기 위해서는 rent를 지불해야 합니다.

 

 

Rent

Account에 데이터를 저장하는 것은 메인 넷에 SOL 비용이 발생합니다.

그리고 그 비용은 rent라고 불리는 것에 의해 지불됩니다.

 

만약 한 Account에 2년 치의 rent 지불과 동등한 최소한의 balance를 유지한다면, Accountrent를 지불하는 것이 면제됩니다. Account 사용을 마치면 rent를 되찾을 수 있고 lamports를 지갑에 보낼 수 있습니다.

 

Rent 지불 시점.

  1. transaction에 의해 참조될 때
  2. 매 epoch시

 

나머지 rent가 매 slot의 마지막에 Account들을 투표하기 위해 분배되는 동안, Account에 의해 수집된 Rent의 비율은 파괴됩니다.

 

만약 Accountrent를 지불하기 위한 충분한 lamports를 갖고 있지 않다면, Account는 할당 해제되며 데이터는 지워질 것입니다.

 

새로운 Account들은 rent가 면제되도록 해야 한다는 것이 중요합니다.

 

 

 

이 글은 아래 참고 자료를 번역한 내용입니다.

References

 

Cooking with Solana | Solana Cookbook

Cooking with Solana The Solana Cookbook is a developer resource that provides the essential concepts and references for building applications on Solana. Each concept and reference will focus on specific aspects of Solana development while providing additio

solanacookbook.com