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

Merkle Patricia Tries (2x) #97

Closed
wants to merge 7 commits into from

Conversation

rodoufu
Copy link

@rodoufu rodoufu commented May 18, 2019

An experimental plugin for persisting neo blockchain states into Merkle Patricia Tries.

@igormcoelho
Copy link
Contributor

Very good Rodolfo! Let's advance with this plugin. The target is still neo-project:master, could you change it for neo-project:master-2.x ?

@vncoelho
Copy link
Member

Great job, @rodoufu.
Lets create this branch here, Igor.

@erikzhang
Copy link
Member

Is this the same as neo-project/neo#528?

@igormcoelho
Copy link
Contributor

Right now it's the same Erik, but it will change... this one here will be more experimental, so that we validate it and then port it to neo project.

@rodoufu
Copy link
Author

rodoufu commented May 18, 2019

Very good Rodolfo! Let's advance with this plugin. The target is still neo-project:master, could you change it for neo-project:master-2.x ?

@igormcoelho , it looks like there's no mater-2x branch on the neo-plugins project:
https://github.com/neo-project/neo-plugins/branches

Only on the core neo project:
https://github.com/neo-project/neo/branches

Am I missing something?

@rodoufu rodoufu changed the base branch from master to master-2.x May 18, 2019 20:33
@rodoufu
Copy link
Author

rodoufu commented May 18, 2019

Now I have changed the target.

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

is on master-2.x , this feature will be for neo 3

@erikzhang
Copy link
Member

I think this plugin is for 2.x, because 2.x has no built-in MPT.

@shargon shargon self-requested a review May 19, 2019 18:59
public byte[] Key
{
get => _hashes[_hashes.Length - 2];
set => _hashes[_hashes.Length - 2] = value;
Copy link
Member

Choose a reason for hiding this comment

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

Throw an exception on empty tree

Copy link
Contributor

Choose a reason for hiding this comment

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

I think node types are verified before usage.. IsNull for example, has no Key.

public override void Serialize(BinaryWriter writer)
{
base.Serialize(writer);
writer.Write((byte) _hashes.Length);
Copy link
Member

Choose a reason for hiding this comment

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

is not possible to be bigger than 256?

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 possible, just an effect of using SHA256. In fact, we should use Hash256, to avoid length attacks.

@rodoufu
Copy link
Author

rodoufu commented May 21, 2019

@shargon , I think the idea is to have the MPT on Neo version 3.0 but start it as a plugin in the version 2.x so we can use it and improve before going to the Neo 3.0

@igormcoelho
Copy link
Contributor

@shargon
A node can be of four kinds:

  • Null (size 0)
  • Hash (size 1) (I don't know if Rodolfo considered this as a node... but I did on mine)
  • Path (size 2) it can be Leaf or Extension. Rodolfo added the Key to Leaf, to avoid colisions, I think we can do that implicitly Rodolfo, without hardcoding the key (so size is effectly 2 and no space is wasted twice)
    -Branch (size 17) I used variable sizes from 3 to 17 on my implementation (3 is Branch2 + Leaf, and 17 is classic Branch16 + Leaf). This slightly compresses the tree.

@rodoufu
As soon as you're back, we need to implement Sparse Merkle Tree, which is a binary tree, and allows much deeper compression techniques. I believe space will be further reduced than MPT.
We can create another plugin with that other tree and compare both, so Neo 3.0 can take a clear decision.
MPT and SMT solve the same problem: validated key-value storage with inclusion and non-inclusion proofs.

@vncoelho vncoelho changed the title Merkle Patricia Tries Merkle Patricia Tries (2x) Dec 18, 2019
@rodoufu rodoufu mentioned this pull request Mar 26, 2020
@vncoelho
Copy link
Member

vncoelho commented Aug 17, 2020

@rodoufu, this has been a great effort. Thanks for all your motivation, studies and prototype on this.
NeoX has already been merged to master2x with another implementation.
In this sense, I will close this one.

However, I would like to state my real appreciation for the work you conducted.

@vncoelho vncoelho closed this Aug 17, 2020
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.

5 participants