SVM Series

Deep dive into Solana Virtual Machine (SVM). Some knowledge of Solana architecture like Ledger
,Bank
,AccountsDB
and transactions is required to go through this series. An overview of the SVM API used in this series of articles can be found at Anza’s SVM API blog.
Articles in this series
Introduction to SVM, a summary of SVM API blog (this article)
Introduction to SVM, a summary of SVM API blog
The Solana Virtual Machine is the entire transaction processing pipeline from validator’s runtime to executing Solana eBPF programs.
The Bank
(contained in the Ledger
) coordinates the networks state during any given slot by processing transactions, packing them into a block. Validators replaying a block attempt to rebuild a matching instance of the Bank
.
Transactions are processed in batches
Each transactions contains one or multiple instructions
Each instruction contains information to load accounts and determine write locks
Read locks allow parallel data access across Bank instances
Transactions are
sanitized
before they are processedDe-duplication of account keys from a transaction’s instruction is done during sanitization
After accounts are loaded, SVM loads the executable program for each instruction and provisions an eBPF virtual machine to execute the program, returning that result
Caching is used to store the machine code from the translated program byte-code until recomputing the program byte-code is needed or when the cache is full
All of these processes are coordinated by the Bank within the SVM.
Agave SVM API
Credit: Anza’s Blog
The solana-svm Rust crate is used to build SVM applications in a protocol compliant manner. The TransactionBatchProcessor struct is the central interface of SVM which processes batches of sanitized transactions using components in the transaction pipeline. During this series we will break down each components.
// From the `solana-svm` crate.
// The method `load_and_execute_sanitized_transactions()` on this struct is used
// to process batched transactions.
pub struct TransactionBatchProcessor<FG: ForkGraph> {
/// Bank slot (i.e. block)
slot: Slot,
/// Bank epoch
epoch: Epoch,
/// SysvarCache is a collection of system variables that are
/// accessible from on chain programs. It is passed to SVM from
/// client code (e.g. Bank) and forwarded to the MessageProcessor.
pub sysvar_cache: RwLock<SysvarCache>,
/// Programs required for transaction batch processing
pub program_cache: Arc<RwLock<ProgramCache<FG>>>,
/// Builtin program ids
pub builtin_program_ids: RwLock<HashSet<Pubkey>>,
}
You can read an overview of this API on Anza’s blog - https://www.anza.xyz/blog/anzas-new-svm-api
Source Code
The source code for each article can be found at https://github.com/448-OG/SVM-Series/
Next Article: SVM Series 02: SVM Feature Activation & Management >
Subscribe to my newsletter
Read articles from 448-OG directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by

448-OG
448-OG
<[Open Source, Rust, Decentralized Infrastructure]>::earth()