merkletree icon indicating copy to clipboard operation
merkletree copied to clipboard

Why does the node contain content?

Open web3coach opened this issue 3 years ago • 1 comments

Hi, wonderful library!

I have one doubt about the implementation. Why do the leaf nodes contain data? https://github.com/cbergoon/merkletree/blob/master/merkle_tree.go#L40

I was of the understanding that Merkle Tree only contains hash of data in its leafs - to separate the data from proofs. Are there multiple variations of the concept?

Good job with the lib again @cbergoon!

web3coach avatar Jul 09 '20 19:07 web3coach

Hey there @web3coach,

The thought process for this design was that the data needed to be stored somewhere and that the it was convenient for a reference to be held directly in the data structure. In this case the leaf, is really only holding a reference to the item data that the node was originally created with. If your entire data set is being held in memory anyway then this seems reasonable.

I hear your point though, if the source data of the tree does not fit in memory or is in some other form/store, the library may not be as simple to use. In this case we could consider adding some sort of abstraction that would allow the data to be separated to enable this type of extended use-case with externalized data.

Open to ideas for improvements and especially ideas that come with PRs and no breaking API changes ;)

Thanks for the kind words.

Cam

cbergoon avatar Jul 11 '20 01:07 cbergoon