Solana SVM, modularized.

Overview

The Case for a Modular SVM

An effort is underway at Anza to extract most of the transaction processing pipeline out of the validator and into what will be known as the Solana Virtual Machine (SVM).

solana-labs/solana#34196

anza-xyz/agave#389

Although the official specification of this standalone SVM is still in development, it's important that we get this right.

An isolated SVM would be a transaction processing pipeline that can operate independent of any validator. Validators would then run some implementation of an SVM, and brand-new services could be built on top of custom SVM-compatible engines.

Why is a Modular SVM Important?

Having a decoupled SVM with its own well-defined interface unlocks the ability for teams to build custom SVM implementations, including:

  • SVM rollups
  • SVM sidechains
  • SVM-based off-chain services

Solutions like these can make Solana more performant and more reliable, as well as expand the landscape of possible products and services that can be built within its ecosystem.

👉 But let's push the envelope. Imagine if we engineered this new isolated SVM to be an assembly of entirely independent modules. Any SVM implementation could simply drive these modules through well-defined interfaces.

This further disintegrates the barriers to SVM-compatible projects by requiring significantly less overhead to architect custom solutions. Teams could simply implement the modules they care about while using already established implementations for the others (such as those from Agave or Firedancer).

How Do We Get There?

We must take this opportunity to break away from library patterns that have plagued both core and protocol developers for a long time. Some of these issues include:

  • High-level libraries depending on low-level libraries for simple things such as types.
  • Tightly-coupled libraries using each other's objects instead of interfaces and adapters.
  • Metrics-capturing strands wired from the highest-level packages all the way to the lowest-level.

The modularity goals outlined in the previous section can be obtained by remedying these issues. Some suggested solutions are as follows:

  • Leverage lean, low-level type packages.
  • Differentiate between interfaces and implementations.
  • Connect implementations using interface adapters.
  • Bake metrics into the specification.

About This Repository

This repository seeks to demonstrate the concepts above by offering two groups of crates:

  • solana: The specification-based crates for types and interfaces, to be used by implementations.
  • agave: Anza's Agave client implementations of the solana specifications.

The solana-runtime specification (grossly over-simplified here) details a runtime that makes use of an SVM. However, notice that this is all done with interfaces.

/// The Solana Validator Runtime.
pub trait ValidatorRuntime<TB: TransactionBatch, TP: TransactionBatchProcessor> {
/// Get the batch processor.
fn batch_processor(&self) -> &TP;
/// Load and execute a batch of transactions.
fn load_and_execute_transactions(&self, batch: &TB) -> LoadAndExecuteTransactionsOutput;
}
/// A batch of Solana transactions.
pub trait TransactionBatch {
/// Get the sanitized transactions.
fn sanitized_txs(&self) -> &[SanitizedTransaction];
}
/// The output of the `load_and_execute_transactions` method.
pub struct LoadAndExecuteTransactionsOutput {
pub loaded_transactions: Vec<TransactionLoadResult>,
pub execution_results: Vec<TransactionExecutionResult>,
pub retryable_transaction_indexes: Vec<usize>,
pub executed_transactions_count: usize,
pub executed_non_vote_transactions_count: usize,
pub executed_with_successful_result_count: usize,
pub signature_count: u64,
}

Meanwhile, the Agave runtime is now an implementation (agave-runtime), and it simply implements the solana-runtime interface, but without specifying a specific SVM implementation.

/// The Agave Validator Runtime.
pub struct AgaveValidatorRuntime<BP: TransactionBatchProcessor> {
/// SVM-agnostic batch processor.
pub batch_processor: BP,
}
/// Agave Validator Runtime Base Implementation.
impl<'a, BP: TransactionBatchProcessor> ValidatorRuntime<AgaveTransactionBatch<'a>, BP>
for AgaveValidatorRuntime<BP>
{
fn batch_processor(&self) -> &BP {
&self.batch_processor
}
/// Load and execute a batch of transactions.
fn load_and_execute_transactions(
&self,
_batch: &AgaveTransactionBatch,
) -> LoadAndExecuteTransactionsOutput {
/*
* MOCK.
*/
let _batch_processor = self.batch_processor();
//
LoadAndExecuteTransactionsOutput {
loaded_transactions: vec![],
execution_results: vec![],
retryable_transaction_indexes: vec![],
executed_transactions_count: 0,
executed_non_vote_transactions_count: 0,
executed_with_successful_result_count: 0,
signature_count: 0,
}
}
}

