An optimized and cryptographically provable key-value store.
Design
The urkel tree was created for the Handshake protocol, and is implemented
as a base-2 merkelized trie. It was created as an alternative to Ethereum's
base-16 trie (which was the initial choice for Handshake name proofs).
Urkel stores nodes in a series of append-only files for snapshotting and crash
consistency capabilities. Due to these presence of these features, Urkel has
the ability to expose a fully transactional database.
The primary advantages in using an urkel tree over something like Ethereum's
trie are:
Performance - Stores nodes in flat files instead of an existing key-value
store like LevelDB. Urkel is its own database. In benchmarks, this results
in a 100x+ speedup.
Simplicity - Maintains only two types of nodes: internal nodes and leaf
nodes.
Storage - Internal nodes are small (a constant size of 76 bytes on disk).
This is important as internal nodes are frequently rewritten during updates
to the tree.
Proof Size - Sibling nodes required for proofs are a constant size of 32
bytes, similar to a typical merkle tree proof. This results in an extremely
compact proof size.
The final benefit was the primary focus of the Handshake protocol. As name
resolutions are a frequently requested operation, Handshake required proof
sizes less than 1kb even after hundreds of millions of leaves are present in
the tree.
History independence and non-destruction are also inherent properties of the
urkel tree, just the same as the Ethereum trie. Note that urkel should only be
used with uniformally distributed keys (i.e. hashed).
Compaction, while available, is currently inefficient and requires user
intervention. This will be optimized in a future C implementation of the urkel
tree. In the meantime, we don't see this as a problem as long as frequent
commissions are avoided in consensus applications of the tree (i.e. avoid
committing the tree on every block).
urkel/trie - A simple base-2 merkelized trie whose design shares
similarities with earlier work done by Bram Cohen.
urkel/radix - A base-2 merkelized radix tree, similar
to Amaury Séchet's Merklix tree.
urkel/optimized - A memory and storage optimized version of the simplified
trie.
These can all still be found in the
old-variants
branch of this repository.
Only the radix variant is currently maintained by The Handshake Developers.
Usage
const bcrypto = require('bcrypto');const urkel = require('urkel');const {BLAKE2b, randomBytes} = bcrypto;const {Tree, Proof} = urkel;// Create a tree using blake2b-256// and a depth/key-size of 256 bits.const tree = new Tree({ hash: BLAKE2b, bits: 256, prefix: '/path/to/my/db'});await tree.open();let key;const txn = tree.transaction();for (
Contribution and License Agreement
If you contribute code to this project, you are implicitly allowing your code
to be distributed under the MIT license. You are also implicitly verifying that
all code is your original work. </legalese>
License
Copyright (c) 2018, Christopher Jeffrey (MIT License).