Skip to main content

Overview

SnarkVM uses the aleo-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 the StorageMode enum:

Production Mode

Persistent storage using RocksDB, suitable for production deployments.
Characteristics:
  • Persistent across restarts
  • RocksDB-backed for durability
  • Optimized for production workloads
  • Automatic directory creation
  • Network ID-specific paths
Use Cases:
  • Validator nodes
  • Full nodes
  • Production applications
  • Long-running services

Development Mode

In-memory storage with optional persistence, ideal for testing and development.
Characteristics:
  • Fast in-memory operations
  • Isolated by instance ID
  • Optional temp directory persistence
  • Automatically cleaned up
  • No network ID requirements
Use Cases:
  • Unit tests
  • Integration tests
  • Local development
  • Rapid prototyping
  • CI/CD pipelines

Custom Mode

User-specified storage path for advanced configurations.
Characteristics:
  • User-defined storage location
  • Full control over path
  • RocksDB-backed
  • Supports any valid filesystem path
  • No automatic cleanup
Use Cases:
  • 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 implement Into<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
Limitations:
  • Limited by available RAM
  • Data lost on restart
  • Not suitable for large datasets
  • No durability guarantees
Typical Performance:
  • 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
Limitations:
  • Slower than in-memory
  • Disk I/O dependent
  • Requires more configuration
  • Compaction overhead
Typical Performance:
  • 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 the rocks feature:
Cargo.toml
RocksDB Features:
  • Production-ready persistence
  • ACID transactions
  • Automatic compression (Snappy/LZ4)
  • Background compaction
  • Write-ahead logging (WAL)

Memory Backend

Default for development and testing:
Cargo.toml
Memory Features:
  • 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

Mainnet ledger can exceed 100GB. Ensure adequate disk space before syncing.

Corrupted Storage

If storage becomes corrupted:

Performance Issues

Best Practices

Development

  • Use Development mode for all tests
  • Generate unique test IDs to avoid conflicts
  • Avoid persistent storage in CI/CD

Production

  • Use Production or Custom mode
  • 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 Development mode to avoid filesystem overhead