WARNING: UNDER DEVELOPMENT
This crate is currently in alpha and under active development. Expect API changes, instabilities, and potential bugs. It is not yet ready for production use.
A Rust implementation of a versioned, immutable AVL Tree, heavily inspired by Cosmos's IAVL crate.
- Immutable & Mutable Interfaces: Exposes
ImmutableTreefor read-only versioned querying andMutableTreefor tree modifications and state progression. - Versioned Key-Value Storage: Maintain historical states of the tree efficiently, enabling queries across different state versions.
- Generic Database Backend: Built around flexible
KVStore,MutKVStore, andKVIteratortraits, making it easily adaptable to custom storage engines. - Drop-in
redbSupport: Provides an optional backend implementation forredb, a pure-Rust embedded key-value store (enable via theredbfeature flag). - Cryptographic Hashing: Provides built-in SHA-256 node hashing to compute state roots and ensure tree integrity.
- Memory Efficient: Utilizes
bytesandnebz(NonEmptyBz) crates for optimized, zero-copy-friendly memory allocation and byte slicing. - Modern Rust: Written targeting the Rust 2024 edition.
This project is currently pre-release. To test it out, add the following to your Cargo.toml:
[dependencies]
iavl = "0.1.0-alpha.2"To enable the redb backend feature:
[dependencies]
iavl = { version = "0.1.0-alpha.2", features = ["redb"] }The core operations pivot around two primary tree models:
MutableTree<DB>: Used for applying updates. Exposes methods likeinsert(),remove(), andsave(). Whensave()is called, changes are persisted to the underlying database and a new version identifier is established.ImmutableTree<DB>: Used for querying a specific, historical state of the tree. Operations on anImmutableTreedo not modify the tree, making it ideal for concurrent read-only operations and generating state proofs.
This implementation draws its concepts and fundamental mechanics from Cosmos's IAVL in Go. It marries a balanced AVL tree with cryptographic Merkle tree properties to support deterministic state hashing and historical version queries commonly required by blockchain state layers.
This project is dual-licensed under Apache 2.0 or MIT.