Commit 3e5f1310aaf2b3f3e5ce84ef70c9d91a24657bde
Update spec.md
Mahnush Movahedi authored on 12/21/2017, 8:16:30 PMGitHub committed on 12/21/2017, 8:16:30 PM
Parent: 89398824f10c7485f1839296a5d994e9b852aef9
Files changed
docs/spec.md | changed |
docs/spec.md | ||
---|---|---|
@@ -1,30 +1,29 @@ | ||
1 | -This is a simple Merkle Binary [Radix Tree](https://ipfs.io/ipns/QmdJiuMWp2FxyaerfLrtdLF6Nr1EWpL7dPAxA9oKSPYYgV/wiki/Radix_tree.html). | |
1 … | +This documnet provides the structure of the Dfinities Radix Tree which is type of the Merkle tree.(https://ipfs.io/ipns/QmdJiuMWp2FxyaerfLrtdLF6Nr1EWpL7dPAxA9oKSPYYgV/wiki/Radix_tree.html). | |
2 … | +The radix tree data structure consists of nodes. | |
2 | 3 … | |
3 | - | |
4 | 4 … | ## Node |
5 | -Each node contains at the most four elements | |
5 … | +Each node has a type and contains at the most four elements | |
6 | 6 … | "extension", "left branch", "right branch" and "value". |
7 | 7 … | |
8 | 8 … | ``` |
9 | -node : = EXTENSION | LBRANCH | RBRANCH | VALUE | |
9 … | +node : = TYPE | EXTENSION | LBRANCH | RBRANCH | VALUE | |
10 | 10 … | ``` |
11 | 11 … | |
12 | -A prefix byte is used a bit field to signify which elements a node contains. | |
13 | -The bit field is defined a the following. The first nibble is reserved for | |
14 | -merkle proofs. | |
12 … | +###Type | |
13 … | +Contains a byte that the last 4 bits are used to signify which elements a node contains. | |
14 … | +The bit field is defined a the following. The first 4 bits are paded to zero while in storage. These bits are reserved as insicators of type when sending the nodes to other clients which we will describe later. | |
15 | 15 … | |
16 | 16 … | ``` |
17 | -PREFIX := reserved | reserved | reserved | reserved | EXTENSION | LBRANCH | RBRANCH | VALUE | |
17 … | +Type := 0 | 0 | 0 | 0 | HasEXTENSION | HasLBRANCH | HasRBRANCH | HasVALUE | |
18 | 18 … | ``` |
19 | 19 … | |
20 | -For example a node that contained a left branch and a value would have a prefix byte | |
21 | -of 00000101 or 0x07 | |
20 … | +For example a node that contained a left branch and a value would have a prefix byte of 00000101 or 0x07 | |
22 | 21 … | |
23 | 22 … | The full encoded node would then look something like. `0x07<20_bytes_for_lbranch><remaing_bytes_for_value>` |
24 | 23 … | |
25 | 24 … | |
26 | -## Branches | |
25 … | +### Branches | |
27 | 26 … | |
28 | 27 … | The branch elements point to the next node in the tree using a merkle link. |
29 | 28 … | A merkle link is defined by the first 20 bytes of the result SHA2-256 of an encoded node. |
30 | 29 … | |
@@ -37,13 +36,13 @@ | ||
37 | 36 … | link := SHA2(encoded_node)[0..20] |
38 | 37 … | ``` |
39 | 38 … | |
40 | 39 … | |
41 | -## Extensions | |
42 | -Extensions encode shared paths. Extensions are defined as | |
40 … | +### Extensions | |
41 … | +For optimization, we use the Extension element that encodes shared paths in the tree. Extensions are defined as | |
43 | 42 … | |
44 | 43 … | ``` |
45 | -extension := length | extension | |
44 … | +extension := Length | ExtensionValue | |
46 | 45 … | |
47 | 46 … | ``` |
48 | 47 … | Where the length is the number of bits that extension repesents. This varuint32 |
49 | 48 … | encoded with leb128. And the extension is bit array padded with 0's to the nearst byte. |
@@ -55,14 +54,14 @@ | ||
55 | 54 … | |
56 | 55 … | where 3 is the the shared path length and the `0x04` is the shared path encoded |
57 | 56 … | as a little endian byte array. |
58 | 57 … | |
59 | -# Examples | |
58 … | +## Examples | |
60 | 59 … | |
61 | -An empty tree is hash a merkle link of sha256(0x00) or `6e340b9cffb37a989ca544e6bb780a2c78901d3f` | |
60 … | +An empty tree has a merkle root which is a hash of sha256(0x00) or `6e340b9cffb37a989ca544e6bb780a2c78901d3f`. | |
62 | 61 … | |
63 | 62 … | |
64 | -A tree with a single key 'binary' and value of 'tree' is encoded as | |
63 … | +A tree with a single node with key 'binary' and value of 'tree' is encoded as | |
65 | 64 … | |
66 | 65 … | ``` |
67 | 66 … | 0x093062696e61727974726565 |
68 | 67 … | |
@@ -71,9 +70,9 @@ | ||
71 | 70 … | 0x62696e617279 the key 'binary' |
72 | 71 … | 0x4726565 the value 'tree' |
73 | 72 … | ``` |
74 | 73 … | |
75 | -If an other key "bin" with the value "number" is add the tree will have two nodes | |
74 … | +If we add another key-value with the key "bin" and the value "number" to the tree, the tree will have two nodes | |
76 | 75 … | |
77 | 76 … | The root node will be |
78 | 77 … | |
79 | 78 … | ``` |
Built with git-ssb-web