Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem: No BEP discussing the UTXO implementation #20

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions utxo-info/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
```
shortname: ?/UTXO-IMPL
name: A short discription of the current UTXO implementation
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

description

type: informational
status: Draft
editor: Vanshdeep Singh <vanshdeep@bigchaindb.com>
```

## Description
The UTXO (unspent transaction output) of each transaction is tracked using the a merkle tree. The merkle root of this tree is used as the app hash and retuned to Tendermint during `commit`. Below is a short summary of the UTXO is calculated,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear how all the outputs (which are like floating independent dots) are somehow connected to form a Merkle tree. Maybe draw a picture? They say pictures are worth 1000 words and in this case I think it's true.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe link to some articles about Merkle trees.

https://en.wikipedia.org/wiki/Merkle_tree

What about AVL trees, IAVL trees, and IAVL+ trees. I gather that those are supposed to be useful somehow, as an improvement. Is it the rules for adding the next leaf UTXO, where to put it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ttmc I have restrained the context of this BEP to just discussing the current implementation. Also, the leaves of the UTXO merkle tree are added to the list of the existing leaves and the list is sorted after which merkle root is calculated. As explained in the BEP, the leaves are added to the utxo collection and then all the leaves are read back and sorted, after which the root is calculated.


- Each unspent output is considered as a leaf node in the merkle tree.
- The nodes are added/removed with each incoming transaction i.e. during `commit` when the transactions are being processed for bulk write the UTXO are updated in the `utxo` collection.
- Once all the transactions in a block are processed and stored, all the objects in the `utxo` collection are fetched and stored i.e. a list of leaves is prepared.
- The merkle root is calculated using this list of leaves.


## Copyright Waiver
To the extent possible under law, the person who associated CC0 with this work has waived all copyright and related or neighboring rights to this work.