Overview
SnarkVM uses thealeo-std storage abstraction layer to support multiple storage backends. Understanding storage modes is crucial for optimizing performance, managing disk usage, and ensuring data persistence across different deployment scenarios.
Storage Mode Types
SnarkVM supports three primary storage modes through theStorageMode enum:
Production Mode
Persistent storage using RocksDB, suitable for production deployments.- Persistent across restarts
- RocksDB-backed for durability
- Optimized for production workloads
- Automatic directory creation
- Network ID-specific paths
- Validator nodes
- Full nodes
- Production applications
- Long-running services
Development Mode
In-memory storage with optional persistence, ideal for testing and development.- Fast in-memory operations
- Isolated by instance ID
- Optional temp directory persistence
- Automatically cleaned up
- No network ID requirements
- Unit tests
- Integration tests
- Local development
- Rapid prototyping
- CI/CD pipelines
Custom Mode
User-specified storage path for advanced configurations.- User-defined storage location
- Full control over path
- RocksDB-backed
- Supports any valid filesystem path
- No automatic cleanup
- Custom deployment configurations
- Specific disk/volume requirements
- Network attached storage (NAS)
- Cloud storage volumes
- Multi-node setups
Storage Initialization
Opening a Ledger
Opening a Store
Storage Mode Conversion
Storage modes implementInto<StorageMode> for convenience:
Storage Components
SnarkVM’s ledger uses multiple storage components:Block Store
Stores block data, headers, and metadata.Transaction Store
Manages transaction data and indices.Program Store
Stores deployed programs and their state.Performance Characteristics
In-Memory (Development)
Advantages:- Fastest read/write operations
- No disk I/O overhead
- Deterministic test behavior
- Easy cleanup
- Limited by available RAM
- Data lost on restart
- Not suitable for large datasets
- No durability guarantees
- Read latency: <1μs
- Write latency: <10μs
- Throughput: Memory bandwidth limited
RocksDB (Production/Custom)
Advantages:- Persistent and durable
- Scales to large datasets
- Built-in compression
- Background compaction
- Crash recovery
- Slower than in-memory
- Disk I/O dependent
- Requires more configuration
- Compaction overhead
- Read latency: 10-100μs (with cache)
- Write latency: 50-500μs
- Throughput: Disk-dependent (NVMe: 100K+ ops/sec)
Configuration Examples
Production Validator
Test Suite
Multi-Instance Deployment
Storage Backend Selection
Choose the appropriate storage backend using feature flags:RocksDB Backend
Enable with therocks feature:
Cargo.toml
- Production-ready persistence
- ACID transactions
- Automatic compression (Snappy/LZ4)
- Background compaction
- Write-ahead logging (WAL)
Memory Backend
Default for development and testing:Cargo.toml
- BTreeMap-based storage
- In-process only
- Fastest for small datasets
- Optional temp persistence
Storage Maintenance
Checking Storage Size
Backup and Recovery
Cleanup
Advanced Configuration
Storage Mode Helper
Get the storage directory path:Test Storage Isolation
Custom Storage Traits
Implement storage traits for custom backends:Troubleshooting
Permission Errors
Disk Space Issues
Corrupted Storage
If storage becomes corrupted:Performance Issues
Best Practices
Development
- Use
Developmentmode for all tests - Generate unique test IDs to avoid conflicts
- Avoid persistent storage in CI/CD
Production
- Use
ProductionorCustommode - Mount ledger storage on fast SSD/NVMe
- Monitor disk usage and I/O
- Implement regular backups
- Plan for growth (10-20GB/month typical)
Testing
- Use deterministic test IDs for reproducibility
- Clean up storage in test teardown if needed
- Use
Developmentmode to avoid filesystem overhead
Related Topics
- Custom Networks - Configure storage for custom networks
- CUDA Acceleration - Optimize computation performance