erigon-pulse/core/vm/lightclient/iavl
Alex Sharov 52fd0d0e8b
Aggregator22.Unwind() (#5039)
* save

* save
2022-08-13 18:51:25 +07:00
..
.gitignore Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
CHANGELOG.md Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
CONTRIBUTING.md Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
doc.go go1.19 gofmt (#4988) 2022-08-10 19:04:13 +07:00
key_format_test.go Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
key_format.go Aggregator22.Unwind() (#5039) 2022-08-13 18:51:25 +07:00
LICENSE Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
Makefile Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
PERFORMANCE.md Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
POEM Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
proof_iavl_absence.go Aggregator22.Unwind() (#5039) 2022-08-13 18:51:25 +07:00
proof_iavl_value.go Aggregator22.Unwind() (#5039) 2022-08-13 18:51:25 +07:00
proof_path.go Aggregator22.Unwind() (#5039) 2022-08-13 18:51:25 +07:00
proof_range.go Fixed lint errors for staticcheck (#4901) 2022-08-02 21:07:39 +07:00
proof.go Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
README.md Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
version.go Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00
wire.go Remove dependency on leveldb (#4213) 2022-05-20 11:24:28 +07:00

IAVL+ Tree

Note: Requires Go 1.8+

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

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.