Solana Core

 

by Heavy Duty Builders & Solana Bootcamp

I'm J.D. Nicholls 👋

- Open Source Contributor 👨‍💻

- Game developer (Hobby) 🎮

- Developer who loves UX 💫

- Chocolate lover 🍫

- Founding Full-Stack Engineer 👷

AT

BAXUS

Why Solana?

Solana has low gas fees, it's really fast...

- Scales natively with Moore's Law

- Great Nakamoto Coefficient of decentralization

Accounts

Smart contracts on Solana, referred to as "programs", are stateless - meaning they don't store anything except code. Everything happens in accounts, so they're central to Solana, they're used for storage, contracts, and for native blockchain programs.

The program itself doesn't hold a user's data. The program just talks to "accounts" that hold the user's data.

⬇️

Types of accounts

- Data

These accounts store data:

  • System owned accounts.
  • PDA (Program derived address) accounts.

- Program

These accounts store executable programs (AKA smart contracts).

- Native

These accounts are for core blockchain functions like Stake, Vote, etc.

⬇️

Account Types

Non-executable Accounts

STORE DATA

Executable Accounts

STORE USER PROGRAMS

STORE NATIVE PROGRAMS

User programs are created by us, and they can be updated by the authority of the program.

⬇️

(State of a Program)

Account Fields

FIELD DESCRIPTION
lamports The # of lamports owned by this account
owner The program owner of this account
executable Whether this account can process instructions (is executable)
data The raw data byte array stored by this account
rent_epoch The next epoch that this account will owe rent

Iamports are the smallest unit of Solana:

1 Iamport = 0.000000001 SOL

⬇️

Account Structure

  • Unique 256-bit address
  • Hold some balance of SOL
  • Can store arbitrary data
  • Data storage is paid with Rent
  • Anyone can credit SOL or read data
  • Only the account’s owner can debit SOL or modify data
{
  key: number,            // The address of the account
  lamports: number,       // Lamports currently held
  data: Uint8Array,       // Data stored in the account
  is_executable: boolean, // Is this data a program?
  owner: PublicKey,       // The program with write access
  rent_epoch: number,     // System checks whether an account needs to pay rent
}

Accounts are...

Iamports defines how much SOL the account has 💰

⬇️

Account in Solana

lamports
owner
executable
data
rent_epoch

AccountInfo

Public Key (Address)

Account

Each account is identifiable by its unique address (Public Key). Based on the size of that arbitrary data (Max 10 mb), a user is required to pay some value of SOL for what’s called "Rent".

Programs

Smart contracts on Solana are called programs;

A Solana program is just a piece of code that lives on the blockchain. The blockchain is a place where anyone can run code for a fee and it's being run by miners, in the world of Solana we actually call them validators.

 

 

 

Programs characteristics:

- Special kind of account

- Data is eBPF bytecode

- Written in Rust, C/C++, Python

⬇️

Deep in Programs

  • Accounts can also store executable programs
  • Programs are stateless, they read & write data to other accounts. This allows programs to be executed in parallel.
  • Must be the owner of an account to modify
  • Programs process instructions
  • Programs can send instructions to other programs

⬇️

Types of programs

ON-CHAIN
PROGRAMS

NATIVE
PROGRAMS

- Can only be updated by the authorized account.

- Developed by users

- Can only be updated through network upgrades.

- Integrated into Solana's core.

⬇️

Native programs are integral to effectively managing accounts and deploying executable code on the Solana blockchain.

On-chain programs are custom programs deployed on the Solana Network through executable accounts.

Native Programs

BPF LOADER

SYSTEM PROGRAM

- Create accounts

- Transfer funds

- Assign Account Ownership

- Allocate Space for Data Accounts

- Account Closure

Basic account management operations:

Deploying and managing executable programs:

- Deploy Programs

- Execute Programs

- Upgrade Programs

- Initialize Program Data

Initial owner of new accounts

⬇️

Manage programs created by users

Program Structure

data
owner: BPF Loader
executable: true
lamports

AccountInfo

Public Key (Address)

Program ID

Account Data

Program Code

⬇️

A Solana program uses a unique identifier (Program ID) for invocation and interactions. AccountInfo contains metadata about interacting accounts, and the Account Data stores various types of state information crucial to the program's logic.

Executable Program

data
owner: BPF Loader
executable: true
lamports

AccountInfo

BPF Loader

Account Data

Program Code
Program Account

owner

Address

data
owner: Program
executable: false
lamports
Program State
Data Account

owner

Address

Instructions

Memory (variables and configurations)

When a executable program is created, two default accounts are involved

Program instructions

{
  program_id: number,           // The program this instruction is for
  keys: Array<{                 // Accounts involved in the instruction
    key: PublicKey,
    is_mutable: boolean,        // Defines if the account is mutable
    is_signer: boolean,
  }>,
  data: Uint8Array,             // Serialized code (action to perform) + args
}

Program Instructions are the commands that tell a program what actions to perform. They define what operations need to be performed, which accounts are involved and what specific data is required to execute the program logic.

Transactions