The beautiful thing here is that any SVM could easily be plugged into Agave's runtime implementation. Anyone could configure an Agave node, then write an adapter for some other SVM implementation and plug it in right here.

// This is a grossly over-simplified demonstration of an adapter, bridging the
// SVM-agnostic Agave runtime implementation with the Agave SVM implementation.
// Ideally, this would instead manifest as some module that could be easily
// replaced if another SVM implementation were to be used.
type Svm<FG> =
AgaveTransactionBatchProcessor<AgaveValidatorRuntimeTransactionProcessingCallback, FG>;
/// A mock Agave Validator.
pub struct AgaveValidator<FG: ForkGraph> {
pub runtime: AgaveValidatorRuntime<Svm<FG>>,
}

🔑 🔑 A huge advantage with this arrangement is the fact that consensus-breaking changes would reside in the specification-level, guarded by SIMDs, while developers could more freely adjust implementation-level code and ship new versions without worrying about partitioning the network.

Other important notes:

  • This demo uses lightweight "leaf node" crates for types (ie. solana-compute-budget).
  • Some leaf node crates are specification-wide (ie. solana-compute-budget) while others are implementation-specific (ie. agave-program-cache).
  • Although metrics are not demonstrated here (yet), the idea is that they would reside in one's implementation, and be vended back up to the callers.
You might also like...
🕶 Assorted checks and validations for writing safer Solana programs.
🕶 Assorted checks and validations for writing safer Solana programs.

vipers 😎 Assorted checks and validations for writing safer Solana programs. Motivation Solana's fee mechanism is unlike Ethereum's, in that the numbe

⛏ An open protocol for launching liquidity mining programs on Solana.
⛏ An open protocol for launching liquidity mining programs on Solana.

⛏ Quarry An open protocol for launching liquidity mining programs on Solana. Background Quarry was built with the intention of helping more Solana pro

The Voting example based on MoonZoon and Solana.
The Voting example based on MoonZoon and Solana.

Voting example The Rust-only Voting example based on MoonZoon and Solana. MoonZoon is a Rust Fullstack Framework. Solana is a decentralized blockchain

A framework for creating PoC's for Solana Smart Contracts in a painless and intuitive way

Solana PoC Framework DISCLAIMER: any illegal usage of this framework is heavily discouraged. Most projects on Solana offer a more than generous bug bo

Repo for Monaco, a DCA engine for Solana. Built on Solend and lending protocols (Jet, Solend, Port, etc...)
Repo for Monaco, a DCA engine for Solana. Built on Solend and lending protocols (Jet, Solend, Port, etc...)

Monaco Monaco is a DCA protocol for solana built on top of Serum and compatible with any program that implements or extends the instruction interface

Command line interface for Solana Metaplex programs.

Metaplex Command Line Interface This is a command line interface for creating and managing non-fungible tokens on the Solana blockchain through the Me

Generate Nice Solana Address By Template

Yes, I know about GPU generators. https://smith-mcf.medium.com/solana-vanity-address-using-gpus-5a68ad94d1d4 ./solana-nice-address --help solana-nice-

The Voting example based on MoonZoon and Solana + Anchor framework.
The Voting example based on MoonZoon and Solana + Anchor framework.

The Voting example based on MoonZoon and Solana + Anchor framework.

The Solana Program Library (SPL) is a collection of on-chain programs targeting the Sealevel parallel runtime.

Solana Program Library The Solana Program Library (SPL) is a collection of on-chain programs targeting the Sealevel parallel runtime. These programs a

🐉 Aggregate of Solana stake pools.
🐉 Aggregate of Solana stake pools.

🐉 aSOL: Aggregate Stake Pool aSOL is an unbiased stake pool aggregator built to tackle one goal: to ensure all SOL on Solana is staked into stake poo

