Skip to content

Commit

Permalink
Strip out all merkleeyes-related code
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudhead committed Aug 31, 2017
1 parent 2f6e5d3 commit a1c21bc
Show file tree
Hide file tree
Showing 52 changed files with 43 additions and 1,630 deletions.
50 changes: 0 additions & 50 deletions CHANGELOG.md

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Tendermint MerkleEyes
Tendermint iavl
Copyright (C) 2015 Tendermint


Expand Down
14 changes: 2 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@ GOTOOLS = \

PDFFLAGS=-pdf --nodefraction=0.1

all: get_vendor_deps install test

install:
go install github.com/tendermint/merkleeyes/cmd/...

dist:
@ bash scripts/dist.sh
@ bash scripts/publish.sh
all: get_vendor_deps test

test:
go test -v --race `glide novendor`

get_deps:
go get -d github.com/tendermint/merkleeyes/...

tools:
go get -u -v $(GOTOOLS)

Expand Down Expand Up @@ -64,4 +54,4 @@ exploremem:
delve:
dlv test ./benchmarks -- -test.bench=.

.PHONY: all test get_deps install tools dist
.PHONY: all test tools
File renamed without changes.
29 changes: 29 additions & 0 deletions POEM
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
writing down, my checksum
waiting for the, data to come
no need to pray for integrity
thats cuz I use, a merkle tree

grab the root, with a quick hash run
if the hash works out,
it must have been done

theres no need, for trust to arise
thanks to the crypto
now that I can merkleyes

take that data, merklize
ye, I merklize ...

then the truth, begins to shine
the inverse of a hash, you will never find
and as I watch, the dataset grow
producing a proof, is never slow

Where do I find, the will to hash
How do I teach it?
It doesn't pay in cash
Bitcoin, here, I've realized
Thats what I need now,
cuz real currencies merklize

-EB
94 changes: 7 additions & 87 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1,13 @@
# merkleeyes
## IAVL+ Tree

[![CircleCI](https://circleci.com/gh/tendermint/merkleeyes.svg?style=svg)](https://circleci.com/gh/tendermint/merkleeyes)
A snapshottable (immutable) AVL+ tree for persistent data

A simple [ABCI application](http://github.com/tendermint/abci) serving a [merkle-tree key-value store](http://github.com/tendermint/merkleeyes/iavl)
**Note** Please make sure you read the [caveat](https://github.com/tendermint/merkleeyes/blob/develop/iavl/iavl_tree.go#L34-L40) on `Copy`. If you have a backing DB and call `Save` to persist the state, all existing copies become potentially invalid and may panic if used. For safe coding, you must throw away all references upon save, and `Copy` again from the new, committed state.

# Use
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 algortihm](http://en.wikipedia.org/wiki/AVL_tree) so all operations are O(log(n)).

Merkleeyes allows inserts and removes by key, and queries by key or index.
Inserts and removes happen through the `DeliverTx` message, while queries happen through the `Query` message.
`CheckTx` simply mirrors `DeliverTx`.
Nodes of this tree are immutable and indexed by its 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).

# Formatting
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.

## Byte arrays

Byte-array `B` is serialized to `Encode(B)` as follows:

```
Len(B) := Big-Endian encoded length of B
Encode(B) = Len(Len(B)) | Len(B) | B
```

So if `B = "eric"`, then `Encode(B) = 0x010465726963`

## Transactions

There are two types of transaction, each associated with a type-byte and a list of arguments:

```
Set 0x01 Key, Value
Remove 0x02 Key
```

A transaction consists of the type-byte concatenated with the encoded arguments.

For instance, to insert a key-value pair, you would submit `01 | Encode(key) | Encode(value)`.
Thus, a transaction inserting the key-value pair `(eric, clapton)` would look like:

```
0x010104657269630107636c6170746f6e
```


Here's a session from the [abci-cli](https://tendermint.com/docs/getting-started/first-abci):

```
> deliver_tx 0x010104657269630107636c6170746f6e
> commit
-> data: ��N��٢ek�X�!a��
-> data.hex: 978A4ED807D617D9A2651C6B0EC9588D2161C9E0
> query 0x65726963
-> height: 2
-> key: eric
-> key.hex: 65726963
-> value: clapton
-> value.hex: 636C6170746F6E
```

# Poem

```
writing down, my checksum
waiting for the, data to come
no need to pray for integrity
thats cuz I use, a merkle tree
grab the root, with a quick hash run
if the hash works out,
it must have been done
theres no need, for trust to arise
thanks to the crypto
now that I can merkleyes
take that data, merklize
ye, I merklize ...
then the truth, begins to shine
the inverse of a hash, you will never find
and as I watch, the dataset grow
producing a proof, is never slow
Where do I find, the will to hash
How do I teach it?
It doesn't pay in cash
Bitcoin, here, I've realized
Thats what I need now,
cuz real currencies merklize
-EB
```
In Ethereum, the analog is [Patricia tries](http://en.wikipedia.org/wiki/Radix_tree). 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.
Loading

0 comments on commit a1c21bc

Please sign in to comment.