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

stake trie #161

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft

stake trie #161

wants to merge 3 commits into from

Conversation

jyouyj
Copy link
Contributor

@jyouyj jyouyj commented Oct 15, 2018

The draft code for stake trie --- I start from a random function that takes the previous block hash as the random seed and output an index I, which is larger than zero and smaller than the total number of tokens. Then, I try to rewrite the trie such that this stake trie can return the owner's address efficiently.

@jyouyj jyouyj self-assigned this Oct 15, 2018
@jyouyj jyouyj requested review from qizhou, qcgg, ninjaahhh and qcdll October 15, 2018 22:48
@qcgg
Copy link
Contributor

qcgg commented Oct 15, 2018

can you separate your change from the original commit of the trie so that it's easier to see what you have changed over the original trie code?

@qcgg
Copy link
Contributor

qcgg commented Oct 15, 2018

just do two commits

  1. commit the original trie code
  2. commit your change

@jyouyj
Copy link
Contributor Author

jyouyj commented Oct 16, 2018

I have separated the change by doing two commits. Please check it.

@qcgg
Copy link
Contributor

qcgg commented Oct 18, 2018

can you describe the purpose of the stake trie and the difference from trie?
That'd help us review the code. thanks!

@jyouyj
Copy link
Contributor Author

jyouyj commented Oct 18, 2018

A stake trie is a variant of the original trie that supports two addition operations beyond insertion, lookup, and deletion:
get_total_stake(): return the total number of stakes stored in the trie
select_staker(i): find the owner address of ith stake stored in the trie
where i is the random index, which is larger than zero and smaller than the total number of stakes.
This stake trie is designed for our proof of stake consensus (Photon). By using this stake trie, we
can keep track of the total number of stakes and return the ith owner's address efficiently.

For the implementation, I add an extract variable for each trie node to store the total number of stakes rooted at the node (i.e., the number of tokens below it). More specifically, blank or stake trie node in form of [key, [value, stake]] or [[v0, stake],[v1, stake]..[v15, stake],[v, stake]]. All the above operations that modify the trie must adjust the stake information. Besides, I deleted the useless operations split() and merge() in the original trie.

For the test part, I start from a random function that takes the previous block hash as the random seed and output an index I, which is larger than zero and smaller than the total number of tokens.
Then, I compare the results from the select_staker() operation and nominal values in the sorted list of elements of the trie. The corresponding test dataset is enclosed in the file fixtures/TrieTests/staketrietest.json.

@ninjaahhh ninjaahhh marked this pull request as draft April 30, 2020 21:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants