Skip to content

Commit

Permalink
Add info about memory
Browse files Browse the repository at this point in the history
  • Loading branch information
urani-engineering authored Mar 27, 2024
1 parent 0d1f073 commit be19aa5
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 48 deletions.
87 changes: 56 additions & 31 deletions chapters/01_intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,30 +83,7 @@ Transaction fees are calculated based on two main parts:

<br>

---

### Programs

<br>

* Solana Programs are the executable code that interprets the instructions sent inside transactions on the blockchain.

* They run on top of the Sealevel runtime (Solana's parallel and high-speed processing model).
Programs are special types of accounts that are marked as "executable".

* Programs can own accounts and change the data of the accounts they own. Unlike other blockchains, they can also be upgraded by their owner.

* Programs are stateless, as the primary data stored in a program account is the compiled SBF code.

* Programs can be:
- **Native Programs**: programs built directly into the core of the Solana blockchain.
- **Chain Programs**: written by users and deployed directly to the blockchain for anyone to interact and execute. The Solana Labs also keep a library of them, the [Solana Program Library](https://spl.solana.com/).

* The instructions's `program_id` specifies which program will process the instructions.

* Programs on Solana don't store data or state between transactions: these are stored in accounts.

<br>

---

Expand All @@ -115,22 +92,26 @@ Programs are special types of accounts that are marked as "executable".

<br>

* Accounts on Solana are storage spaces that can hold data up to 10MB.
* Accounts on Solana are storage spaces that can hold data up to 10MB.

* Solana clients use an address (a 256-bit public key) to find an account.

* Accounts can hold arbitrary persistent data and hold ownership metadata for the runtime
* The metadata also includes the lifetime info and is expressed by lamports.

* Solana clients use an address (a 256-bit public key) to find an account.
* Accounts are referenced by an instruction representing the on-chain state and server as both the inputs and outputs of a program.

* Accounts can be signers if the transaction includes their addresses as a digital signature.

* Accounts can be treated as read-only by transactions. This enables parallel account processing between transactions.
* Accounts can be treated as read-only by transactions.
- This enables parallel account processing between transactions.

* An account is a program if it's marked as "executable" in its metadata.
- Accounts that store programs are owned by the `BPFLoader`, a program that can be used to deploy and upgrade other programs.
- The `BPFLoader` is owned by the **Native Loader**.

* If a program is marked as final (non-upgradeable), the runtime makes the account's data (the program) immutable.

* Accounts are referenced by an instruction representing the on-chain state and server as both the inputs and outputs of a program.

<br>

Expand All @@ -150,9 +131,54 @@ Programs are special types of accounts that are marked as "executable".

<br>



---

### Cross-Program Invocation (CPI)
### Programs

<br>

* Solana Programs are the executable code that interprets the instructions sent inside transactions on the blockchain.

* They run on top of the Sealevel runtime (Solana's parallel and high-speed processing model).
Programs are special types of accounts that are marked as "executable".

* Programs can own accounts and change the data of the accounts they own. Unlike other blockchains, they can also be upgraded by their owner.

* Programs are stateless, as the primary data stored in a program account is the compiled SBF code.

* Programs can be:
- **Native Programs**: programs built directly into the core of the Solana blockchain.
- **Chain Programs**: written by users and deployed directly to the blockchain for anyone to interact and execute. The Solana Labs also keep a library of them, the [Solana Program Library](https://spl.solana.com/).

* The instructions's `program_id` specifies which program will process the instructions.

* Programs on Solana don't store data or state between transactions: these are stored in accounts.

<br>



#### Memory on Solana

<br>


* Memory inside a Solana cluster can be thought of as a monolithic heap of data. All state lives in this heap.

* Programs each have access ot their own part of the heap.

* A memory region is "account" (and some programs own thousands of independent account)
- Each memory region has a program that manages it (the `owner`).



<br>



#### Cross-Program Invocation (CPI)

<br>

Expand All @@ -170,8 +196,9 @@ Programs are special types of accounts that are marked as "executable".


> [!IMPORTANT]
> Key information users need to know to achieve their goal.
> When writing CPI, it's important to not pull in the dependent program's entrypoint symbols (because they may conflict with the program's own). To avoid this, programs should define an `no-entrypoint` feature in `Cargo.toml`.
<br>

#### Program Derived Address (PDA)

Expand Down Expand Up @@ -200,8 +227,6 @@ Programs are special types of accounts that are marked as "executable".
* Programs can deterministically derive any number of addresses by using seeds. These seeds can symbolically identify how the addresses are used.




<br>

---
Expand Down
7 changes: 4 additions & 3 deletions chapters/02_dev_env.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@

2. Create a filesystem wallet and airdrop Solana tokens to it.

3. Write programs.
3. Write programs.
- Programs export a known `entrypoint` symbol which the Solana runtime looks up and calls when invoking a program.

4. Compile the program (down to [Berkley Packet Filter](https://solana.com/docs/programs/faq#berkeley-packet-filter-bpf) byte-code that will then be deployed to the blockchain).

Expand All @@ -50,7 +51,7 @@

<br>

* Install [Rust](https://rustup.rs/).
* Install [Rust](https://rustup.rs/) and [Yarn](https://yarnpkg.com/getting-started/install).


<br>
Expand Down Expand Up @@ -251,6 +252,6 @@ solana program deploy <PROGRAM_FILEPATH>
<br>

* [Setup local dev, by Solana Labs](https://solana.com/developers/guides/getstarted/setup-local-development)
* [Intro to Solana development (using only your browser)](https://solana.com/developers/guides/getstarted/hello-world-in-your-browser)
* [Intro to Solana development (on your browser)](https://solana.com/developers/guides/getstarted/hello-world-in-your-browser)
* [Reference for many `solana-cli` commands](https://docs.solanalabs.com/cli/examples/deploy-a-program)
* [Seahorse: Python's wrapper for Anchor framework](https://seahorse.dev/)
31 changes: 18 additions & 13 deletions chapters/03_anchor.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,25 @@

<br>

### General Guidelines
### tl; dr

<br>


* Anchor is Solana's Sealevel runtime framework, providing several convenient developer tools for writing smart contracts.
* Anchor is Solana's Sealevel runtime framework, providing several convenient developer tools for writing programs.

* Anchor writes various boilerplates, such as (de)serialization of accounts and instruction data.

* Anchor handles security checks and keeps them separated from business logic.

<br>

----

### Transactions and Accounts
### Setting up Anchor

<br>

* Your program can read and write data by sending a transaction, as programs provide endpoints that can be called by it.
* A function signature takes the following arguments:
* the accounts that the program may read from and write to during this transaction.
* additional data specific to the function.

* This design is partly responsible for Solana's high throughput. The runtime can look at all the incoming transactions of a program and can check whether the memory regions in the first argument of the transactions overlap. If the runtime sees two transactions access overlapping memory regions but only read and don't write, it can also parallelize those transactions.


<br>

Expand Down Expand Up @@ -78,13 +73,23 @@ pub struct Initialize {}
```


<br>

----

### Tests


<br>

---

### Installation
### Resources

<br>

* [Installing Anchor version manager (avm)](https://www.anchor-lang.com/docs/installation), a tool for using multiple versions of the anchor-cli.
* [The Anchor Book](https://book.anchor-lang.com/).
* [Anchor Docs](https://www.anchor-lang.com/)
* [The Anchor Book](https://book.anchor-lang.com/)
* [Developing with Rust, by Solana Labs](https://solana.com/docs/programs/lang-rust)
* [Debugging Programs, by Solana Labs](https://solana.com/docs/programs/debugging)

4 changes: 3 additions & 1 deletion demos/01_hello_world/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ solana-test-validator

<br>

* Initialize a new Rust library via Cargo:
* Either use this directory or initialize a new Rust library via Cargo:

```shell
cargo init hello_world --lib
Expand Down Expand Up @@ -56,6 +56,8 @@ solana-program = "=1.1x.x"
* At the top, we import the `solana-program` crate and bring needed items into the local namespace:

```rust
extern crate solana_program;

use solana_program::{
account_info::AccountInfo,
entrypoint,
Expand Down

0 comments on commit be19aa5

Please sign in to comment.