sandbox to play around numerous functionalities on Solana

Solana Sandbox This sandbox is for verifying smart contracts(programs) implemented on Solana for a self-study purpose. Programs Currently implemented

Solana Escrow Program written by RUST.

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

A suite of programs for Solana key management and security.
A suite of programs for Solana key management and security.

🔑 goki Goki is a suite of programs for Solana key management and security. It currently features: Goki Smart Wallet: A wallet loosely based on the Se

NFT Marketplace with Rust on Solana

NFT Marketplace with Rust on Solana Compile and Deploy Contracts make sure you have solana installed make sure you have rust installed install phantom

Testing a smart contract on the Solana blockchain

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

@Buildspace project creating a Web3 Solana Dapp with React and Rust
@Buildspace project creating a Web3 Solana Dapp with React and Rust

buildspace Solana GIF Portal Project Welcome 👋 To get started with this course, clone this repo and follow these commands: Run npm install at the roo

Solana Escrow Program

Environment Setup Install Rust from https://rustup.rs/ Install Solana from https://docs.solana.com/cli/install-solana-cli-tools#use-solanas-install-to

A variation of the solana helloworld program example with a client written in Rust instead of Typescript

Simple Solana Smart Contract Example This repository demonstrates how to create and invoke a program on the Solana blockchain. In Solana the word prog

Traction is a protocol for issuing American options on Solana.

Traction is a protocol for issuing American options on Solana.

Owner
Joe C
Joe C
A simple heads or tails (cross and pile) on Solana

cross-pile (Coin flip) A heads or tails (cross and pile) on Solana. It's meant to serve as an example of how to use solrand, a randomness Oracle: http

Evan Marshall 22 Nov 19, 2022
Write Anchor-compatible Solana programs in Python

seahorse: Write Solana programs in Python The ease of Python with the safety of Rust. Seahorse lets you write Solana programs in Python. It is a commu

✨ amelia chen ✨ 214 Dec 28, 2022
The example anchor implementation for solana-swap

anchor-liquidity-pool This is the example anchor implementation for solana-swap. The curve is always ConstantProduct in this implementation. The fee r

Something-Something 2 Aug 17, 2024
SVM - Spacemesh Virtual Machine

SVM - Spacemesh Virtual Machine Project Goals Self-contained. Should be hosted by the Spacemesh Golang full-node and future Spacemesh Rust full-node B

Spacemesh 83 Sep 15, 2022
Solana Foundation stake bot used on the Solana Testnet and Mainnet-Beta

Effortlessly Manage Cluster Stakes The testnet and mainnet-beta clusters currently have a large population of validators that need to be staked by a c

Solana Foundation 113 Dec 29, 2022
Demonstrates Solana data account versioning used in supporting the Solana Cookbook article: Account Data Versioning

versioning-solana This repo demonstrates ONE rudimentary way to upgrade/migrate account data changes with solana program changes. What is data version

Frank V. Castellucci 6 Sep 30, 2022
Solana Game Server is a decentralized game server running on Solana, designed for game developers

Solana Game Server* is the first decentralized Game Server (aka web3 game server) designed for game devs. (Think web3 SDK for game developers as a ser

Tardigrade Life Sciences, Inc 16 Dec 1, 2022
My attempt at learning Solana program (smart contract) development through RareSkill's Solana course.

60-days-of-solana My attempt at learning Solana program (smart contract) development through RareSkill's Solana course. Originally, I was trying to cr

Jasper 3 Feb 25, 2024
⚓ Solana Sealevel Framework

Anchor ⚓ Anchor is a framework for Solana's Sealevel runtime providing several convenient developer tools. Rust eDSL for writing Solana programs IDL s

Project Serum 2.6k Jan 2, 2023
Metaplex is a protocol built on top of Solana that allows: Creating/Minting non-fungible tokens;

Metaplex is a protocol built on top of Solana that allows: Creating/Minting non-fungible tokens; Starting a variety of auctions for primary/secondary

Metaplex Foundation 3.2k Jan 4, 2023