# blockchain-compression > Lossless compression for blockchain data using Zstandard plus custom dictionaries trained on Solana-specific byte patterns. Written in Rust. MIT licensed. README reports up to 60:1 ratios with the MaxCompression preset (Zstd level 19) on archival workloads. ## What it actually is A Rust crate (`blockchain-compression`) that wraps Zstandard with a pre-built dictionary of common Solana byte sequences (program IDs, instruction discriminators, common lamport amounts, Base58 characters, transaction structure markers). When the encoder runs, those byte sequences are referenced rather than emitted, which is where the ratio gains come from. It is not a chain client. It is not a node. It does not depend on a running validator. You feed it bytes; it gives you smaller bytes. You feed it the smaller bytes; it gives you the original bytes back, byte-for-byte. ## Presets (from the README) The library ships six presets that select a Zstd compression level and report ratio ranges on representative Solana workloads: | Preset | Zstd Level | Compression Ratio | Best For | | ----------------- | ---------- | ----------------- | ---------------------------- | | FastCompression | 3 | 5–15:1 | Real-time processing | | Transactions | 3 | 10–30:1 | Transaction data | | Instructions | 6 | 10–25:1 | Program instructions | | Accounts | 6 | 15–40:1 | Account state snapshots | | Mixed | 6 | 12–35:1 | General-purpose | | MaxCompression | 19 | 20–60:1 | Archival storage | The "up to 60:1" headline number is the top of the MaxCompression range on archival Solana data. It is not the median, it is not the guarantee, and it is not what you will see on, say, a random EVM payload. ## Architecture (from the repo) - `src/core/` defines the `CompressionStrategy` trait and a generic pattern engine. No chain knowledge. - `src/algorithms/` ships three internal algorithms: `EnhancedCTW` (context tree weighting), `MultiPassCompressor`, and `PracticalMaxCompression`. These are mostly used by the more aggressive presets and the pattern engine. - `src/presets/solana.rs` is where the production path lives: `SolanaCompressor` constructs a Zstandard dictionary from a hardcoded list of common Solana byte patterns at initialization and passes it to the Zstd encoder/decoder. - Compression backends are feature-gated: `deflate` (default), `lz4`, `zstd`. The Solana presets require `zstd`. ## Lossless guarantee Every compress/decompress operation is round-trip validated in tests. The trait method `decompress` is required to return the exact original bytes. The README is explicit: "100% lossless — rigorous roundtrip validation on every operation." ## Install ```toml [dependencies] blockchain-compression = { version = "0.1", features = ["zstd"] } ``` ## Usage ```rust use blockchain_compression::presets::solana::{SolanaCompressor, SolanaPreset}; use blockchain_compression::core::traits::CompressionStrategy; let mut compressor = SolanaCompressor::new(SolanaPreset::Transactions); let compressed = compressor.compress(data)?; let decompressed = compressor.decompress(&compressed)?; assert_eq!(data, decompressed.as_slice()); ``` ## What is in the dictionary The Solana preset dictionary is built from: - Common program IDs: System Program, Token Program, Associated Token, Serum DEX, BPF Loader, Config, Vote, Stake - Instruction discriminators: Transfer, Initialize, Close, Approve - Common lamport amounts: 0.01, 0.1, 1, and 10 SOL - Transaction structure markers: signature-count headers - Base58 character set used in Solana address encoding This is a hardcoded list. There is no online training. There is no per-customer model. The dictionary is the same on every installation, which keeps decompression deterministic and the binary self-contained. ## Audience - Archive-node operators who pay storage bills for historical chain data - Indexer teams snapshotting account state for analytics - Block-explorer infrastructure that warehouses past transactions - Anyone who has measured what generic gzip or vanilla zstd actually achieves on chain data and decided the gap was worth closing ## Pages - / — overview, architecture diagram, preset table, install + usage - /features/ — full feature set (lossless round-trip, Solana dictionary, six presets, feature-gated backends, deterministic output, chain-agnostic core) - /presets/ — all six presets with level, README ratio range, and per-workload guidance - /quickstart/ — cargo add → pick preset → compress → decompress → assert round-trip - /how-it-works/ — architecture: CompressionStrategy trait, algorithms (EnhancedCTW, MultiPassCompressor, PracticalMaxCompression), Solana dictionary, feature-gated backends, pipeline diagram - /use-cases/ — index of workloads - /use-cases/archive-nodes/ — MaxCompression for cold historical data - /use-cases/account-state-snapshots/ — Accounts preset for snapshot dumps - /use-cases/block-explorers/ — Mixed preset to keep history on warm disk - /use-cases/indexer-warehousing/ — Transactions preset for the decoded firehose - /faq/ — is it 60:1, is it lossless, which chains, which backend, does it need a validator - /about/ — design notes - /blog/ — engineering notes - /compare/zstd/ — vs vanilla Zstandard (no dictionary) - /compare/deflate/ — vs DEFLATE / gzip - /contact/ — get in touch - /rss.xml — blog feed - /sitemap-index.xml — sitemap ## Source - GitHub: https://github.com/cryptuon/blockchain-compression - crates.io: https://crates.io/crates/blockchain-compression - docs.rs: https://docs.rs/blockchain-compression - License: MIT