Skip to content

cosmos/iavl

Folders and files

NameName
Last commit message
Last commit date
Apr 1, 2025
Aug 26, 2022
Apr 1, 2025
Mar 14, 2024
Apr 11, 2025
Aug 14, 2024
Nov 4, 2024
May 19, 2023
Apr 2, 2025
Apr 1, 2025
Apr 2, 2025
Jun 29, 2023
Jul 30, 2020
Apr 11, 2025
Nov 4, 2024
Aug 29, 2022
Apr 1, 2025
Aug 31, 2024
Mar 6, 2024
Dec 16, 2024
Oct 30, 2022
Jul 25, 2022
Apr 1, 2025
Apr 10, 2025
Aug 31, 2017
Sep 6, 2024
Apr 20, 2023
Apr 1, 2025
Aug 14, 2024
Jun 11, 2024
Jun 29, 2023
Apr 1, 2025
May 19, 2023
Apr 1, 2025
Aug 14, 2024
Jan 25, 2024
Dec 13, 2024
Jun 11, 2024
Apr 10, 2025
Apr 10, 2025
Apr 2, 2025
Sep 23, 2024
Dec 13, 2024
Jun 11, 2024
Nov 4, 2024
Jul 25, 2024
Nov 4, 2024
Aug 14, 2024
Apr 1, 2025
Apr 1, 2025
Apr 1, 2025
Apr 1, 2025
Mar 27, 2025
Apr 1, 2025
Nov 4, 2024
Dec 8, 2024
Jul 25, 2024
Apr 1, 2025
Jul 25, 2024
Oct 19, 2022
May 30, 2023
Jul 26, 2024
Apr 11, 2025
May 30, 2023
Jun 29, 2023
May 30, 2023
Apr 1, 2025
Apr 1, 2025
Jun 11, 2024
May 30, 2023
Aug 29, 2022

Repository files navigation

IAVL+ Tree

version license API Reference Lint Test Discord chat

Note: Requires Go 1.18+

A versioned, snapshottable (immutable) AVL+ tree for persistent data.

Benchmarks

The purpose of this data structure is to provide persistent storage for key-value pairs (say to store account balances) such that a deterministic merkle root hash can be computed. The tree is balanced using a variant of the AVL algorithm so all operations are O(log(n)).

Nodes of this tree are immutable and indexed by their hash. Thus any node serves as an immutable snapshot which lets us stage uncommitted transactions from the mempool cheaply, and we can instantly roll back to the last committed state to process transactions of a newly committed block (which may not be the same set of transactions as those from the mempool).

In an AVL tree, the heights of the two child subtrees of any node differ by at most one. Whenever this condition is violated upon an update, the tree is rebalanced by creating O(log(n)) new nodes that point to unmodified nodes of the old tree. In the original AVL algorithm, inner nodes can also hold key-value pairs. The AVL+ algorithm (note the plus) modifies the AVL algorithm to keep all values on leaf nodes, while only using branch-nodes to store keys. This simplifies the algorithm while keeping the merkle hash trail short.

In Ethereum, the analog is Patricia tries. There are tradeoffs. Keys do not need to be hashed prior to insertion in IAVL+ trees, so this provides faster iteration in the key space which may benefit some applications. The logic is simpler to implement, requiring only two types of nodes -- inner nodes and leaf nodes. On the other hand, while IAVL+ trees provide a deterministic merkle root hash, it depends on the order of transactions. In practice this shouldn't be a problem, since you can efficiently encode the tree structure when serializing the tree contents.

IAVL x Cosmos SDK

IAVL DB Interface Cosmos SDK
v0.19.x tm-db v0.45.x, v0.46.x
v0.20.x cometbft-db v0.47.x
v1.0.3 cosmos-db v0.50.0-5
v1.1.2,4 iavl-db v0.50.6
v1.2.x iavl-db v0.50.7+
v1.3.0 iavl-db v0.52.x
v2.0.0 iavl-db cosmossdk.io/store/v2

NOTE: In the past, a v0.21.x release was published, but never used in production. It was retracted to avoid confusion.