diff --git a/chapters/01_intro.md b/chapters/01_intro.md index 5b828d0e..10a0d3cc 100644 --- a/chapters/01_intro.md +++ b/chapters/01_intro.md @@ -83,30 +83,7 @@ Transaction fees are calculated based on two main parts:
---- - -### Programs - -
- -* 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. - -
--- @@ -115,22 +92,26 @@ Programs are special types of accounts that are marked as "executable".
-* 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.
@@ -150,9 +131,54 @@ Programs are special types of accounts that are marked as "executable".
+ + --- -### Cross-Program Invocation (CPI) +### Programs + +
+ +* 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. + +
+ + + +#### Memory on Solana + +
+ + +* 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`). + + + +
+ + + +#### Cross-Program Invocation (CPI)
@@ -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`. +
#### Program Derived Address (PDA) @@ -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. - -
--- diff --git a/chapters/02_dev_env.md b/chapters/02_dev_env.md index f0543803..bfa96422 100644 --- a/chapters/02_dev_env.md +++ b/chapters/02_dev_env.md @@ -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). @@ -50,7 +51,7 @@
-* Install [Rust](https://rustup.rs/). +* Install [Rust](https://rustup.rs/) and [Yarn](https://yarnpkg.com/getting-started/install).
@@ -251,6 +252,6 @@ solana program deploy
* [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/) diff --git a/chapters/03_anchor.md b/chapters/03_anchor.md index 5690f1a5..58f72317 100644 --- a/chapters/03_anchor.md +++ b/chapters/03_anchor.md @@ -2,30 +2,25 @@
-### General Guidelines +### tl; dr
-* 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.
---- -### Transactions and Accounts +### Setting up Anchor
-* 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. -
@@ -78,13 +73,23 @@ pub struct Initialize {} ``` +
+ +---- + +### Tests + +
--- -### Installation +### Resources
-* [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) + diff --git a/demos/01_hello_world/README.md b/demos/01_hello_world/README.md index 43a477fd..7414635c 100644 --- a/demos/01_hello_world/README.md +++ b/demos/01_hello_world/README.md @@ -11,7 +11,7 @@ solana-test-validator
-* 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 @@ -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,