Transactions allows to send an instruction to a Solana program. Transactions send a package of "instructions" to an RPC client, which then forwards it to the network

  • Programs are invoked by instructions.
  • Instructions are sent via transactions.
  • Transactions are atomic.
  • Transactions must be signed.
{
  message: {
    instructions: Array<Instruction>,
    recent_blockhash: number,
    fee_payer: PublicKey,
    ...
  },
  signers: Array<Uint8Array>,
}

NFTs

The Metadata Standard on Solana introduces countless ways to customize NFTs and the user’s experience.

  • Are SPL Tokens
  • Have 0 decimal places
  • Have a total supply of 1
  • Can have highly-customizable metadata
  • A Collection is a NFT as well

SPL Tokens

Token standard used for creating custom (fungible and non-fungible) tokens like USDC, USDT, etc with a supply and use those tokens in our programs.

SPL tokens simply need instructions sent to the Token Program to create and mint tokens, making the process more efficient and cost-effective compared to Ethereum's ERC-20 tokens.

Useful commands

# Verify installed versions
solana --version
solana-keygen --version

⬇️

Verify Installed versions

# Verify current configuration
solana config get

# Change RPC url to connect to different clusters in Solana ecosystem
solana config set --url https://api.devnet.solana.com
solana config set --url https://api.mainnet-beta.solana.com
# Local machine
solana config set --url localhost

Change Current Configuration

- devnet: playground for developers and validators to use the same release of mainnet

- testnet: for solana core contributors to test recent releases and features

Solana Clusters

# Generate a new wallet (key-pair)
solana-keygen new
# saved from $HOME/.config/solana/id.json

# Override current key-pair
solana-keygen new --force

# Get the pubkey of the current wallet
solana-keygen pubkey

Manage Authentication (cryptographic key pairs)

# Check the balance of solana tokens of the current wallet
solana balance

# Request new tokens to the current wallet (try a lower amount if fails)
solana airdrop 0.5

# Transfer tokens to a different wallet with a custom amount
solana transfer "TARGET WALLET ADDRESS" 0.2
# if the target wallet is new (not funded yet), you can use the below command
solana transfer "TARGET WALLET ADDRESS" 0.2 --allow-unfunded-recipients

Save the seed phrase and BIP39 passphrase to recover your new keypair 🔐 (ProtonPass, 1Password, etc)

Manage Tokens

# Starts a full-featured, single-node cluster on the developer's workstation
solana-test-validator

# Configure cli tool suite to target the local cluster
solana config set --url http://127.0.0.1:8899

# Verify the cli tool suite config
solana genesis-hash

# Disable runtime features
solana-test-validator --deactivate-feature <FEATURE_PUBKEY_1>

Manage Anchor projects

# Create and initialize a new project with Anchor
anchor init <project-name>

# Compile your project (use the same anchor version of the project in your machine)
anchor build

# Get the list of IDs (addresses) of your programs in your Anchor project
anchor keys list

# Run program tests
anchor test

FAQ

What mechanism does Solana use to synchronize local virtual clocks on all nodes? 

Proof-of-History (PoH)

What's the nature of PoH for production and verification?

PoH is difficult to produce but easy to verify.

When considering TBFT in Solana, what is the approximate time duration for one slot?

Every 400ms, a new potential rollback point occurs in the Solana network due to the slot duration

In the context of Solana's TBFT, what action takes place when a leader seems to have failed?

Another node attempts to take his place by initiating an election process

⬇️

What does Turbine aim to reduce by utilizing a smart block propagation protocol?

Time needed for block propagation

How are nodes in the network organized in the Turbine protocol?

Into neighborhoods; nodes within a particular neighborhood in the Turbine protocol are responsible for sharing received data with other nodes in the same neighborhood.

How is propagation priority determined in Turbine?

Stake-weighted selection algorithm. This algorithm prioritizes propagation based on the amount of stake validators hold in the network. Validators with higher stakes are placed closer to the current leader for efficient data sharing.

⬇️

What does Gulf Stream serve as in Solana?

A mempool-less solution for forwarding and storing transactions before processing.

What is the primary role of the mempool in traditional blockchains?

Store transactions being broadcasted but not yet processed.

Why can Solana execute transactions in parallel?

Each Solana transaction describes all the states required to read and write to, enabling non-overlapping instructions to be executed simultaneously.

Why did the Solana team develop the Transaction Processing Unit (TPU)?

To validate and execute transactions quickly before receiving another block. It ensures efficient processing of transactions to maintain the network's speed and performance.

⬇️

What are the pipeline stages of the TPU?

- Data fetch in kernel space via network card (I/O).

- Signature verification using GPU

- Change of the state using CPU (banking).

- Write to the disk in kernel space and send out via network card (I/O).

What becomes a bottleneck after achieving fast computation in blockchain systems?

The memory becomes a bottleneck due to the limitations of storing everything in RAM

How does Cloudbreak handle data storage?

It makes use of memory-mapped files.

How is data integrity ensured among the specialized network nodes?

By splitting into small pieces and replicating the data multiple times.

Questions?

Resources

- Solana Developer Guides

- Solana Devnet Faucet

- Solana Whitepaper

Community

- Ackee Solana Handbook 

- Shyft, full-suite Solana Development Experience

Made with Slides.com